Skip to main content

Node.JS - SDK

The CallSDK is designed to provide a straightforward and efficient way to implement flash call (missed call) authentication within your applications. It abstracts the complexities of interacting directly with the underlying API, allowing developers to quickly and easily integrate phone number verification through missed calls. This SDK is particularly useful for scenarios requiring secure and rapid user authentication.

Installation

Install the SDK

npm install betatel-sdk

Import the SDK

import { CallSDK } from 'betatel-sdk'; //or './path/to/CallSDK' if local.

Initialization

Create an instance of the CallSDK:

const callSDK = new CallSDK({
base_url: 'YOUR_API_BASE_URL', // Replace with your API base URL
api_key: 'YOUR_API_KEY', // Replace with your API key
version: 'YOUR_API_VERSION' //Replace with your API version
});

Replace YOUR_API_BASE_URL, YOUR_API_KEY, and YOUR_API_VERSION with the actual values provided by your service.

warning

Security Notice:

Keep your API key secure. Do not expose it in client-side code or commit it to version control. Store it securely and retrieve it from a safe source.

Usage: Initiating a Flash Call

Use the flash method:

async function initiateFlashCall(callee: string, caller: string, maxRingTime?: number) {
try {
const success = await callSDK.flash(callee, caller, maxRingTime);

if (success) {
console.log('Flash call initiated successfully!');
} else {
console.log('Flash call initiation failed.');
}
} catch (error) {
console.error('Error initiating flash call:', error);
}
}

// Example usage:
initiateFlashCall('+15551234567', '+15559876543', 7); // Example phone numbers and maxRingTime
initiateFlashCall('+15551234567', '+15559876543'); //example without optional maxRingTime
tip

Phone Number Formatting:

Ensure that the phone numbers you provide are in the E.164 format (e.g., +15551234567) or the format expected by your API. Consult your API documentation for specifics.

ParameterTypeDescription
calleestringThe phone number of the person to be called.
callerstringThe phone number of the person making the call.
maxRingTimenumber(Optional) The maximum time (in seconds) to ring before the call is considered failed.

Error Handling:

  • The flash method will throw an error if the API response status code is not valid (e.g., 4xx or 5xx errors).
  • Wrap your flash call within a try...catch block to handle these errors gracefully.

Example of complete integration

import { CallSDK } from 'your-sdk-name'; //or './path/to/CallSDK' if local.

const callSDK = new CallSDK({
base_url: 'https://api.example.com', // Replace with your API base URL
api_key: 'YOUR_API_KEY_HERE', // Replace with your API key
version: 'v1' //Replace with your API version
});

async function initiateFlashCall(callee: string, caller: string, maxRingTime?: number) {
try {
const success = await callSDK.flash(callee, caller, maxRingTime);

if (success) {
console.log('Flash call initiated successfully!');
} else {
console.log('Flash call initiation failed.');
}
} catch (error) {
console.error('Error initiating flash call:', error);
}
}

initiateFlashCall('+15551234567', '+15559876543');
note

Important notes

  • Ensure that the phone numbers are in the correct format expected by your API.
  • Consult your API documentation for any specific requirements or limitations.
  • Keep your API key secure and do not expose it in client-side code.