For famous quotes, I’ve chosen the Quotable API from Luke Peavey. To supply the chatbot with original quotes and cat pictures I’m going to use two publicly available APIs. The responded boolean is useful to track the case where the message does not include any of the keywords we are looking for, and in that case, offer a generic response. With this simple structure, we can detect references to quotes and/or cats and configure the Twilio response object accordingly. Don’t worry about copying this code, I will first show you all the different parts of the implementation and then once you understand them I’ll show you how they are all combined into the working application. Below is a skeleton application with a webhook definition. With the Flask framework, it is extremely easy to define a webhook. The chatbot application will have a new webhook that is going to replace the default one. The automated response that you received when you texted your Twilio number actually comes from a default webhook that is installed by Twilio on your number. The Twilio SMS API uses a webhook to notify an application when there is an incoming message. If both “quote” and “cat” are present in the message, then the bot will respond with a quote and a cat picture together. If instead, the message has the word “cat”, then a random cat picture will be returned. If the user writes anything that contains the word “quote”, then the chatbot will return a random famous quote. If you have followed my WhatsApp chatbot tutorial, then you can skip this section, as the chatbot service is actually the same one that I used on that tutorial.įor this tutorial, I’m going to build an extremely simple chatbot that recognizes two keywords in messages sent by the user and reacts to them. The chatbot application is going to be implemented as a Flask web service. If you are using a Unix or Mac OS system, open a terminal and enter the following commands to do the tasks described above: We then are going to install the Python packages that we need for our chatbot on it. You should receive a response instructing you to configure your number, which you will do after you have the chatbot application up and running.įollowing Python best practices, as a first step in creating the chatbot we are going to create a separate directory for the project, and inside it we are going to create a virtual environment. After you confirm your purchase, click the “Close” button.Ĭongratulations, you now have your very own programmable phone number! Grab your smartphone and send a text message to your new number to make sure that it is working. If you’d like to request a number from your region, you can enter your area code in the Number field.Ĭlick the Search button to see what numbers are available, and then click Buy for the number that you like from the results. In the Buy a Number screen you can select your country and check SMS in the capabilities field. Your first task is to configure a Twilio SMS-enabled phone number for the chatbot to use.įrom your Twilio Console, select Phone Numbers, and then click on the red plus sign to buy a Twilio number (you will not be charged for this purchase if you are using a trial account). If you don’t have ngrok it installed, you can download a copy for Windows, MacOS or Linux. This is necessary for the development version of the chatbot because your computer is likely behind a router or firewall, so it isn’t directly reachable on the Internet. We will use this handy utility to connect the Flask application running on your system to a public URL that Twilio can connect to. You can review the features and limitations of a free Twilio account. If you are new to Twilio create a free account now.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |