In this tutorial, we are going to create a bot that allows users to find out the weather forecast for a specific town, city or location.

I magine this – you’re late for work, trying to get your bag packed, and looking for everything you might need in a day. The weather looks nice and sunny out the window so, as you’re updating your colleagues on your arrival time on Workplace Chat, you leave your umbrella behind and rush out the door.

You start speed-walking to your office, going over in your mind the notes for your next big meeting – when boom – thunder and raindrops appear overhead.

Now imagine as you had Workplace open in the palm of your hand you were able to quickly ask your office weather bot what the forecast was going to be.

Adding tools like weather forecasts to Workplace not only keeps more utilities on the platform and avoids people having to have multiple other applications on their phone, but it also ensures they’re looking fly and staying dry when they are on their way to a big pitch or meeting.

Follow the steps below to learn how you can use The Bot Platform to make your own weather bot on Workplace, keeping your staff informed and always prepared.

Knowledge Required: Intermediate

You need a basic knowledge of The Bot Platform, Zapier and Google Maps.

You will need:

Step 1: Create your account and bot

Before you do anything, you need an account with The Bot Platform.

Then you’ll need to create a bot by following the instructions on our blog on how to set up your bot on Workplace. For this tutorial, you should start with a blank template and create a new integration on your Workplace account.

Step 2: Set up your bot

Now we have our blank bot set up and integrated with our Workplace instance, we can start by creating the integrations we need.

Create the initial Welcome Message for your bot. In our example, we have included an image and a text option with two buttons for yes and no. You need to set the button to send the user a message and set the reply message as ‘Location.’

Step 3: Start building your messages

Now we need to set up the message that collects the address. Create a Q&A message that asks for the weather. Click on the settings option and select save user attribute and send a message.

Save the information with a new user attribute called ‘Location.’

Set the response message to be ‘Weather Details’ and click save.

Step 4: Add a "Weather lookup" message and connect to Zapier

Let’s now edit the new Weather Details message. In our message, add a text introduction that says ‘Great, let’s look up the weather.’ This lets the user know that the bot is doing something while the next stage of the lookup happens.

We now need to add a webhook. Add a webhook from The Bot Platform options on the right.

Now we need to go to Zapier.

Step 5: Edit your Zap to collect data

We need to create a new Zap that collects the data from our bot and produces a suitable weather report.

Search for a webhook trigger on Zapier. Click on the webhook icon and select Catch Hook as your option. You will then be given a webhook URL. Copy this URL to your clipboard and go back to The Bot Platform. Click on the settings icon next to your webhook and paste in the URL you just copied from Zapier.

You now have your webhook set up!

Step 6: Test your webhook

Now we need to test our webhook so we can set up the rest of the Zap.

Go back to the dashboard for your bot and click ‘Test’ next to your Welcome Message. Test your bot and make sure the message flow is as expected. Once you reach the final message ‘Great, let’s look up the weather’, head back over to Zapier. Click on ‘Test this step’ and you should be able to see the hook data you have just submitted through your bot.

Select your most recent hook and select continue.

Step 7: Connect to Google Maps API

We now need to turn the text-based location your user inputs into longitude and latitude coordinates that we can then use with the Zapier weather look up.

To do this we need another Webhook. Set your Zapier action app as a webhook. This time, we need to use a custom request, instead of catch.

In the next screen, we need to set the method as a POST method.

We now need to post our user entered location to Google Maps in order to pull back the longitude and latitude. Google maps have a really well-documented API. This means we are able to get location data in many different formats.

To get a Google Maps API key, you need to go here and follow the instructions.

An API key is free to obtain and allows you thousands of free calls before you need to pay.

Step 8: Get the geocode for your location

We now need to use the API key we have just obtained in our Zap. Paste the below in the URL box on Zapier. We need to get the geocode for our location so we should use the URL in the format:

https://maps.googleapis.com/maps/api/geocode/json?address=ADDRESS&key=YOURGOOGLEAPIKEY

Replace the YOUR GOOGLE API key text in the above URL with your Google API key.

Instead of the text ADDRESS, click the + icon on the right and select the user attribute ‘Location’ pulled through from your bot.

By the end, your URL should look like the below:

Click continue at the bottom and test this step. You should see that you get a long list of data returned, which includes several mentions of longitude and latitude.

Step 9: Push changes live

Now we want to set up our weather look up.

For this, we need to choose Weather by Zapier as our next connection.

Select the get current weather option and click continue.

On the next screen, we can select the longitude and latitude readings we have just pulled from Google maps. Click the + option on the right of the bot. Select your custom request and from the full data, choose the Results Geometry Location Lat and Long to match your latitude and longitude fields.

Click continue, test your step and then continue again.

Step 10: Add an action step

Now we need to pass all of the data back to our bot.

Again, we will use a webhook to do this. Add another action step and choose webhook from the options. We need to use another custom request.

We will use Facebook’s own messenger API for this part. We need to set up a POST method. Our URL this time will make use of graph.facebook.com.

The URL will take the following format:
https://graph.facebook.com/v2.6/me/messages?access_token=INTEGRATIONACCESSTOKEN

Your integration access token is the same one you used when setting up your bot to integrate with Workplace.

To find it, you can go to integrations on Workplace and click the Access Token button. Please note, that if you click the reset access token to get one, you will need to update the access token for this bot on The Bot Platform too or else your bot won’t be able to access your workplace account.

Paste this link into the URL box.

This time, we need to add how we want our data to be formatted by adding content in the data box. You can use as much or as little data from the weather forecast as you like. Here is how we have chosen to format our data:

Now click on continue and test this step and it should push a message back to you on workplace chat. Click finish and your bot is now set up and good to go.

You just made a weather forecasting bot!

Never be caught without an umbrella again thanks to this Workplace weather forecaster bot.

To learn more about custom integrations and more bot “how to’s,” head over to our help center for more information or drop us an email below.

Want To Learn More?

Let’s talk about how your business or organization can benefit from bots on Workplace by Facebook and Messenger.

Get in touch with our team