Skip to content
Sign upLog in
← Back to Community

Build a WhatsApp bot in 30 minutes πŸ•

Profile icon
jajoosamHacker

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
DarrellPowerss

You can cΓ i Δ‘αΊ·t ngay after reading this article, an extremely detailed tutorial.

Profile icon
nazmahasan

GBWhatsApp features an excellent option for retrieving WhatsApp messages. Typo mistakes or the message we wish we hadn't sent are two examples of situations when a tool for recalling a sent message might be helpful https://www.teernews.in/topic/gb-whatsapp-pro-apk-download-latest-version-v12-android-whatsapp-plus

Profile icon
Coder100

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

Profile icon
jajoosam

@Coder100
sure - check out https://buttondown.email :)

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

@Coder100
https://apkgrape.com/thoptv-apk-download-1/

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

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

@jajoosam
https://repl.it/@makeavish/wikibot-start
Thanks

Profile icon
Obvio

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

Profile icon
Rosalie7

his was really very informative site for me. I really liked it. Thanks a lot!. WA Plus

Profile icon
AhteshamKhan1

Krnl is one of the best and reliable Roblox exploits used to get an advantage by using exploiting the vulnerabilities of the script.https://krnl.vip/

Profile icon
AhteshamKhan1

A macrogamer is a pre-programmed command that makes data entering easier. Individual keys on Gaming Mouse and keyboards are referred to as macro keys by gamers. Macro keys are a set of keys that can be pushed repeatedly to do the same task. https://macrogamer.org/

Profile icon
AhteshamKhan1

Synapse X is a engine which use for scripting, this is powerful tool that execute all Roblox scripts easily.

Dark Dex, ESP, Stream Sniper, Remote Spy, Script Dumper, Teleport, Speed, Fly, Infinite jump, everything in one package.https://synapsex.co/

Profile icon
AhteshamKhan1

TinyTask is the greatest Roblox and Minecraft Autoclicker. It’s also useful for everyday tasks. It simply records mouse clicks and plays them again! https://tinytask.app/

Profile icon
DeaconAnnie

it's a good and useful article, https://apktodo.com/vi/stick-war-legacy a reputable site to download free games with the best quality!

Profile icon
befunky
Profile icon
saivenkat13

capcut for pc download - windows 7/8/10/11, Capcut online, mac, chromebook, how to use capcut, capcut pro, mod apk. all capcut tips and tutorials.

https://www.capcutforpcdownloadguide.com/

Profile icon
poptesse

Can we have this bot work on gbwhatsapp apk android? I have both whatsapp and I want to have this for chatting.

Profile icon
Rosalie7

I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post gbwa

Profile icon
AmberGoldstain

I also created a WhatsApp named CΓ“MO INSTALAR WHATSAPP PLUS
without any bugs and issues.

Profile icon
Fernand99

Super blockbuster 2022 with the hottest mod games. You will own infinite gold, infinite diamonds and unlimited emotions when you come to us https://apktodo.com/vi/

Profile icon
rahul142

Rakshabandhan (or Rakhi) is a Hindu festival, taking place on the full moon in the month of Sravana, which celebrates brotherhood and love. https://funkylife.in/raksha-bandhan-images/

Profile icon
lucaspete20s

Canelo Alvarez and Gennady Golovkin signed up for drug testing after their trilogy fight was officially confirmed.

Profile icon
robertwadraa

MacroGamer is a program that provides ardent gamers with the tools they need to become more effective and successful in the games they play. https://macrogamer.org/

Run 3 is an endless runner game in which you control a small alien through space. https://run3unblocked.net/

Krnl is one of the best and reliable Roblox exploits used to get an advantage by using exploiting the vulnerabilities of the script.https://krnl.vip/

Profile icon
robertwadraa

SmartTubeNext is an advanced YouTube app for Android TVs and TV boxes, free & open source. It is not a live TV client and does not support "YouTube TV".

βœ… Features: no ads | SponsorBlock | adjustable playback speed | 4k and higher | 60fps | HDR | does not require Google Services | helpful international community

❌ Disadvantages: no live chat | no comments stability, voice search and casting support might be worse than in the official YouTube, depending on your device Download page Here https://smarttubenext.net/

Profile icon
robertwadraa

MegaBox HD is an app that lets you enjoy hundreds of movies and TV shows from your Android. You get to choose if you want to download or stream them. That way, you can also select if you want to watch your content in 360p, 720p or 1080p resolution.

The interface on MegaBox HD is very intuitive. Within the dropdown menu bar on the left you'll find easy access to movies and TV shows. Also, inside each category you'll be able to filter results by popularity, latest releases, and according to positive user reviews. Of course, you'll also get to choose if you want to use the search bar to look for a specific movie or TV show. https://megaboxhdapk.com/

Profile icon
robertwadraa

Hey Guys, if you love to edit videos and create animation videos, graphic animation videos, etc. So Alight Motion Pro APK is the best video editing app for android currently. You can easily edit animating videos But it is available only for Android and iOS So, if you asks me that is there any way to install Alight Motion Pro APK on PC as well then the answer is YES. You can run it on your Windows and Mac PC as Well.

Editing videos on the PC with Alight Motion is really great to edit on a big screen So, We have prepared the complete guide to install the latest version of Alight Motion Pro on PC. You just simply follow the steps given here and will also able to install Alight Motion on PC Download Now Alight Motion For Pc Link Here : https://alightmotionpc.com/

Profile icon
robertwadraa

Movie Hd Apk – As an open-source Android application, movie HD lets you play high-definition movies on your device. Movie HD supports a variety of formats and codecs, including MP4 (x264), AVI (XviD), MKV (x264), and WMV (VC-1). Movie HD also allows you to download movies from torrent sites. The program has been widely embraced by Android users due to its easy-to-use interface and features.

Note that in order to use movie HD effectively, you’ll need to root your device first. Also keep in mind that if you want to use any of these formats or codecs with Movie HD, then you’ll have to install additional software on your computer beforehand. However, we expect most people looking for Movie HD will be satisfied with how it works out of the box. https://moviehd.onl/

Profile icon
robertwadraa

BeeTV lets you watch the latest movies and TV shows on any device you want. Let us see how to download and install the BeeTV for PC.

The name may sound quirky and strange but the service that it offers is nothing but unique. Yes, we are referring to the newest entrant in the field of entertainment. It is BeeTV. It is in fact one of the best apps when it comes to streaming movies and shows. https://beetvapp.me/

Profile icon
RuthThornton

That is an extremely good article, and https://yotonos.com is proud to be the store that provides the best ringtones for mobile phones!

Profile icon
mrvinnu

great time to read this blog post and waiting for more updates. Yacine TV & Airy TV

Profile icon
JonesSkylar

it's a very good article, besides https://apktodo.com/vi/minecraft is proud to be the provider of the best minecraft game for mobile devices!

Profile icon
HortonMA

Allows users to search for life, on GB WhatsApp APK, and much more apps here with best user experience:https://www.new-gbmods.com/gbwhatsapp/