Complete the following steps to create a simple Google Chat bot. The bot can be directly messaged, and responds by echoing your messages.
To run this quickstart, you need:
- A Google account.
Step 1: Create the script
- Go to the Apps Script Getting Started page.
- Click the Hangouts Chat Bot template. You might have to scroll down to see this template.
- Click Untitled project at the top left, type Quickstart bot, and click Rename.
- Open the Google Apps Script Editor using the Hangouts Chat Bot template.
- Click File > Save, name the project "Quickstart bot", and click OK.
You now have working bot code that you can try out (as described in the steps below) and then customize to meet your requirements.
Be sure you're signed in to the correct Google account when you open the Apps Script template. The current account can sometimes be switched to your default account without your noticing.
You need the Deployment ID for this Apps Script project, so that you can use it in the next step. To get the Deployment ID, do the following:
- Click Deploy > New deployment.
- Under Select type, click Add-on.
- Fill out the options and click Deploy.
- Under "Deployment ID," click Copy.
- Click Publish > Deploy from manifest.
- In the Deployments dialog box next to Latest Version (HEAD), click Get ID.
- In the Deployment ID dialog box, copy the value listed for the Deployment ID.
- Click Close and Close to dismiss the dialog boxes.
Step 2: Publish the bot
For information about how to set up a bot, see Publishing bots. Once the API is enabled:
- In the Bot name field, enter 'Quickstart bot'.
- In the Avatar URL field, enter 'https://goo.gl/yKKjbw'.
- In the Description field, enter 'Quickstart bot'.
- Under Functionality, select Bot works in direct messages.
- Under Connection settings, select Apps Script project and paste the Deployment ID into the field.
- Under Permissions, select Specific people and groups in your domain, and enter your own email.
When you've finished configuring your bot, click Save Changes.
Step 3: Run the sample
To run the sample, do the following:
- Create a new direct message with the bot by clicking Find people, rooms, bots > Message a Bot.
- On the Add bot page, under Find a bot, type 'Quickstart Bot'.
- Select the Quickstart Bot.
- In the new direct message with the bot, type 'hello'.
The bot thanks you for adding it and echoes your message.