![]() It's a simple bot, but provides a good basis to build more. You can get all the code for this bot on GitHub. In this post we've seen how to configure the Twilio API for WhatsApp and connect it up to a Ruby application to return pictures and facts of dogs or cats. You can now send a message to the WhatsApp sandbox number and your application will swing into action to return you pictures and facts of dogs or cats. Enter that URL in the WhatsApp sandbox admin in the input marked "When a message comes in" and save the configuration. Take that ngrok URL and add the path to the bot so it looks like this. This will give you an ngrok URL that you can now add to your WhatsApp sandbox so that incoming messages will be directed to your application. To do so, we pass a block to the post method that Sinatra defines. Twilio webhooks are POST requests by default, so we'll set up the route to handle that too. Let's remove the "Hello World!" route and add a /bot route instead. The application we have built so far could respond to a webhook at the root path, but all it does is respond with "Hello World!" so let's get to work updating that. TwiML is a set of XML elements that describe how your application communicates with Twilio. Our application will need to define a route that we can set as the webhook request URL to receive those incoming messages, parse out whether the message contains the words we are looking for, and respond with the use of TwiML. That request will include all the information about the message, including the body of the message. With the Twilio API for WhatsApp, when your number (or sandbox account) receives a message, Twilio makes a webhook request to a URL that you define. The words we're going to look for in the message are "dog" or "cat" and our bot will respond with a random picture and fact about either dogs or cats. In this post we will build a simple bot that responds to two keywords when someone sends a message to our WhatsApp number. Now that our application is all set up we can start to build our bot. Open that in your browser and you will see the text "Hello World!". The application will start on localhost:9292. Then initialise a new Gemfile in the app and create a couple of files we'll need: Start by creating a new directory to work in. Let's kick off a new Ruby application in which to build our bot. When you receive a message back, you are all set up and ready to work with the sandbox. The page also has the message you need to send, which is "join" plus two random words, like "join flagrant-pigeon".Open your WhatsApp application and start a new message to that number The page will have the WhatsApp sandbox number on it.Head to the WhatsApp sandbox area of the Twilio console, or navigate from the console to Programmable SMS and then WhatsApp.The Twilio console walks you through the process, but here's what you need to do: Let's start by configuring the sandbox to use with your WhatsApp account. To launch a bot on WhatsApp you must go through an approval process with WhatsApp, but Twilio allows you to build and test your WhatsApp apps using our sandbox. A Twilio account (if you don't have one, sign up for a new Twilio account here and receive $10 credit when you upgrade).ngrok so we can expose our local webhook endpoints to the world in style.To build your own WhatsApp bot along with this tutorial, you will need the following: Here's an example of the conversation we're going to build: In this tutorial we are going to see how easy it is to get started building chatbots for WhatsApp using the Twilio API for WhatsApp and the Ruby web framework Sinatra. They can be very basic, responding to keywords or phrases, or use something like Twilio Autopilot to take advantage of natural language understanding (NLU) to provide a richer experience and build out more complicated conversations. Chatbots are programs that communicate some way with humans.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |