Skip to content

An example of a WhatsApp bot that can respond to location messages and can send images, vcards and location messages

License

Notifications You must be signed in to change notification settings

philnash/whatsapp-bot-capabilities

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Building with the Twilio API for WhatsApp

This example code is from the how to build a location-aware WhatsApp application Twilio webinar and the Building with the Twilio API for WhatsApp. It demonstrates how to build a WhatsApp bot that reacts to different inputs, including location. It can send messages that include text, images, files and locations.

This bot responds to a number of commands:

  • contact: sends a VCard with Phil's contact details
  • picture: sends a picture of Alex, the Twilio developer evangelism team mascot
  • If you send your location, it looks up restaurants from the Foursquare API and sends you an image, description and location of a nearby restaurant
  • If you send anything else it will respond with a default message

Running this bot yourself

To run this bot yourself you will need:

Then, clone the repository:

git clone https://github.com/philnash/whatsapp-bot-capabilities.git
cd whatsapp-bot-capabilities

Install the dependencies:

npm install

Copy the .env.example file to .env:

cp .env.example .env

Get your Twilio Account Sid and Auth Token from your Twilio console and enter them in .env.

Create a Foursquare application and get your Foursquare API client ID and secret from the Foursquare developers portal and enter them in .env.

Setup the Twilio Sandbox for WhatsApp

Go to your Twilio account and follow the prompts to set up the Twilio Sandbox for WhatsApp

Running the bot locally

You can run the bot locally, which will use ngrok to tunnel through to your account. Start the application with:

npm start -- --ngrok

Then take the URL for the /whatsapp function (which should look like https://RANDOM_SUBDOMAIN.ngrok.io/whatsapp) and paste it into the Twilio WhatsApp Sandbox configuration.

Then send your bot a message.

Deploying to Twilio Functions

To deploy the function, you can run:

npm run deploy

When the script is finished you will see a URL that looks like https://whatsapp-bot-webinar-XXXX-dev.twil.io/whatsapp. Take that URL and paste it into the Twilio WhatsApp Sandbox configuration.

Then send your bot a message.

Further resources

About

An example of a WhatsApp bot that can respond to location messages and can send images, vcards and location messages

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published