Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

google/hangouts-chat-bot-cloud-function-nodejs-example

Hangouts Chat Bot on Google Cloud Functions

This is not an officially supported Google product

This repo contains a full example of a Google Cloud Function which can server as a bot for Google Hangouts Chat written in NodeJS. The bot is able to authenticate users with their Google account by means of a OAuth 2.0 web flow and acquire permissions for scopes from the Google Cloud Platform (GCP). In this particular example, the bot asks to access Google BigQuery on behalf of the user.

The following sections describe how to deploy the bot on Google Cloud Functions and which prior steps are necessary to prepare your GCP project.

Prerequisites

Following a list of steps which prepare your GCP project and configure the code example:

First, you need to enable the following APIs in your GCP project:

Then, following steps are required:

To enable Google Cloud Build to deploy to Cloud Functions, you need to grant developer permissions and enable the use of service accounts. Add the permissions Service Account > Use Service Account and Cloud Functions > Developer to the Cloud Build service account.

Finally, copy src/param.js.template to src/params.js. In the new file, copy your OAuth client credentials and add scopes (optional).

Deployment

The deployment of the code is a one line execution using the Google Cloud SDK. From the root folder, simply run the following:

gcloud builds submit --substitutions=_BUCKET=[code-bucket]

Test & Experimentation

You can use the following command to trigger the authentication flow from the shell:

curl -vvv -X POST -H "Content-Type: application/json" -d '{"configCompleteRedirectUrl": "https://google.com"}' https://[region]-[gcp-project-id].cloudfunctions.net/[function-name]/bot

To follow the OAuth flow, pick the URL included in the response and open it in a browser (e.g. Chrome).

Read more about concepts of a Hangouts Chat bot.

Publish your Hangouts Chat Bot

The procedure to publish the chat bot is as described in the documentation. When entering the URL of your bot, use the following pattern to construct your bot URL:

https://[region]-[gcp-prject-id].cloudfunctions.net/[function-name]/bot

Contributers

Releases

No releases published

Packages

No packages published