A zero-dependency TypeScript/JavaScript module for interacting with the Kavenegar API, allowing you to send SMS messages, manage message status, and perform other actions.
npm install --save kavenegar-api
Replace 'YOUR_API_KEY' with your actual API key.
import { KavenegarApi } from 'kavenegar-api';
// OR
const { KavenegarApi } = require('kavenegar-api');
// Initialize the Kavenegar API with your API key
const apiKey = 'YOUR_API_KEY' || 0 // set apiKey to zero just for test connection;
const kavenegar = new KavenegarApi({ apiKey });
async function testConnection() {
const date = await kavenegar.getDate();
console.log('Connection successful. Current date:', date.datetime);
}
async function sendSingleSMS() {
const message = 'Hello, world!';
const receptor = 'RECIPIENT_NUMBER';
const result = await kavenegar.send({ message, receptor });
console.log('Single SMS sent:', result);
}
async function sendMultipleSMS() {
const messages = ['Hello', 'Hi', 'Hey'];
const receptors = ['RECIPIENT_1', 'RECIPIENT_2', 'RECIPIENT_3'];
const senders = ['SENDER_1', 'SENDER_2', 'SENDER_3'];
const result = await kavenegar.sendArray({ message: messages, receptor: receptors, sender: senders });
console.log('Multiple SMS sent:', result);
}
async function verifyPhoneNumber() {
const receptor = 'RECIPIENT_NUMBER';
const token = '123456';
const template = 'TEMPLATE_NAME';
const result = await kavenegar.verifyLookup({ receptor, token, template });
console.log('Verification result:', result);
}
async function checkSMSStatus() {
const messageIds = [1234567890, 9876543210]; // Replace with actual message IDs
const status = await kavenegar.status({ messageid: messageIds });
console.log('SMS Status:', status);
}
async function cancelSMSSending() {
const messageId = 1234567890; // Replace with actual message ID
const result = await kavenegar.cancel({ messageid: messageId });
console.log('SMS Cancelled:', result);
}
async function receiveSMS() {
const lineNumber = 'YOUR_LINE_NUMBER'; // Replace with actual line number
const isRead = 0; // 0 for unread, 1 for read
const receivedMessages = await kavenegar.receive({ lineNumber, isRead });
console.log('Received SMS:', receivedMessages);
}
async function getAccountInfo() {
const accountInfo = await kavenegar.accountInfo();
console.log('Account Information:', accountInfo);
}
async function configureAccount() {
const accountConfigs = {
apilogs: 'enabled',
dailyreport: 'disabled',
debugmode: 'enabled',
defaultsender: 'YOUR_SENDER_ID',
mincreditalarm: 100,
resendfailed: 'enabled'
};
const configuredSettings = await kavenegar.accountConfig(accountConfigs);
console.log('Account Settings Configured:', configuredSettings);
}
async function makeTTS() {
const receptor = 'RECIPIENT_NUMBER';
const message = 'Hello, this is a text-to-speech message.';
const result = await kavenegar.callMakeTTS({ receptor, message });
console.log('Text-to-Speech Call result:', result);
}
- statusLocalMessageId
- select
- selectOutbox
- latestOutbox
- countInbox
- countOutbox
Feel free to customize and expand these examples according to your needs!
This README provides clear instructions on how to use the Kavenegar API module and includes examples for some of its functions.
For more information, visit the Kavenegar official website.