Develop bot integrations with the Hangouts Chat platform and API
Mike Sorvillo
Product Manager, Hangouts Chat
Wesley Chun
Developer Advocate
Try Google Workspace at No Cost
Get a business email, all the storage you need, video conferencing, and more.
SIGN UPYou might have seen that we announced new features in G Suite to help teams transform how they work, including Hangouts Chat, a new messaging platform for enterprise collaboration on web and mobile. Perhaps more interesting is that starting today you’ll be able to craft your own bot integrations using the Hangouts Chat developer platform and API.
Now, you can create bots to streamline work—automate manual tasks or give your users new ways to connect with your application, all with commands issued from chat rooms or direct messages (DMs). Here are some ideas you might consider:
- Create a bot that can complete simple tasks or query for information
- Create a bot that can post asynchronous notifications in any room or DM
- Use interactive UI cards to bring your message responses to life
- Use Google Apps Script to create custom bots for your colleagues or organization
When messages are sent to an Apps Script bot, the onMessage()
function is called and passed an event object. The code below extracts the bot name as well as the location requested by the user. The location is then passed to Google Maps to create the static map as well as an openLink
URL that takes the user directly to Google Maps if either the map or "Open in Google Maps" link is clicked.
Finally, this function returns everything Hangouts Chat needs to render a UI card assuming the appropriate links, data and Google Maps API key were added to the response JSON payload. It may be surprising, but this is the entire bot and follows this common formula: get the user request, collate the results and respond back to the user.
When results are returned immediately like this, it's known as a synchronous bot. Using the API isn't necessary because you're just responding to the HTTP request. If your bot requires additional processing time or must execute a workflow out-of-band, return immediately then post an asynchronous response when the background jobs have completed with data to return. Learn more about bot implementation, its workflow, as well as synchronous vs. asynchronous responses.
Developers are not constrained to using Apps Script, although it is perhaps one of the easiest ways to create and deploy bots. Overall, you can write and host bots on a variety of platforms:
- Google Apps Script (JavaScript)
- Google Cloud Functions (JavaScript)
- Google App Engine (Python, Java, PHP, Go, and more)
- Google Compute Engine (your language, your stack, your instance)
- Other public or private cloud