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.
npm install notify-lk --save
Run the above command in your project directory to install the package.
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));
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).
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).
Retrieves the account status including the balance and active status.
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));
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));
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));
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));
});
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);
}
});
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));
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.