Deliver asynchronous notifications in Google Chat using webhooks

August 09, 2021


Link copied to clipboard

Posted by Charles Maxson, Developer Advocate & Justin Wexler, Strategic Cloud Engineer

As Google Workspace is redefining the future of team collaboration and Google Chat Rooms evolve into Spaces, webhooks are a useful feature that already exists in the current Chat rooms of today that allow you to deliver asynchronous messages directly into Chat rooms where users work. Webhooks in Chat are powerful and simple to use. Unlike the more well known Chatbots, which are applications built specifically for interacting synchronously with users using the Google Chat API, webhooks enable asynchronous messaging into Google Chat from applications that aren't bots themselves. In this post, we’ll explore using webhooks in Chat and demonstrate a real world use case from our work internally at Google.

The Case for Webhooks in Google Chat

Teams create and use Rooms (now Spaces) in Google Chat for many purposes. Some rooms may work along themes, such as Sales Support or Customer Service topics, while others may be more generic for specific departments or company-wide conversations. But all these use cases are centered on human activity, and as we rely on them more and more, they have become a critical way we communicate with each other.

Webhooks allow you to add another dimension to rooms by introducing information and updates from other systems and applications that fit in with the theme of these rooms and conversations. For example, in a Sales Support room, a webhook could provide alerts from a CRM system notifying users when a deal closes or when a RFP deadline is approaching. In a Customer Service room, a webhook can post urgent alerts for requests to immediately get the attention of the whole team. For more generic scenarios, webhooks can be used to remind folks in a department about upcoming deadlines or broadly share a company’s stock price with all employees at the close of the market. Whatever the situation, webhooks can help efficiently deliver data and information in real time.

A Google Real World Use Case

We have a Chat room at Google named G Workspace Community that is used to connect Googlers who want to ask questions and stay up to date with news across our product and customer teams focused on Google Workspace. As you can imagine, this room is widely used, resulting in a constant flow of posts and responses every day. One of the most commonly discussed topics is around new features, which includes keeping track of their launch timing and status on our roadmap.

At Google, we also produce the Google Workspace Updates blog, a public feed that lets everyone know when new Workspace features ship. It would be logical to assume every member of the G Workspace Community also subscribes to the Updates blog and is up to date on every feature release. But the truth is the G Workspace Community Chat room has become the main resource where Googlers get the latest information about Google Workspace. Instead of referring room members to check the blog first before posting in the Chat room asking about releases, we decided to bring the Google Workspace Updates feed into the Google Workspace Community room. Webhooks in Google Chat made it easy, and now everybody can easily stay up to date on all the updates from Google Workspace.

Meet the Google Workspace Updates “bot”

As posts about new Workspace features are released on the Updates blog, the Google Workspace Updates “bot” (aka the Google Wexbot as its known internally after its creator, Justin Wexler) adds a new thread to the Chat room that calls out the post’s title and the first 250 characters of it’s main content. This offers room members a quick glimpse of what just launched, as well as a place to quickly have a discussion around the blog content. Users can ask questions or add comments about the feature release, making it a much more enhanced and collaborative experience, and they can get the full story on the Updates blog by simply clicking READ MORE.

Image of Google Workspace Updates bot

Webhooks + Apps Script = Magic

For community members receiving these timely updates, this “bot” may seem magical. In reality, it’s neither magic nor a traditional Chat bot, so the reference in the Chat UI calling it a “bot” is a bit of a misnomer. The Google Updates “bot” is in fact a simple Google Apps Script application that parses the RSS feed about new posts, and sends them asynchronously to the room via webhooks.

Apps Script is well suited to help deliver on this use case, as it offers triggers (ie. cron jobs) that can run on time-based intervals to check the Updates blog for new posts, parse the feed XML from those posts, and return those results using the Chat Card format to the waiting webhook via a UrlFetchApp call.

In our internal implementation of the Google Workspace Updates “bot”, an Apps Script trigger runs hourly to check for new posts to the Update blog. Beyond that, the project itself is a single Apps Script project file that doesn't require a significant amount of coding, is super easy to configure with Chat rooms, and has been essentially maintenance free. Justin’s effort to create the original version only took a couple of days -- and the value for the users is clearly worth it -- hence why they insisted on naming it after him ;)

Add Google Workspace Updates “bot” (aka Wexbot) to your own Chat rooms

If you are interested in adding your own Google Workspace Updates “bot”, or you’d like to see how you can leverage Apps Script to fulfill other use cases for sending asynchronous messages to Google Chat via webhooks, the project is available up on GitHub for you to explore and implement:

Google Chat Updates Bot Project - GitHub

README | Apps Script Code.js

More Resources

To start learn more about working with Google Workspace Chatbots and using webhooks, please explore the following resources:

And remember to sign up for the Google Workspace Developer Newsletter!