notify-lk
v1.0.1
Published
A Node.js package for interacting with the Notify.lk API. This package provides functionality to send SMS messages, check account status, manage contacts, and retrieve SMS history using the Notify.lk service.
Downloads
7
Maintainers
Readme
Notify.LK Documentation
Introduction
Welcome to the NotifyLK NPM package documentation. This package enables you to send SMS messages, check account status, and manage contacts using the Notify.lk API.
Installation
npm install notify-lk --save
Run the above command in your project directory to install the package.
Usage
Here’s how to use the NotifyLK package in your Node.js application:
const NotifyLK = require('notify-lk');
const notify = new NotifyLK('YOUR_USER_ID', 'YOUR_API_KEY', 'YOUR_SENDER_ID');
notify.sendSMS('9471XXXXXXX', 'Hello from NotifyLK')
.then(response => console.log(response))
.catch(error => console.error(error));
API Reference
NotifyLK(userId, apiKey, senderId)
Constructor for creating a new instance of the NotifyLK class.
- userId: string - Your Notify.lk user ID.
- apiKey: string - Your Notify.lk API key.
- senderId: string - The sender ID for your messages (default: NotifyDEMO).
sendSMS(to, message, options)
Sends an SMS to the specified number.
- to: string - The recipient's phone number in 94XXXXXXXXX format.
- message: string - The message to be sent.
- options: object - Additional options for the message (optional).
getAccountStatus()
Retrieves the account status including the balance and active status.
Examples
1. Sending a Simple SMS
This example demonstrates how to send a simple SMS using the NotifyLK package:
const NotifyLK = require('notify-lk');
const notify = new NotifyLK('YOUR_USER_ID', 'YOUR_API_KEY', 'YOUR_SENDER_ID');
notify.sendSMS('9471XXXXXXX', 'Hello from NotifyLK')
.then(response => console.log('SMS Sent:', response))
.catch(error => console.error('Error Sending SMS:', error));
2. Checking Account Status
This example shows how to check your account's status, including balance and active status:
notify.getAccountStatus()
.then(status => console.log('Account Status:', status))
.catch(error => console.error('Error Fetching Account Status:', error));
3. Sending SMS with Unicode Characters
To send an SMS containing Unicode characters (e.g., emojis, non-Latin scripts), include the type
option:
notify.sendSMS('9471XXXXXXX', 'Hello from NotifyLK 😊', { type: 'unicode' })
.then(response => console.log('Unicode SMS Sent:', response))
.catch(error => console.error('Error Sending Unicode SMS:', error));
4. Bulk SMS Sending
Sending SMS to multiple recipients in a loop:
const numbers = ['9471XXXXXXX', '9472XXXXXXX', '9473XXXXXXX'];
const message = 'Hello from NotifyLK';
numbers.forEach(number => {
notify.sendSMS(number, message)
.then(response => console.log(`SMS Sent to ${number}:`, response))
.catch(error => console.error(`Error Sending SMS to ${number}:`, error));
});
5. Handling SMS Errors Gracefully
This example demonstrates how to handle errors, such as invalid phone numbers or API issues:
notify.sendSMS('invalid_number', 'This message will fail')
.then(response => console.log('SMS Sent:', response))
.catch(error => {
if (error.response && error.response.data) {
console.error('API Error:', error.response.data);
} else {
console.error('Unknown Error:', error.message);
}
});
6. Scheduling SMS for Future Delivery
If Notify.lk supports scheduling (hypothetical, as the real API may not), you could do something like this:
const scheduleDate = new Date(Date.now() + 60 * 60 * 1000); // 1 hour from now
notify.sendSMS('9471XXXXXXX', 'This message is scheduled for future delivery', { send_at: scheduleDate.toISOString() })
.then(response => console.log('Scheduled SMS Sent:', response))
.catch(error => console.error('Error Scheduling SMS:', error));
Author
This package is maintained by Omindu Dissanayake.
For more information, visit the GitHub profile. License
This package is licensed under the MIT License. See the LICENSE file for more information.