Sending WhatsApp OTP and Notification with Nodejs
A quick walk-through on how to send WhatsApp OTP and Notification with Sendchamp WhatsApp API with Nodejs
Aliyu Abubakar
Aug 12, 2021
Learn how to quickly send WhatsApp OTP and notifications with Node.js using sendchamp API.
In this guide we will walk you through:
- Signing up free Sendchamp account
- Activate WhatsApp Number
- Setting up a Nodejs Application
- Sending your WhatsApp OTP and Notification
Prerequisite
Before you can get started, you need the following already set up:
- Node.js and a familiarity with how to create a new app.
- A sendchamp account
- Activated WhatsApp Number
Signing up free sendchamp account
If you Already have an account? skip to the next section You can sign up for a free sendchamp account here.
When you sign up, you'll have to verify your email address. This allows sendchamp to verify your identity.
After you've verified your email address, you'll be asked a question in order to get you started in a way that's relevant to you.
After you finish setting up your account, you'll have access to your dashboard where you can access your API Key and perform dashboard communication functions.
Active a WhatsApp Number
Visit your sendchamp dashboard and navigate to WhatsApp channel.
Click on activate number and choose a subscription plan that is suitable for you. You won’t be asked to pay for it until your number is active.
When you select a plan, you’ll be redirected to a page that would ask you to fill in the necessary information. Basic information, WhatsApp account information and your business information.
Setting up a Nodejs Application
Create a new node app with NPM.
npm init
Create a new file named index.js in the project and paste the provided "WhatsApp OTP and Notification" code into the file.
Code Sample
var request = require('request');
var options = {
'method': 'POST',
'url': 'https://sandbox-api.sendchamp.com/api/v1/whatsapp/template/send',
'headers': {
'Accept': 'application/json',
'Authorization': 'Bearer SECRET_KEY'
},
body: JSON.stringify({"recipient":"2348055372961",
"type": "template",
"template_code": "TEMPLATE_CODE",
"sender":"234810000000",
"custom_data": {
"body": {
"1": "Damilola",
"2": "Olotu",
"3": "Lagos"
}
}
}})
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
Parameters
Parameter | Your Value |
---|---|
recipient required. | This represents the destination phone number. E.g 2349000000000) |
type required. | type of message being sent. |
sender required. | This will be the activated Whatsapp phone number E.g 234810000000 |
template_code required. | You can find this on the template page under Whatsapp Channel of your Sendchamp dashboard |
Sending your WhatsApp OTP and Notification
Now you can execute the code to send your WhatsApp message.
Run the following command:
node index.js
The code you used in the index.js file sends a POST request to the sendchamp API endpoint to send your WhatsApp message.