Skip to content
← Back to Community
Build a WhatsApp bot in 30 minutes πŸ•
Profile icon
h
has Hacker Plan
jajoosam

A few months ago, I'd started making chatbots on Telegram - I'd seen APIs for WhatsApp but they were unoffical and there was a chance for getting your number blocked πŸ“± ❌

A while ago, I saw that Twilio had an official WhatsApp API. 30 minutes later, I made a Wikipedia bot on WhatsApp πŸ‘‡

This is a tutorial to help you make a something like this, your own chatbots on WhatsApp - these bots are immediately available to 2 billion users, and there are so many things possible πŸŽ“

I can't wait to see what you make! Now, let's get started πŸƒβ€β™‚οΈ

πŸ”‘ Accounts and Keys

First, Sign up for Twilio - it's free and you won't need a credit card πŸ’³

Once you're done verifying your phone number, select Procuts > Programmable SMS and then continue to name your project.

Feel free to skip steps for adding teammates - you won't need that for now.

You must now take note of some authentication keys you'll need for building the WhatsApp bot πŸ‘‡

The final step - setup your WhatsApp Sandbox here - choose any number, and join your sandbox following instructions on the page.

Aaaaaand you're done with credential setup! Don't worry, that was the toughest part of this tutorial πŸ˜›

πŸš€ Getting Started

So that we don't spend too much time on setup, I've created an environment (with repl.it!) you can use within your browser. Head over here, and wait for a couple of seconds to fork it.

Next, open up server.js and put in your Account SID and Auth Token, on lines 7 and 8

const accountSid ="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; //Account SID const authToken ="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; // Auth Token

You can see, this environment already has dependencies installed, and an express server set up. We still need to give Twilio a URL to send incoming messages to, though πŸ”—

Let's go back to the WhatsApp Sandbox, and put in a webhook URL for incoming messages.

This URL must be what you see on the preview panel of your repl.it project + /incoming

We can now finally read messages that are sent to the bot. Add a simple console.log() in your webhook handler πŸ‘‡

app.post('/incoming', (req, res) => { console.log(req.body) });

When you send a message to your bot, you should be able to see something like this in your repl console πŸ‘¨β€πŸ’»

Building an echo bot would look something like this, using twiml to write a message πŸ‘‡

app.post('/incoming', (req, res) => { const twiml = new MessagingResponse(); twiml.message(req.body.Body); res.writeHead(200, {'Content-Type': 'text/xml'}); res.end(twiml.toString()); });

But, since we're actually trying to build a useful bot - let's use informative APIs!

🌐 Fetching Information

DuckDuckGo has an amazing, free instant answer API. It takes in a query and returns back a summary from WikiPedia and more.

A few examples πŸ‘‰ WikiPedia, Macbook Air, Twilio

I spent some time creating a decent parser which usually returns information from this API. Try pasting this code in your repl.it project, and your console should have stuff about Trump in it πŸ˜›

var base = 'https://api.duckduckgo.com/?skip_disambig=1&format=json&pretty=1&q='; var query = 'Donald Trump'; request(base + query, function (error, response, body) { body = JSON.parse(body) if(body["Abstract"] == ""){ body["Abstract"]= body["RelatedTopics"][0]["Text"] } var msg = body["Heading"]+"\n\n"+body["Abstract"]; console.log(msg) });

Pretty straight forward, right? πŸ˜„

πŸ› οΈ Putting it all together

To make our actual bot, all we need to do is get the query from our request - which we can get as req.body.Body - and use twmil to send across the data we collected in msg

app.post('/incoming', (req, res) => { const twiml = new MessagingResponse(); var base = 'https://api.duckduckgo.com/?skip_disambig=1&format=json&pretty=1&q='; var query = req.body.Body; request(base + query, function (error, response, body) { body = JSON.parse(body) if(body["Abstract"] == ""){ body["Abstract"]= body["RelatedTopics"][0]["Text"] } var msg = twiml.message(body["Heading"]+"\n\n"+body["Abstract"]); res.writeHead(200, {'Content-Type': 'text/xml'}); res.end(twiml.toString()); }); });

You now have a fully functionaing WhatsApp bot! Send anything you want to know about your bot πŸ€– and you should see it respond super fast πŸ’¬ ⚑

Adding welcome messages and a little formatting is quite simple, look at the final repl to see how I did it πŸ‘¨β€πŸ’»

πŸ”— Sharing the bot

For others to use this bot, they'll need to join your sandbox first - and send a message just like you did earlier πŸ‘‰ join <two-words>

You can create links with this text too - For example this link lets you join my bot πŸ‘‡

https://wa.me/14155238886?text=join ultramarine-tapir

14155238886 is my bot's number, while ultramarine-tapir is the sandbox phrase.

⚑ What's next?

Now that you know how to build a bot on WhatsApp, try sending notifications to yourself, and building more useful tools! Twilio has loads of other mediums to message through too!

All code for my WikiBot is on Github!

I'm a 15 year old maker πŸ‘¨β€πŸ’» For more cool things to make and to stay update with my progress, sign up for my newsletter πŸ“§

Voters
Profile icon
HetavPaiAngle
Profile icon
wendelknow
Profile icon
Alisson-Arellan
Profile icon
kokoe-beep
Profile icon
theDami
Profile icon
kaveedev
Profile icon
whattyu
Profile icon
MatheoAbdiel
Profile icon
EhanireOghogho
Profile icon
EmilieBrock
Comments
hotnewtop
Profile icon
abdulsamad26

Tap on the Install button. It will then take you to the Android installation interface where it will show you the permissions required for the app. Tap β€˜Install’ again for the installation to begin. wwe 2k20 Apk

Profile icon
abdulsamad26

Once the contamination has taken place on a macOS or Mac OS X system, the redirects to search.yahoo.com are usually triggered according to a specific pattern rather than haphazardly. yahoo redirect The victims report their Google searches being forcibly diverted to Yahoo.

Profile icon
Eidulfitr2022

The article posted was very informative and useful. You people are doing a great job. Keep going. Please visit site https://eidulfitr2022.com/

Profile icon
Robert-CC2

Taptap Heroes Mod APK has all the features unlocked, which means no purchases are required for players to win the game.Taptap Heroes Mod APK

Profile icon
Alltrackingcour

Everyone has a hard time getting out of bed in the winter. That's totally understandable because it's so cold outdoors that we don't want to leave the comfort of our favorite blankets. However, on the other hand, this makes us quite lazy, and at the end of the day, we regret an unproductive day.
blanket hoodies

Profile icon
apkhunter

Thanks for sharing check the A game in which players can make their own rules and do everything which they want. Moreover, players can enjoy all those rules that are required in their daily life. Gacha Life Old Version apk

Profile icon
EmmaBrook

Live QR Code Generator is a leading cloud-based platform with thousands of users worldwide. We make it easy for everyone to create editable and scan qr code chrome. Make use of our Dynamic QR Codes to drive more traffic and revenue.

Profile icon
MalikMalik5

Allows users to search for life, on GB WhatsApp , pro apk, and much more apps here with best user experience: https://thegbapp.com/gbwhatsapp-apk/

Profile icon
ayaanly

damn this seems soo cool, BTW will it work in FM WhatsApp MOD? here - (https://www.avoid.uk.net/fmwhatsapp/) I am using this app since a long time if yes then kindly upload a detailed youtube video https://www.avoid.uk.net/youtube-vanced-apk-download/

Profile icon
Ronnieorton

Thank you for the information you share, if you are a video editing enthusiast, you can't miss this font store. Access now https://yofonts.com/styles/hindi to download free, simple fonts.

Profile icon
ceciliaparks

use YouTube Music Premium latest version https://techgara.com/youtube-music

Profile icon
Terranceii

Thanks for the information you share, download free ringtones with lots of trending music. Visit now https://klingeltonmobi.de/

Profile icon
Grandson009

Thanks for sharing this stunning info about how can we build a whatsapp bot in 30 minutes.I really like this and would like to share it via Yo whatsapp that I have downloaded from official site https://playapkpro.com/yowhatsapp-apk/

Profile icon
mohan311

It is also a default gateway that is used worldwide by the various popular router and modem brands.
https://www-192-168-100-1.com/
https://192-168-l0-1.club/192-168-10-1/

Profile icon
KateDouglas

Can you give me a link to make the basic WhatsApp Plus ( https://wasplus.com )

Profile icon
PatKelley

New fastest bot creation feature on Yo Whatsapp at https://yowaplus.net

Profile icon
AyushKukreti

nice thanks

Profile icon
dhamelvishal
Profile icon
kleytonos

Hey, still works? "wikibot-start" there is no file named "server.js" or any files. Could you take a look for us. Thanks!

Profile icon
perrymay

@kleytonos Thank you for sharing you can download Cinema HD here to be able to enjoy watching the latest great movies that are constantly being updated https://cinemahdplus.com/

Profile icon
KermitBailey

@perrymay Besides you can try Rokkr allows users to search for live streams of TV channels, movies, sports and much more here: https://rokkrplus.com/fr/

Profile icon
AnthonyAnthony4

@perrymay
Thank you for sharing you can download FHX COC the modified version of Clash of clans becomes a more popular video game day by day. https://cocpureapk.com/coc-fhx-server/

Profile icon
princeapkapk

here are a lot of apps that can be used to simplify different android applications. So I am going to tell you one of the best apps from them, Lulubox APK. https://princeapk.com/lulubox-apk/

Profile icon
phighhiapk

Did you want to buy Cute Thigh High Socks then check https://thighhighsocks.shop/collections/cute-thigh-high-socks

Profile icon
Grandson009

I was searching for a mobile app which should be as useful as cash app plus plus https://gbfunda.com/cash-app-plus-plus/
.then I visit to your blog and nkow I have found thatt app named by whatsapp.

Profile icon
Coder100

Hey, can you teach me how you made the newsletter?

Profile icon
jajoosam
Profile icon
Coder100

@jajoosam Thanks!

Profile icon
danclay
Profile icon
danclay

That's pretty useful in daily life. But will it work with a WhatsApp Mod APK?

Profile icon
dhamelvishal
Profile icon
JOmbra

thanks man for this tutorial.
One question how i can use multi API to bring more information

Profile icon
jajoosam

@JOmbra You can have more requests inside the block where you're fetching information from the DuckDuckGo API :)

Profile icon
makeavish

On twilio it's showing this error
Error - 11200
HTTP retrieval failure
and on repl.it terminal it doesnot shows any info about incoming message.
Please help.

Profile icon
jajoosam

@makeavish can you share your repl with me? - I'll take a look :)

Profile icon
makeavish
Profile icon
Obvio

@makeavish @jajoosam it should be app.post('/', (req, res) => {

Profile icon
kaldisberzins

Too many emojis

Profile icon
jajoosam

@kaldisberzins but emojis are the best πŸŽ‰

Profile icon
kaldisberzins

@jajoosam Nah man, emoticons (>_<)

Profile icon
[deleted]

@kaldisberzins emoticons all the way :3

Profile icon
AdeeshJain

@kaldisberzins Emojis make life