![]() ![]() Mwangi Kabiru is a Data Engineer at Wellio and a Software Engineer at Andela. If you decide to research this option, here is a tutorial on how you can build a WhatsApp chatbot using Python, Flask, and Twilio. Besides GCP cloud functions, AWS offers a similar product called AWS Lambda and Microsoft has Azure Functions.įor various reasons such as hosting costs, you may also consider a traditional endpoint built using a Python web framework for your webhook. From our example above, we had an endpoint in less than 30 lines of code and we did not require a web framework to run it. Serverless architectures offer you an opportunity to spin up a webhook without worrying about infrastructure and deployment. You can ensure that the bot handles errors well by sending a word that is not a country: Send the name of a country to it to get a response from the Python webhook running on GCP. Using the WhatsApp number you connected to the Sandbox, you can now chat with the bot. Make sure the request method is set to “HTTP POST” and then click on “Save”. Copy the “Trigger URL” from the cloud function and paste it in the “WhatsApp Sandbox Settings” in the “When a message comes in” field. Go back to the Twilio Console, click on Programmable Messaging, then on Settings, and finally on WhatsApp Sandbox Settings. When successfully deployed, you will see a green tick next to your function name as shown below.Ĭlick on the cloud function in the dashboard above and then click on the “TRIGGER” tab to display the Trigger URL. Do the same for the requirements.txt file. Replace contents of the *main.py* file on the left with those from the main.py we created in the previous section. Set the “Runtime” to ‘Python 3.7’ and the “Entry point” to ‘whatsapp_webhook’. Click on “Save” and you should see the following:Ĭlick on “NEXT”, which should send you to the page where we input the cloud function code. Also check “Allow unauthenticated invocations” to make the webhook publicly available. Log in to your GCP account and navigate to your dashboard and on your sidebar menu click on “Cloud Functions”.Ĭlick on “Create Function” and set your function name to twilio-webhook. There are four common ways to deploy the cloud function we just built to the Google Cloud Platform: The response text, or any set of values that can be turned into aĬountry = ('Body', "").lower() Request (flask.Request) : The request object. Open a terminal and type:įrom _response import MessagingResponse The following commands will work for Unix and Mac OS platforms. In your local machine, create a folder where code for our chatbot will live and then set up a virtualenv inside this folder. Create a Python virtualenv and install the requirements You will receive a confirmation response from the sandbox once the code is accepted. To join the sandbox, send a WhatsApp message to the sandbox number with the text “join ”. On the WhatsApp Sandbox page you will see the sandbox number and a code for joining. Click on “Try it Out” and then “ Try WhatsApp”. On your Twilio console, select Programmable Messaging from the menu on the left sidebar. Let’s start by testing out our WhatsApp sandbox. Once your application is complete you can request production access for your Twilio phone number, which requires approval by WhatsApp. Twilio provides a WhatsApp sandbox, where you can easily develop and test your application. You can review the features and limitations of a free Twilio account. If you are new to Twilio create a free account now. If your operating system does not have a pre-installed Python interpreter, you can download an installation file from. To follow this tutorial you need to have: ![]() The country data will be retrieved from the REST Countries public API. The chatbot will accept a country name and return information about it. In this tutorial, I am going to show how you can build a serverless WhatsApp chatbot using Twilio’s WhatsApp API and Python functions in Google Cloud. The goal is to abstract the process of building and running applications from the complexities of developing and deploying infrastructure required to run them. Serverless architecture is a design pattern where applications are broken up into individual functions that can be invoked and scaled separately. Common uses of chatbots include request routing, customer service, and information gathering. A chatbot is a software application used to automate interactions and conversations with people via messaging platforms.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |