Integrating Hubot with Google Chat

Stay organized with collections Save and categorize content based on your preferences.

Hubot is a great way to build an app that works on multiple platforms. With the Google Chat Hubot Adapter, you can easily utilize your Hubot apps in Google Chat. The adapter feeds messages into Hubot and serves the replies.

The Google Chat Hubot adapter supports two types of endpoints:

  • HTTP
  • Cloud Pub/Sub

This guide explains how to launch a Hubot app in Google Chat, using either type of endpoint.


Follow the instructions in Getting Started with Hubot to download and install the necessary tools: Node.js, npm and the Hubot generator for Yeoman.

You can try creating a new instance of Hubot that uses the built-in shell adapter, install Hubot scripts, play with it, and get a feel of the Hubot ecosystem and developing a Hubot app.

Using the Hubot Google Chat adapter

This section guides you through creating a Hubot app that uses the Google Chat adapter, deploying it in AppEngine, and publishing the app in Google Chat. You can also choose to deploy the app in any system of your choice other than AppEngine.

The Google Chat Hubot adapter supports two modes: HTTP and Cloud Pub/Sub. The HTTP mode spins up an Express web server and listens for events in a user specified port. The Cloud Pub/Sub mode creates a Pub/Sub subscriber and pulls events from a user specified subscription. On receiving events from Google Chat, both modes create a HangoutsChatMessage object (which extends one of Hubot's Message objects) and pass it on to your Hubot script. The response from your Hubot script is posted to the chat space or DM in Google Chat from which the original message event was published to the app.

Create a Hubot instance

Make sure to set up Node.js, the npm package manager, and the Yeoman generator for Hubot before proceeding.

Suppose you want to create an app called "myhubot". Start by creating a new directory and then create your Hubot instance it in.

$> mkdir myhubot
$> cd myhubot
$> yo hubot

At this point, Yeoman asks a few questions about who is creating the app and which adapter to use. Specify google-hangouts-chat for the adapter.

Alternatively, you can install the adapter separately using the following command:

$> npm install --save hubot-google-hangouts-chat

In Hubot the actual app behaviour is implemented using scripts. Hubot comes with a sample script that you can use for testing. Once you have everything setup, you can customize and add your own scripts to implement the desired app behaviour.

Configure options for the Google Chat adapter

Options are passed to the Google Chat adapter using environment variables.

Service Account

To use the adapter, you need to setup a service account for your app. Follow the Using service accounts guide to create a service account and download the JSON file containing your key. Then, set the path to your key in an environment variable:

# Point to the private key json file of the service account you created.
$> export GOOGLE_APPLICATION_CREDENTIALS='Path to the service account key json file'

HTTP Options

No additional configuration is necessary to run the adapter in HTTP mode. The adapter uses Hubot's express server, which runs on port 8080 by default. To change the port, you need to set the PORT environment variable:

# Port number, 8080 by default.
$> export PORT=8080

Cloud Pub/Sub Options

See Set up a Pub/Sub endpoint to setup a GCP project, Cloud Pub/Sub topic, subscription, and service account to be used by your app. Ignore the sample code in the link; in the paragraphs below, you'll create a Hubot app with the Google Chat adapter.

To use the Google Chat adapter in Pub/Sub mode, you need to set the following options:

# To toggle the adapter to Pub/Sub mode.
$> export IS_PUBSUB=true

# Set the IDs of the project and subscription you created.
$> export PUBSUB_PROJECT_ID='GCP Project ID'
$> export PUBSUB_SUBSCRIPTION_ID='GCP Cloud Pub/Sub Subscription ID'

Run locally

To run the Hubot instance locally, run the corresponding command from the myhubot directory:

# For HTTP mode
$> bin/hubot -a google-hangouts-chat

# For Cloud Pub/Sub mode
$> bin/hubot -d -a google-hangouts-chat

The following message appears in the console if the Google Chat Hubot Adapter was initialized successfully:

Hangouts Chat adapter initialized successfully

Depending on whether you configured a HTTP adapter or a Cloud Pub/Sub adapter, other relevant information can also appear on the screen.

Deploy in AppEngine

Follow the instructions in the AppEngine Quickstart to set up the GCP project and development environment.

Once this is set up, follow the steps below for configuring and deploying your Hubot instance in AppEngine.

Create app.yaml

First, create an app.yaml file in your Hubot directory. The contents will resemble the following example:

runtime: nodejs8
  PORT: 8080

Configure environment

Next, check the instructions on this page to configure environment variables.

Create package.json

Finally, create a package.json file that specifies the node.js version and the scripts property used to launch the app.

  • Specify the Node.js version you would like to use with the engines property in your package.json file.
  • AppEngine uses npm start to start your application. Setup the scripts property in your package.json to configure npm start to invoke Hubot.
# Sample snippet of package.json file

"dependencies" : {
  "hubot": "^3.1.1",
  "hubot-google-hangouts-chat": "^3",
  # more deps...

"scripts": {
  "start": "bin/hubot -a google-hangouts-chat"
"engines": {
  "node": ">=8"

# Once you've set up everything, deploy the app in AppEngine
$> gcloud app deploy

Publish in Google Chat

Follow the instructions in Publish apps page to publish an app in Google Chat via the Google Cloud Console. Configure the appropriate endpoint (HTTP or Cloud Pub/Sub) in the app configuration page. If you created a GCP project in the previous step to deploy your Hubot instance in AppEngine, you can use the same GCP project to publish your app.

Test the app

Once you publish your app, you can add it to a space or start a direct message with it in Google Chat. Your app should respond to messages sent to it. Hubot comes with a sample script in its scripts folder. Uncomment the code in the sample script that responds to messages containing the word "badger" and restart the app.

If you named your app "myhubot" and added it to a space, you can message it as shown below:

@myhubot badger

You should see the following response from your app:


You can now customize or add Hubot scripts to your Hubot instance to implement the desired functionality for your app. To see example scripts specific to Google Chat, look at the Google Chat Adapter GitHub Repository.