Google Apps Script Chat app

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

Complete the following steps to create a simple Google Chat app. The app can be directly messaged, and responds by echoing your messages.

Prerequisites

To run this quickstart, you need:

Step 1: Create the script

  1. Create the script from the Chat app template.
    1. Go to the Apps Script Getting Started page.
    2. Click the Chat App template. You might have to scroll down to see this template.
    3. Click Untitled project at the top left, type Quickstart app, and click Rename.
  2. Copy the Google Cloud project number.
    1. Open the Google Cloud Console.
    2. If necessary, open the Google Cloud project you intend to use for this quickstart:
      1. Next to "Google Cloud Platform," click the Down arrow . A dialog listing current projects appears.
      2. Select your project and click Open. The console opens your project.
    3. In the upper-right corner, click Settings and Utilities > Project settings.
    4. Copy the Project number.
  3. Set the Apps Script project's Google Cloud project.
    1. Return to the Chat app Apps Script project.
    2. At the left, click Project Settings .
    3. Under Google Cloud Platform (GCP) Project, click Change project.
    4. In GCP project number, paste the Google Cloud project number.
    5. Click Set project.

You now have working app 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:

  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.

Step 2: Publish the app

Publish the Chat app 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 app:

    3. In the App name field, enter Quickstart app.

    4. In the Avatar URL field, enter https://developers.google.com/chat/images/quickstart-app-avatar.png.

    5. In the Description field, enter Quickstart app.

    6. Under Functionality, select Receive 1:1 messages and Join spaces and group conversations.

    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 app is ready to respond to messages.

Step 3: Run the sample

To run the sample, do the following:

  1. Open Google Chat.
  2. Send a new direct message to the app by clicking Start a chat > Find apps.
  3. On the Find apps page, search for "Quickstart App".
  4. Next to Quickstart App, click Chat.
  5. In the new direct message with the app, type Hello and press enter.

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

Next steps

To add more functionality to your Chat app, refer to these guides:

  • Create interactive cards — Card messages support a defined layout, interactive UI elements like buttons, and rich media like images. Use card messages to present detailed information, gather information from users, and guide users to take a next step.
  • Support slash commands — Slash commands let you register and advertise specific commands that users can give your app by typing a command that begins with a forward slash (/), like /help.
  • Launch dialogs — Dialogs are windowed, card-based interfaces that your app can open to interact with a user. Multiple cards can be strung together sequentially, which helps users complete multi-step processes, like filling in form data.

Further reading