TWILIO CHATBOT SOFTWARE
Mia Adjei is a Software Engineer for Technical Content at Twilio. Additionally, if you are interested in upgrading your Weatherstack API access, you can even get historical and forecast data that may be interesting to include in your weather bot application. Now that you have built this SMS weather bot, you can customize or expand on it with other data or add even more weather-related advice to share with the user. You can even try it out with other cities around the world. Try it out! Text your city name, zip code, or coordinates to your Twilio phone number, and see what the weather is around you. Now, every time someone sends a text message to your Twilio number, your weather bot will receive the request at the /weather endpoint and be able to use the location information in the incoming message to fetch weather data and return information and advice to the user. Make sure the request method is set to HTTP POST.Ĭlick the Save button to save your changes. Then, add /weather to the end of this URL, since /weather is the endpoint for our chatbot. Copy the forwarding URL from ngrok, and paste it into the Webhook field under A MESSAGE COMES IN. Return to the Phone Numbers section of the Twilio Console and scroll down to the Messaging section. Take note of the URL next to Forwarding - you will need it in order to configure a webhook that will let your bot respond to SMS messages. The output from ngrok will be similar to the following: 'įormatted_response += 'Bring an umbrella! ☂️ 'įormatted_response += 'Wear some sunscreen! ☀️ ' Precipitation = dataįormatted_response = f'. Msg.body('Sorry, I am unable to get weather data for that location.')
# Get the user's location from the incoming message In the file, paste in the following methods=) This is where you will store the environment variables for your project. Inside your weather-bot directory, create a new file called. Once you sign up, you will see your API key on your dashboard. Navigate to their website and sign up for a free account to start using the API. Now that you have your phone number, it's time to get an API key so you can use the Weatherstack API to get information about weather around the world. Once you do this, you'll have your own Twilio phone number! Get a Weatherstack API key
Then, click the Search button, and when you see a number you like, click the Buy button to purchase it. On the Buy a Number screen, select your country and make sure SMS is selected in the capabilities field. If you do not already have a Twilio phone number that you want to use for this project, go to the Phone Numbers section in the Twilio Console and click the Buy a number button. Next, you will need to configure a Twilio phone number with SMS capabilities for your chatbot to use. Once you have done this, run the following commands to set up a new directory called weather-bot and change into the directory: To start, open a new terminal window and navigate to where you would like to set up your project.
TWILIO CHATBOT INSTALL
Set up a virtual environment and install dependencies ( Learn more about using ngrok in 2022 here.)
TWILIO CHATBOT UPGRADE
(If you register here, you'll receive $10 in Twilio credit when you upgrade to a paid account!)
TWILIO CHATBOT HOW TO
In this tutorial, you will learn how to build a little chatbot that can tell you the weather in your area or where you are planning to be, as well as remind you what you might want to bring along with you if you go outside. After all, even though you might be able to look out the window and see whether it's raining or not, you might not know what the temperature or UV index is without checking a website or app.
Weather apps are extremely helpful in a world where weather is becoming increasingly unpredictable.