@davidbolaji/termii-node
Version:
Node.js SDK for Termii API – send SMS, voice, OTP, and manage messaging with ease.
54 lines (53 loc) • 1.78 kB
JavaScript
import { EmailTokenService } from "./EmailTokenService";
import { InAppTokenService } from "./InAppTokenService";
import { VerifyTokenService } from "./VerifyTokenService";
/**
* Service for sending and verifying OTP tokens (SMS, WhatsApp, or Voice)
*/
export class TokenService {
constructor(http) {
this.http = http;
this.email = new EmailTokenService(this.http);
this.verify = new VerifyTokenService(this.http);
this.inApp = new InAppTokenService(this.http);
}
/**
* Send a one-time password (OTP) token via SMS, WhatsApp, or Email
*
* @param payload - Request payload with OTP configuration and message
* @returns Expanded `SendTokenResponse` containing PIN details
*/
async sendToken(payload) {
return this.http.request("/sms/otp/send", {
method: "POST",
data: payload,
authLocation: "body"
});
}
/**
* Send a one-time password (OTP) token via Voice call
*
* @param payload - Request payload with phone number and OTP parameters
* @returns Expanded `VoiceTokenResponse` with OTP call details
*/
async sendVoiceToken(payload) {
return this.http.request("/sms/otp/send/voice", {
method: "POST",
data: payload,
authLocation: "body"
});
}
/**
* Initiate a direct voice call delivering a numeric code
*
* @param payload - Request containing phone number and numeric code
* @returns Expanded `VoiceCallResponse` with call status
*/
async sendVoiceCall(payload) {
return this.http.request("/sms/otp/send/call", {
method: "POST",
data: payload,
authLocation: "body"
});
}
}