We've seen how to write a text chatbot using the Twilio API for WhatsApp using Ruby, but WhatsApp also supports sending and receiving location data via their API. In this post we are going to see how to build a WhatsApp bot that can receive and respond to location messages.

We'll build a weather bot so that you can send your location to the bot to get your local weather forecast.

What you'll need

To code along with this post and build your own location-aware WhatsApp bot you will need:

Configure your WhatsApp sandbox

If you want to launch a bot on WhatsApp you need to get approval from WhatsApp, but Twilio allows you to build and test your WhatsApp bots using our sandbox. Let's start by configuring the sandbox to use with your WhatsApp account.

If you haven't set up your WhatsApp sandbox, head to the Twilio console WhatsApp Sandbox and follow the instructions in my previous post. When you've received a message back over WhatsApp you're ready to continue.

Setting up the Ruby application

At the end of the last post, we had a good base application which we can start with this time. Get this setup by cloning it from GitHub and changing into the directory: