termii-api-client
Version:
A TypeScript client for interacting with the Termii API.
311 lines (303 loc) • 11.3 kB
TypeScript
type Config = {
baseUrl: string;
apiKey: string;
};
type MessageMedia = {
url: string;
caption: string;
};
type MessageBase = {
from: string;
sms?: string;
type: string;
channel: "generic" | "dnd" | "whatsapp";
};
type Message = MessageBase & {
to: string | string[];
media?: Message;
};
type BulkMessage = MessageBase & {
to: string[];
};
type SenderIDRequest = {
sender_id: string;
usecase: string;
company: string;
};
type PhoneBookCreateInput = {
phonebook_name: string;
description?: string;
};
type ContactCreateInput = {
phone_number: string;
country_code: string;
email_address: string;
first_name: string;
last_name?: string;
company?: string;
};
type PinConfig = {
pin_attempts: number;
pin_time_to_live: number;
pin_length: number;
};
type SendTokenInput = PinConfig & {
message_type: "NUMERIC" | "ALPHANUMERIC";
to: string;
from: string;
channel: "whatsapp" | "dnd" | "generic";
pin_placeholder: string;
message_text: string;
pin_type: "NUMERIC";
};
type VoiceTokenInput = PinConfig & {
phone_number: string;
};
type VoiceCallInput = {
phone_number: string;
code: string;
};
/**
* @property {string} email_address - Represents the email address you are sending to.
* @property {string} code - Represents the OTP sent to the email address.
* @property {string} email_configuration_id - This represents the email configuration you have added on your Termii dashboard. It can be found on your {@link https://accounts.termii.com/#/email-otp-config Termii dashboard}.
*/
type EmailTokenInput = {
email_address: string;
code: string;
email_configuration_id: string;
};
type InAppTokenInput = PinConfig & {
pin_type: "NUMERIC" | "ALPHANUMERIC";
phone_number: string;
};
declare class Campaign {
private readonly config;
constructor(config: Config);
/**
* Returns available campaigns on the integration.
* @returns
*/
fetch(): Promise<any>;
}
/**
* This API allows businesses send text messages to their customers across different messaging channels.
*/
declare class Messaging {
private readonly config;
constructor(config: Config);
/**
* Send a custom message. {@link https://developer.termii.com/messaging-api Read Documentation.}
*
* @example
* await client.Messaging.send({
* to: "2347880234567",
* from: "talert",
* sms: "Hi there, testing Termii",
* type: "plain",
* channel: "generic",
* });
*/
send(payload: Message): Promise<any>;
/**
* Send a custom bulk messages. {@link https://developer.termii.com/messaging-api Read Documentation.}
*
* @example
* await client.Messaging.sendBulk({
* to: ["23490555546", "23423490126999","23490555546"],
* from: "talert",
* sms: "Hi there, testing Termii",
* type: "plain",
* channel: "generic",
* });
*/
sendBulk(payload: BulkMessage): Promise<any>;
}
declare class PhoneBooks {
private readonly config;
constructor(config: Config);
/**
* Fetches the phonebooks available on the integration. {@link https://developer.termii.com/phonebook#fetch-phonebooks Read Documentation.}
*
* @example
* await client.PhoneBooks.fetch();
*/
fetch(): Promise<any>;
/**
* Creates a phonebook. {@link https://developer.termii.com/phonebook#create--a-phonebook Read Documentation.}
* @example
* await client.PhoneBooks.create({
* phonebook_name:"Phone test",
* description:"Phonebook for test"
* });
*/
create(payload: PhoneBookCreateInput): Promise<any>;
/**
* Fetches contacts in a phonebook. {@link https://developer.termii.com/contacts#fetch-contacts-by-phonebook-id Read Documentation.}
* @param {string} phoneBookID - The ID of the phonebook.
*
* @example
* await client.PhoneBooks.contacts("04c3ebcc-3a7e-485a-88c1-68e731386f77");
*/
contacts(phoneBookID: string): Promise<any>;
/**
*
* @param {string} phoneBookID - The ID of the phonebook.
* @param {ContactCreateInput} payload - data of the contact to be added.
* @returns
*/
addContact(phoneBookID: string, payload: ContactCreateInput): Promise<any>;
}
declare class SenderID {
private readonly config;
constructor(config: Config);
/**
* Fetches the sender IDs available on an integration. {@link https://developer.termii.com/sender-id#fetch-sender-id Read Documentation.}
*
* @example
* await client.SenderID.fetch();
*
*/
fetch(): Promise<any>;
/**
* Request for a sender ID. {@link https://developer.termii.com/sender-id#request-sender-id Read Documentation.}
*
* @example
* await client.SenderID.request({
* sender_id: "Acme",
* usecase: "Your OTP code is zxsds",
* company: "Acme Corp"
* });
*
*/
request(payload: SenderIDRequest): Promise<any>;
}
/**
* Contains various methods for managing tokens.
*/
declare class Token {
private readonly config;
constructor(config: Config);
/**
* The send token API allows businesses trigger one-time-passwords (OTP) across any available messaging channel on Termii. One-time-passwords created are generated randomly and there's an option to set an expiry time. {@link https://developer.termii.com/send-token Read Documentation.}
* @example
* await client.Token.send({
* message_type : "NUMERIC",
* to : "eg. 2348109077743",
* from : "Approved Sender ID or Configuration ID",
* channel : "dnd",
* pin_attempts : 10,
* pin_time_to_live : 5,
* pin_length : 6,
* pin_placeholder : "< 1234 >",
* message_text : "Your pin is < 1234 >",
* pin_type : "NUMERIC"
* });
*/
send(payload: SendTokenInput): Promise<any>;
/**
* The voice token API enables you to generate and trigger one-time passwords (OTP) through the voice channel to a phone number. OTPs are generated and sent to the phone number and can only be verified using our Verify Token API. {@link https://developer.termii.com/voice-token Read Documentation.}
*
* @example
* await client.Token.voice({
* phone_number : "23409800000000",
* pin_attempts : 10,
* pin_time_to_live : 5,
* pin_length : 6
* });
*/
voice(payload: VoiceTokenInput): Promise<any>;
/**
* The voice call API enables you to send messages from your application through our voice channel to a phone number. Only one-time-passwords (OTP) are allowed for now and these OTPs can not be verified using our Verify Token API. {@link https://developer.termii.com/voice-call Read Documentation.}
*
* @example
* await client.Token.voiceCall({
* phone_number : "2349800000000",
* code : 55675,
* });
*
*/
voiceCall(payload: VoiceCallInput): Promise<any>;
/**
* The email token API enables you to send one-time-passwords from your application through our email channel to an email address. Only one-time-passwords (OTP) are allowed for now and these OTPs can not be verified using our Verify Token API. {@link https://developer.termii.com/email-token Read Documentation.}
*
* @example
* await client.Token.email({
* email_address: "shola.olu@term.ii",
* code: "092471",
* email_configuration_id: "0a53c416-uocj-95af-ab3c306aellc"
* });
*
*/
email(payload: EmailTokenInput): Promise<any>;
/**
*
* This API returns OTP codes in JSON format which can be used within any web or mobile app. Tokens are numeric or alpha-numeric codes generated to authenticate login requests and verify customer transactions. {@link https://developer.termii.com/in-app-token Read Documentation.}
*
* @example
* await client.Token.inApp({
* pin_type: "NUMERIC",
* phone_number: "2348109477743",
* pin_attempts: 3,
* pin_time_to_live: 0,
* pin_length: 4
* });
*/
inApp(payload: InAppTokenInput): Promise<any>;
/**
* Verify token API, checks tokens sent to customers and returns a response confirming the status of the token. A token can either be confirmed as verified or expired based on the timer set for the token. {@link https://developer.termii.com/verify-token Read Documentation.}
*
* @param {string} pin_id ID of the PIN sent
* @param {string} pin The PIN code
*
* @example
* await client.Token.verify("c8dcd048-5e7f-4347-8c89-4470c3af0b", "195558");
*/
verify(pin_id: string, pin: string): Promise<any>;
}
declare class TermiiClient {
private readonly config;
readonly Messaging: Messaging;
readonly SenderID: SenderID;
readonly PhoneBooks: PhoneBooks;
readonly Token: Token;
readonly Campaign: Campaign;
constructor(config: Config);
/**
* The Balance API returns your total balance and balance information from your wallet, such as currency. {@link https://developer.termii.com/balance Read Documentation.}
*
* @example
* await client.getBalance();
*/
getBalance(): Promise<any>;
/**
* The status API allows businesses to detect if a number is fake or has ported to a new network. {@link https://developer.termii.com/status Read Documentation.}
* @param {string} phoneNumber - Represents the phone number to be verified. Phone number must be in the international format
* @param {string} countryCode - Represents short alphabetic codes developed to represent countries.
*
* @example
* await client.checkNumberStatus("2348753243651", "NG");
*/
checkNumberStatus(phoneNumber: string, countryCode: string): Promise<any>;
/**
* The search API allows businesses verify phone numbers and automatically detect their status as well as current network. It also tells if the number has activated the do-not-disturb settings.
* @param {string} phoneNumber - Represents the phone number to be verified. Phone number must be in the international format. {@link https://developer.termii.com/search Read Documentation.}
*
* @example
* await client.searchNumber("2348753243651");
*/
searchNumber(phoneNumber: string): Promise<any>;
/**
* This Inbox API returns reports for messages sent across the sms, voice & whatsapp channels. Reports can either display all messages on termii or a single message. Optionally accepts a `message_id` to query the report of a single message. {@link https://developer.termii.com/history Read Documentation.}
*
* @example
* // All messages
* await client.messageReports();
*
* // Single message
* await client.messageReports("04c3ebcc-3a7e-485a-88c1-68e731386f77");
*
*/
messageReports(message_id?: string): Promise<any>;
}
export { type BulkMessage, type Config, type ContactCreateInput, type EmailTokenInput, type InAppTokenInput, type Message, type MessageMedia, type PhoneBookCreateInput, type SendTokenInput, type SenderIDRequest, type VoiceCallInput, type VoiceTokenInput, TermiiClient as default };