Weather Bot: Implementing a Bot in facebook Workplace with Zapier
Weather Bot: Implementing a Bot in facebook Workplace with Zapier

Weather Bot: Implementing a Bot in facebook Workplace with Zapier

by Sergio López

This post would be part of my blog, and the ultimate purpose is to show the people an overview of implementing a bot on WorkPlace using Zapier, and how it compares with Slack integrations.

The Bot in Zapier

Zapier is the glue of the internet and is used by many people to integrate their existing software stack between each other.

🤖

This bot would check every day at 9 am the OpenWeatherAPI Forecast and will get the actual weather, the weather in 3 and 6 hours, and will post in a Group in WorkPlace this information with the link to OpenWeather.

Additionally, this can be configured in any group (by group id) and the temperatures can be shown in Celsius or Fahrenheit.

Zapier Integration

As the date of this post, there is no zapier integration for Workplace, so I had to use a JavaScript code (Typescript).

I think this is a significant missing feature for "Workplace", having a zapier integration would be a great place to attract new customers, and it would be easier for companies to create integrations with their actual SaaS that are in Zapier.

Subscription Requirements

For this bot, you will need the Workplace premium plan that costs $3 a month, compared with Slack, this is half the price, and facebook has a lot of other features, so I think that's a fair price.

The only thing missing is that Slack has in the free plan included integrations (limited to 10).

Third-Party Integrations/Custom Integrations

Another thing is that third-party integrations in Slack are open to any developer, actually, there have been some companies that were born with Slack (https://standuply.com/blog/slack-bot-business-tutorial/) and that helped to build an outstanding bot ecosystem.

In Workplace, you have to register a Third-Party application, but one of the limitations is "Your company's track record for delivering valuable enterprise collaboration apps" among other restrictions (https://developers.facebook.com/docs/workplace/third-party-apps/request).

Workplace Weather Bot Setup

Workplace Custom Integration Setup

The first step is to create a custom integration (https://developers.facebook.com/docs/workplace/custom-integrations-new)

image

You can customize the logo, and you will get from there the App Id and App Secret tokens, we will use it later in Zapier.

The permissions needed for this integration are shown in the image above "Manage group content".

Zapier Setup

As this would need to be executed the first thing in the morning, we would use a Zapier Schedule Step that runs every day at 9 am.

image

With the instructions on the Github repository clone the project and change the next variables on the index.ts file with the ones of your workplace and openweather api.

  • openWeatherApiKey
  • city
  • workplaceAccessToken
  • workplaceAppSecret
  • workplaceGroupId

You can register to obtain a free API key for OpenWeather in the next link https://openweathermap.org/api

Then we have to create a Zapier Code Step and paste the code that was generated by the Typescript gulp compilation (instructions on github repository).

image

So that's all, you can see the result posted in the group that you configured.

image

Technical Implementation

A technical peculiarity for this project is that I used Typescript, compiling with gulp and browserify to zapier code. I loved the typed languages, and I prefer using async/await over Promises

I didn't find someone on the internet that has done the same thing with Typescript in Zapier, and this is the first time I do it in Typescript, regularly I use pure javascript.

I think the reason is by the limitations of Zapier itself (but that would be content for another blog post).

You can find the code for this project on Github in the next link: