How To Send Message TO WhatsApp Using JavaScript/Node.js-- Twilio
Hello everyone
In this post, we are going to learn how to send a message to WhatsApp using JavaScript/node.js. In this video, we will send some messages to my WhatsApp number through a small piece of code. We are going to use Twilio Node Library. This will help us connect our code to the WhatsApp. So let's begin the tutorial.
First of all, if you don't have the Nodejs installed please install it from the official site.
Now go to the Twilio website and create a free account.
After creating the account login to your account and click on the three dots.
Now click on the programmable SMS .
Click on the whatsapp beta and then activate the sanbox
Now send the given code to the given number in order to connect your WhatsApp number.
You will get a message like this after sending the code to the number.
Now go back to the main page of Twilio and copy the following keys.
Open VS Code and install the Twilio library by running the following command.
npm install twilio
Wait for the installation and then copy-paste the below code to a newly .js file
const accountSid =YOUR_SID;
const authToken = YOUR_KEY;
const client = require('twilio')(accountSid, authToken);
client.messages
.create({
from: 'whatsapp:+14155238886',
body: 'Hello from nodejs',
to: RECIVER-NUMBER
})
.then(message => console.log(message.sid));
Assign the keys to the variables.
In my case, I have created a JSON file and everything ting is in the JSON. Just for privacy purpose you can just assign them to the variables.
Let's run the script now
If your message is sent successfully you should get output like this
As you can see the messages are successfully sent. If you want to change the message just change the text in body and rerun the code.
I think this much is enough for today. Now if you like the post please upvote and comment if you want to give me some advise
Leave How To Send Message TO WhatsApp Using JavaScript/Node.js-- Twilio to:
Read more #hive-148441 posts
Best Posts From ProGrammer
We have not curated any of pakgamer's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From ProGrammer
- What do you think your Password is Secure?
- Nodejs Tutorial-- Sending Email using NodeMailer
- Node.js Tutorial --Reading and Writing files
- How to install Nodemon-- Express.js Tutorials
- How to use Range Element in a simple voting tool
- Learning Express.js-- installation and Hello World Example
- How to Compile your C/C++ code on the Visual Studio Code.
- How to check Voting Power And Resource Credit of Hive Account Through dhive
- How To Send Message TO WhatsApp Using JavaScript/Node.js-- Twilio
- How to add Custom prefix to your Discord Bot. Discordjs Tutorial
- HiveJs Tutorials --Learning how to transfer HIVE/HBD thorugh HiveJs
- Fetching API -- JavaScript Tutorial
- Learning Local Storage in JavaScript..
- Hivejs Tutorials-- #3
- Learn jQuery. Learning Events/Methods
- Learn jQuery --- Learning Selectors
- Learning JQuery-- Understanding the basics
- TypeScript for beginners -- A quick start
- How to Stream Hive Blockchain Transactions.-- HIVED
- Grand Theft Auto V (GTA 5) is now free on Epic Games Store.