create account

How To Send Message TO WhatsApp Using JavaScript/Node.js-- Twilio by pakgamer

View this thread on: hive.blogpeakd.comecency.com
· @pakgamer ·
$11.20
How To Send Message TO WhatsApp Using JavaScript/Node.js-- Twilio
## <center> Hello everyone</center>


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](https://www.twilio.com/) website and create a free account.


![image.png](https://images.hive.blog/DQmVv1rMr1hNN65NKtdPsrztau6niEPy8QSRBywBPavZSqP/image.png)
 After creating the account login to your account and click on the three dots.


![image.png](https://images.hive.blog/DQmYszS4CmEi7sCaNoudz7z3Ar5AgxBKoJnG9CHHosSvBUD/image.png)

Now click on the programmable SMS . 

![image.png](https://images.hive.blog/DQmf6cL6SYh3d7o5irBc7T4QxP7paG7fbxWX5632qa9uVf6/image.png)


Click on the whatsapp beta and then activate the sanbox

![image.png](https://images.hive.blog/DQmcXv4dt75ScA3ktKNNuSoWTe3bSmCA8JJgZqfDCAUNUXn/image.png)


Now send the given code to the given number in order to connect your WhatsApp number.
![image.png](https://images.hive.blog/DQmV6fZR72VeZSnzmb5ckHJU4XGZMYBM8GgcgC9TpYJrCLS/image.png)

You will get a message like this after sending the code to the number.


![image.png](https://images.hive.blog/DQmcTDG4gXjPKH18FQVCBNYWvWtx1dUoYeGgv4LZmgsZUcC/image.png)

Now go back to the main page of Twilio and copy the following keys.



![image.png](https://images.hive.blog/DQmNyDPWL8pnMaXFHdna7e6F1bCUxpuxQU5U1WNiJ8Yn8F5/image.png)
 
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.


![image.png](https://images.hive.blog/DQmUFvTAx7PpbWHNh4jDEJEZTYUGL9MYDKcxpikSNyJCZoX/image.png)

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


![image.png](https://images.hive.blog/DQmPsqeoAdF9zwbdu3FqiErcTjgamsGPRTX8ypjRtTvbawk/image.png)

If your message is sent successfully you should get output like this
![image.png](https://images.hive.blog/DQmeHDq85awE7gTgme7pt6agz2utgh3WPKMGMamiUWVgZcL/image.png)

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.

![image.png](https://images.hive.blog/DQmdY8HQq6bYUQs4m5hScTx5U1S1nXvZbrNq4gmEN7KBXCw/image.png)



<center>
**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**
![ntitled-1.png](https://images.hive.blog/DQmd3WcHH8i6U2JkmnrvEvd4FwjDQxJtG3Tnhzxdjswktdx/ntitled-1.png)</center>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 38 others
properties (23)
authorpakgamer
permlinkhow-to-send-message-to-whatsapp-using-javascript-node-js-twilio
categoryhive-148441
json_metadata{"tags":["hive-148441","programming"],"image":["https://images.hive.blog/DQmVv1rMr1hNN65NKtdPsrztau6niEPy8QSRBywBPavZSqP/image.png","https://images.hive.blog/DQmYszS4CmEi7sCaNoudz7z3Ar5AgxBKoJnG9CHHosSvBUD/image.png","https://images.hive.blog/DQmf6cL6SYh3d7o5irBc7T4QxP7paG7fbxWX5632qa9uVf6/image.png","https://images.hive.blog/DQmcXv4dt75ScA3ktKNNuSoWTe3bSmCA8JJgZqfDCAUNUXn/image.png","https://images.hive.blog/DQmV6fZR72VeZSnzmb5ckHJU4XGZMYBM8GgcgC9TpYJrCLS/image.png","https://images.hive.blog/DQmcTDG4gXjPKH18FQVCBNYWvWtx1dUoYeGgv4LZmgsZUcC/image.png","https://images.hive.blog/DQmNyDPWL8pnMaXFHdna7e6F1bCUxpuxQU5U1WNiJ8Yn8F5/image.png","https://images.hive.blog/DQmUFvTAx7PpbWHNh4jDEJEZTYUGL9MYDKcxpikSNyJCZoX/image.png","https://images.hive.blog/DQmPsqeoAdF9zwbdu3FqiErcTjgamsGPRTX8ypjRtTvbawk/image.png","https://images.hive.blog/DQmeHDq85awE7gTgme7pt6agz2utgh3WPKMGMamiUWVgZcL/image.png","https://images.hive.blog/DQmdY8HQq6bYUQs4m5hScTx5U1S1nXvZbrNq4gmEN7KBXCw/image.png","https://images.hive.blog/DQmd3WcHH8i6U2JkmnrvEvd4FwjDQxJtG3Tnhzxdjswktdx/ntitled-1.png"],"links":["https://www.twilio.com/"],"app":"hiveblog/0.1","format":"markdown"}
created2020-06-20 19:43:51
last_update2020-06-20 19:43:51
depth0
children2
last_payout2020-06-27 19:43:51
cashout_time1969-12-31 23:59:59
total_payout_value5.722 HBD
curator_payout_value5.479 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length3,198
author_reputation19,304,605,112,640
root_title"How To Send Message TO WhatsApp Using JavaScript/Node.js-- Twilio"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,081,822
net_rshares26,908,178,852,596
author_curate_reward""
vote details (102)
@gitplait-mod1 ·
Another good tutorial. @pakgamer you efforts for sharing knowledge by making amazing tutorial are laudable. We are looking for people like you in our community. 

Your post has been curated with @gitplait community account because this is the kind of publications we like to see in our community.

Join our Community on [Hive](https://hive.blog/trending/hive-103590) and Chat with us on [Discord](https://discord.com/invite/CWCj3rw).
properties (22)
authorgitplait-mod1
permlinkqc9m61
categoryhive-148441
json_metadata{"users":["pakgamer","gitplait"],"links":["https://hive.blog/trending/hive-103590","https://discord.com/invite/CWCj3rw"],"app":"hiveblog/0.1"}
created2020-06-21 07:30:03
last_update2020-06-21 07:30:03
depth1
children0
last_payout2020-06-28 07:30:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length433
author_reputation64,455,719,431
root_title"How To Send Message TO WhatsApp Using JavaScript/Node.js-- Twilio"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,090,105
net_rshares0
@hivebuzz ·
Congratulations @pakgamer! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s) :

<table><tr><td><img src="https://images.hive.blog/60x70/http://hivebuzz.me/@pakgamer/upvotes.png?202006220304"></td><td>You distributed more than 500 upvotes. Your next target is to reach 600 upvotes.</td></tr>
</table>

<sub>_You can view [your badges on your board](https://hivebuzz.me/@pakgamer) And compare to others on the [Ranking](https://hivebuzz.me/ranking)_</sub>
<sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub>



###### Support the HiveBuzz project. [Vote](https://hivesigner.com/sign/update_proposal_votes?proposal_ids=%5B%22109%22%5D&approve=true) for [our proposal](https://peakd.com/me/proposals/109)!
properties (22)
authorhivebuzz
permlinkhivebuzz-notify-pakgamer-20200622t074647000z
categoryhive-148441
json_metadata{"image":["http://hivebuzz.me/notify.t6.png"]}
created2020-06-22 07:46:45
last_update2020-06-22 07:46:45
depth1
children0
last_payout2020-06-29 07:46:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length812
author_reputation370,776,866,904,634
root_title"How To Send Message TO WhatsApp Using JavaScript/Node.js-- Twilio"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,108,331
net_rshares0