Google Apps Script bot

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:

Step 1: Create the script

New editor

  1. Go to the Apps Script Getting Started page.
  2. Click the Chat Bot template. You might have to scroll down to see this template.
  3. Click Untitled project at the top left, type Quickstart bot, and click Rename.

Legacy editor

  1. Open the Google Apps Script Editor using the Chat Bot template.
  2. 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:

New editor

  1. Click Deploy > New deployment.
  2. Under Select type, click Add-on.
  3. Fill out the options and click Deploy.
  4. Under "Deployment ID," click Copy.

Legacy editor

  1. Click Publish > Deploy from manifest.
  2. In the Deployments dialog box next to Latest Version (HEAD), click Get ID.
  3. In the Deployment ID dialog box, copy the value listed for the Deployment ID.
  4. Click Close and Close to dismiss the dialog boxes.

Step 2: Publish the bot

Publish the Chat bot from Google Cloud Console.

  1. Open the Google Cloud Console.
  2. Search for "Google Chat API" and click Google Chat API.

    1. Click Manage.
    2. Click Configuration and set up the Google Chat bot:

    3. In the Bot name field, enter 'Quickstart bot'.

    4. In the Avatar URL field, enter ''.

    5. In the Description field, enter 'Quickstart bot'.

    6. Under Functionality, select Bot works in direct messages.

    7. Under Connection settings, select Apps Script project and paste the Deployment ID into the field.

    8. Under Permissions, select Specific people and groups in your domain, and enter your own email.

  3. Click Save.

The Chat bot is ready to respond to messages.

Step 3: Run the sample

To run the sample, do the following:

  1. Create a new direct message with the bot by clicking Find people, rooms, bots > Message a Bot.
  2. On the Add bot page, under Find a bot, type 'Quickstart Bot'.
  3. Select the Quickstart Bot.
  4. In the new direct message with the bot, type 'hello'.

The bot thanks you for adding it and echoes your message.

Further reading