Complete the steps described in the rest of this page, and in about fifteen minutes you'll have created a Google Chat bot that sends messages to a Google Chat room. This quickstart uses a simple Node.js script that sends HTTP requests to an incoming webhook registered to a Google Chat room.
Prerequisites
To run this quickstart, you need:
- Node.js & npm installed.
- An existing Google Chat room.
Step 1: Register the incoming webhook
- Open Google Chat in your browser.
- Go to the room to which you want to add a bot.
- From the menu at the top of the page, select Configure webhooks.
- Under Incoming Webhooks, click ADD WEBHOOK.
- Name the new webhook 'Quickstart Webhook' and click SAVE.
- Copy the URL listed next to your new webhook in the Webhook Url column.
- Click outside the dialog box to close.
Step 2: Create the Node.js script
Create a file named index.js
in your working directory and copy the
following code:
Node.js
Be sure to replace the value for the webhookURL
variable in the code snippet
with the URL provided to you by Google Chat when you registered the incoming
webhook. (If you need to find the URL again, go to the Google Chat room,
select Configure webhooks, and then copy the URL associated with your new
incoming webhook in the Webhook Url column.)
Step 3: Run the sample
Run the sample by running the following command from your working directory:
$ node .
Further reading
Troubleshooting
403: The caller does not have permission
Incoming webhooks for rooms will fail with this error if not all users in your domain have bots enabled. See the webhooks documentation for more information.