Build apps for Google Chat with Gemini

1. Before you begin

What are Google Chat apps with Gemini?

Google Chat apps with Gemini do the following:

  • Bring your services and resources into Google Chat, which lets users get information and take action without leaving the conversation.
  • Integrate with the generative AI model Gemini, so they can create or search data like text or images at specific times to streamline your workflows.

Why integrate Google Chat apps with Gemini?

The typical use cases of Generative AI models like Gemini fall in the following categories:

  • Content creation and enhancement. Generate marketing copy, craft social media posts, create realistic images, compose music, or aid in the creation of video content.
  • Data search. Extract key insights from an unstructured knowledge base, summarize lengthy texts, classify contents, or translate languages with enhanced accuracy and speed.
  • Conversation. Engage in natural, informative, and creative conversations.

The ability to integrate these capabilities directly within the familiar interface of Google Chat is a huge opportunity for anyone who wants to improve the experience and productivity of their users.

Prerequisites

What you build

In this codelab, you build three Google Chat apps with Gemini to cover the three use cases introduced in the previous section.

Issue management app (content creation and enhancement)

This app does the following:

  • Manages issues from creation to closure with basic interactions, app home, and app authentication.
  • Monitors messages and provides inclusivity help with events and accessory widgets.

You use Gemini to do the following:

  • Generate issue reports based on message history and issue details.
  • Classify non-inclusive words in messages with gated prompts.

The main technologies used are Vertex AI, Gemini, Apps Script, and Google Workspace APIs (Admin, Chat, Docs, Events).

22efdecff4601417.png

2d127c63518673b2.png

9aea694937f2f3ed.png

This app relies on Gemini to understand and answer questions in natural language and to return source references from unstructured data.

The main technologies used are Dialogflow CX data store agent, Dialogflow CX webhook, Google Cloud Functions, and Gemini.

9468866bfe848bb8.png

Feedback app (conversation)

This app relies on Gemini to collect and store reviews with conversations in natural language.

The main technologies used are Dialogflow CX agent, Dialogflow CX tool, OpenAPI, Google Cloud Functions, and Gemini.

99a7a0295f122f31.png

What you learn

  • How to integrate Google Chat apps with Gemini through Vertex AI.
  • How to integrate Google Chat apps with Dialogflow CX agents.
  • How to use the latest features of Google Chat: app home, Google Chat Events, and accessory widgets.

What you need

2. Get set up

Initialize resources

In this section, you access and configure the following resources from your preferred web browser.

Apps Script project

In the Apps Script console, follow these steps:

  1. Click Settings and then enable the Google Apps Script API.

ea06c593b347b9d1.png

  1. Select your project.
  2. Click Project settings.
  3. Select the Show "appsscript.json" manifest file in editor checkbox.
  4. Rename the project to Chat Apps Gemini.

12c1485bd248b766.png

Google Cloud project

In the Google Cloud console, follow these steps:

  1. Select your project.
  2. Click Menu ☰ > APIs & services > OAuth consent screen > Edit app, and then set App name to Chat Apps Gemini.

  1. Navigate to the Google Chat API configuration, and then set the App name and Description to Chat Apps Gemini.

a71f040755da3b8b.png

Google Chat

In Google Chat, follow these steps:

  1. If necessary, start a chat with your Google Chat app.
  2. Send a message, such as Hello, to ensure that it works.

9625418251528ae9.png

Download source code and resources locally

  1. Download this GitHub repository.

  1. In your preferred development environment, open the apps-script/chat-apps-gemini directory and then navigate to the same directory in your terminal.

da9478df97c99194.png

Install and configure clasp

We use clasp to easily edit and push versions of the source code from the local environment to the Apps Script project.

  1. In your local environment, install the latest versions of node, npm , and clasp.
npm install -g @google/clasp
  1. Log in with your account:
clasp login

8bc2434e6dc6f22a.png

If successful, you see a basic confirmation screen in your web browser and the .clasprc.json file with your client credentials is updated. You can find where it's located in your terminal.

e1d833eb4d5b3a8f.png

3. App 1: Build

Review concepts

Vertex AI

Vertex AI offers everything you need to build and use generative AI, including AI solutions, agent builder, more than 130 foundation models, and a unified AI platform.

c9e9c7a1945b22ac.png

Gemini

Gemini is a multimodal LLM from Google accessible through Vertex AI. It helps people unlock their human potential so that they can augment their imagination, expand their curiosity, and enhance their productivity.

Advanced Chat service

The Advanced Chat service lets you use the Google Chat API in Apps Script. This allows scripts to find, create, and modify Chat spaces, add or remove members to spaces, and read or post messages with text, cards, attachments, and reactions.

Review architecture

8c9c7b7328a69ea6.png

This Google Chat app is built with Apps Script. It works as follows:

  1. A user sends a message to the app, either in a direct message or in a space.
  2. The app, which is implemented in an Apps Script project and is associated with a Google Cloud project, processes the message.
  3. The app integrates with Google Docs and Google Chat APIs.
  4. The app uses the Properties Service to persist data in script properties.
  5. The app sends a synchronous response, either in a direct message or in the original space.

Review flows

Create issue

7ca0e8ba3c8255bb.png

Troubleshoot issue from dedicated space

51b47714c378a24b.png

Close issue from dedicated space

89e50228deeab0f9.png

Review source code

The Apps Script project contains the following scripts:

  • Configuration: Constants to edit based on the environment.
  • ChatApp: Handles Google Chat interaction events, including messages, card clicks, slash commands, and dialogs.
  • Storage: Utility functions that rely on Properties Services.
  • ChatAppAuth: Utility functions that rely on Google Chat app authentication.
  • Docs: Utility functions that rely on Google Docs.
  • VertexAi: Utility functions that rely on Vertex AI.

And here are the parts that are actively used when generating report documents with Gemini and chat space histories:

appsscript.json

// Enables the Admin SDK Directory and Chat services, which you need to retrieve
// messages and usernames.

"enabledAdvancedServices": [
  ...
  {
    "userSymbol": "AdminDirectory",
    "version": "directory_v1",
    "serviceId": "admin"
  },
  {
    "userSymbol": "Chat",
    "version": "v1",
    "serviceId": "chat"
  }
  ...
]
// Includes the OAuth scopes to request the Admin SDK Directory, Google Chat,
// Google Docs, and Vertex AI APIs.

"oauthScopes": [
  ...
  "https://www.googleapis.com/auth/admin.directory.user.readonly",
  "https://www.googleapis.com/auth/chat.messages.readonly",
  "https://www.googleapis.com/auth/documents",
  "https://www.googleapis.com/auth/cloud-platform",
  ...
]

Configuration.js

// Relies on two constants: the first one is the Google Cloud project ID and the
// second one is the Vertex AI location to be used.

...
const PROJECT_ID = 'replace-with-gcp-project-id';
const VERTEX_AI_LOCATION_ID = 'us-central1';
...

ChatApp.js

// The slash command process function retrieves history, generates content, and passes
// it to the report generator.

function processSlashCommand(event) {
  ...
  if (event.message.slashCommand.commandId == CLOSE_COMMAND_ID
    && event.message.space.type !== "DM") {
    ...
    const history = exportSpaceHistory(spaceId);
    const summary = summarizeSpace(history);
    const docUrl = createReport(
      issue.title, issue.description, resolution, history, summary
    );
    ...
  }
  ...
}
/**
 * Fetches and concatenates the 100 first space messages by using the Google Chat API.
 *
 * Messages with slash commands are filtered (app command invocations).
 *
 * @return {string} concatenate space messages in the format "Sender's name: Message"
 */
function exportSpaceHistory(spaceName) {
  const messages = Chat.Spaces.Messages.list(spaceName, { 'pageSize': 100 }).messages;
  // Returns results after fetching message sender display names.
  let users = new Map();
  return messages
    .filter(message => message.slashCommand === undefined)
    .map(message =>
      `${getUserDisplayName(users, message.sender.name)}: ${message.text}`
    ).join('\n');
}
/**
 * Fetches a user's display name by using the Admin Directory API.
 *
 * A cache is used to only call the API once per user.
 *
 * @param {Map} cache the map containing users previously fetched
 * @param {string} userId the user ID to fetch
 * @return {string} the user's display name
 */
function getUserDisplayName(cache, userId) {
  if (cache.has(userId)) {
    return cache.get(userId);
  }
  let displayName = 'Unknown User';
  try {
    const user = AdminDirectory.Users.get(
      userId.replace("users/", ""),
      { projection: 'BASIC', viewType: 'domain_public' });
    displayName = user.name.displayName ? user.name.displayName : user.name.fullName;
  } catch (e) {
    // Ignores errors, uses 'Unknown User' by default.
  }
  cache.set(userId, displayName);
  return displayName;
}

VertexAi.js

/**
 * Summarizes a Google Chat space history with the Gemini Pro model using
 * Vertex AI API.
 *
 * @param {string} history the history
 * @return {string} the summary
 */
function summarizeSpace(history) {
  const url = `https://${VERTEX_AI_LOCATION_ID}-aiplatform.googleapis.com/v1`
    + `/projects/${PROJECT_ID}/locations/${VERTEX_AI_LOCATION_ID}`
    + "/publishers/google/models/gemini-1.0-pro:generateContent";
  const options = {
    method: "POST",
    headers: { Authorization: "Bearer " + ScriptApp.getOAuthToken() },
    contentType: "application/json",
    payload: JSON.stringify({
      contents: {
        role: "user",
        parts: {
          text: "Summarize the following conversation between engineers resolving"
              + " an issue in a few sentences.\n\n" + history
        }
      },
      safetySettings: {
        category: "HARM_CATEGORY_SEXUALLY_EXPLICIT",
        threshold: "BLOCK_LOW_AND_ABOVE"
      },
      generationConfig: {
        temperature: 0.2,
        topP: 0.8,
        topK: 40
      }
    })
  };

  return JSON.parse(UrlFetchApp.fetch(url, options).getContentText())
    .candidates[0].content.parts[0].text;
}

Docs.js

// The report generator function adds two sections: the first one is for the summary and the second one is for history.
function createReport(..., history, summary) {
  ...
  body.appendParagraph("Summary").setHeading(DocumentApp.ParagraphHeading.HEADING1);
  body.appendParagraph(summary);
  body.appendParagraph("History").setHeading(DocumentApp.ParagraphHeading.HEADING1);
  body.appendParagraph(history);
  ...
}

Update Google Cloud project

Enable APIs

  1. In the Google Cloud console, enable the Google Docs, Google Admin SDK, and Vertex AI APIs:

  1. Click Menu ☰ > APIs & Services > Enabled APIs & Services and then confirm that the APIs are enabled.

Initiate service account

In the Google Cloud console, follow these steps:

  1. Click Menu ☰ > IAM & Admin > Service Accounts > + Create service account.

74cf57426419f39.png

  1. Set Service account name to chat-app.
  2. Set Service account description to Chat app auth.
  3. Click Create and continue.
  4. Click Done. You're redirected to the Service accounts page and can see the service account that you created.

ca0468f1f93990f9.png

  1. Select the newly created service account.
  2. Select the Keys tab.
  3. Click Add key.
  4. Click Create new key.
  5. Select JSON.
  6. Click Create.

9f7e6ea020978ab0.png

The dialog closes and your newly created public/private key pair is automatically downloaded to your local environment as a JSON file. You use its content later when you edit your Apps Script project's source code.

Update Google Chat API configuration

In the Google Cloud console, follow these steps:

  1. Add a slash command.
  2. Set Name to /create.
  3. Set Command ID to 1.
  4. Set Description to Create a new issue.
  5. Select the Opens a dialog checkbox.
  6. Add another slash command.
  7. Set Name to /close.
  8. Set Command ID to 2.
  9. Set Description to Close an issue.
  10. Click Save.

bee2e7b63659ab33.png

Update Apps Script project

  • Change the current directory in your local terminal to issue-management/1-baseline. It contains the source code. Before pushing the source code to your Apps Script project, you need to configure a few things.

Configure source code

  1. Set the JSON constant named CHAT_CREDENTIALS in the Configuration.js file to the private key file content that you downloaded previously.

d721f6bff73c5304.png

  1. In the Google Cloud console, click Menu ☰ > IAM & Admin > Settings.

  1. Copy the project ID.

82592fa0bd113469.png

  1. Set the string constant named PROJECT_ID in the Configuration.js file to the project ID.

383cee561130ceba.png

Configure clasp settings

To initialize clasp settings to push the source code to the right Apps Script project, follow these steps:

  1. In the Apps Script console, select your project.
  2. Select Project Settings.
  3. Under IDs, click Copy.

20ea033b6de882c6.png

  1. In the current directory, create a .clasp.json file.
  2. Replace <your-script-id> with the copied ID.
  3. Copy the result to the .clasp.json file.
  4. Save the .clasp.json file.
{
  "scriptId": "<your-script-id>"
}

Push source code

  • Run the following command:
$clasp push
? Manifest file has been updated. Do you want to push and overwrite? Yes
└─ appsscript.json
└─ ChatApp.js
└─ ChatAppAuth.js
└─ Configuration.js
└─ Docs.js
└─ Storage.js
└─ VertexAi.js
Pushed 7 files.

Try it

  1. In Google Chat, send Hello! in a direct message to the app. The app doesn't reply, but a message appears that prompts configuration.

4c1fc68121dcffed.png

  1. Click Configure.
  2. Select your Google Account.
  3. Authenticate.
  4. Review and allow access to the app.

4a2fd7ac5918bf1a.png

If successful, you see a basic confirmation screen on the web page and an actual response from the app to your original message.

acb9065568fe47d2.png

2d6ef9c62f47e082.png

  1. Send another direct message to the app, but with the slash command /create.

be3f3c6eb0f929c1.png

  1. In the dialog, set Title to Issue Title 1.
  2. Set Description to Issue Description 1.
  3. Click Create.

22efdecff4601417.png

The app does the following:

  1. Closes the dialog.
  2. Creates a space dedicated to the newly created issue with the same title.
  3. Joins the newly created space.
  4. Sends a message containing the description of the issue in the newly created space.
  5. Sends a direct message to you with a link to the newly created space.

3253cec2392e281f.png

  1. In the newly created space, send a message with the slash command /close and resolution such as Not reproducible.

132cc4acfc10b98c.png

The app does the following:

  1. Creates a report document in Google Docs.
  2. Sends a message to the space dedicated to the issue with a link to the newly created report document.

2d127c63518673b2.png

  1. Open the report document. It contains basic information, the history, and a summary.

9aea694937f2f3ed.png

4. Optional: App 1: Add app home

Review concepts

App home is a customizable card message that a Chat app sends to a user when the user accesses the Home tab from a direct message with the Chat app. This is typically used to display app documentation or an overview. Technically, there is a dedicated event to handle and it's based on the same core principles as card messages.

65f56f70f67a32e4.png

Review flows

Manage issues

10663f5fc107fb3f.png

Review source code

The Apps Script project needs to be edited.

ChatApp.js

/**
 * Handles app home requests in Google Chat.
 * 
 * Displays the latest status of all issues.
 */
function onAppHome() {
  // Generates one card section per issue.
  var sections = [];
  for (var issueKey in appProperties.getProperties()) {
    const issue = JSON.parse(appProperties.getProperty(issueKey));
    if (issue.spaceId) {
      sections.push({
        header: `${issue.status} - ${issue.title}`,
        widgets: [{ textParagraph: {
            text: `Description: ${issue.description}`
          }}, { textParagraph: {
            text: `Resolution: ${issue.resolution}`
          }}, { buttonList: { buttons: [{
              text: "Open space",
              onClick: { openLink: {
                url: `https://mail.google.com/mail/u/0/#chat/space/${issue.spaceId}`
              }}
            }, {
              text: "Open report",
              onClick: { openLink: {
                url: issue.reportUrl !== "" ? issue.reportUrl : "docs.new"
              }},
              disabled: issue.reportUrl === ""
          }]}
        }]
      });
    }
  }

  return { action: { navigations: [{ push_card: {
    sections: sections
  }}]}};
}

Update Google Cloud project

In the Google Cloud console, follow these steps:

  1. Under the Interactive features section, select the Support app home checkbox.

97159c1c69ca8303.png

In your local environment, follow these steps:

  1. Change the current directory in your terminal to issue-management/2-app-home. It contains the source code that you need to use.
  2. Copy the issue-management/1-baseline/.clasp.json file to your current directory.
  3. Copy the issue-management/1-baseline/Configuration.js file to your current directory so that it replaces the existing one.
  4. Run the following command:
clasp push

Try it

In Google Chat, follow these steps:

  1. Send a direct message with the slash command /create to the app. The app opens a dialog.
  2. Set Title to Issue Title 2.
  3. Set Description to Issue Description 2.
  4. Click Create.

3b2a8690e758f965.png

  1. Select the Home tab from your space with the Google Chat app. You can see the details of the issues that you created.

ed8e32da0e6f2ac6.png

5. Optional: App 1: Add space monitoring

Review concepts

Pub/Sub

Pub/Sub is an asynchronous and scalable messaging service that decouples services producing messages from services processing those messages. Pub/Sub lets you create systems of event producers and consumers, called publishers and subscribers. Publishers communicate with subscribers asynchronously by broadcasting events, rather than by synchronous remote procedure calls (RPCs).

Publishers send events to the Pub/Sub service without regard for how or when these events are to be processed. Pub/Sub then delivers events to all the services that react to them. In systems communicating through RPCs, publishers must wait for subscribers to receive the data. However, the asynchronous integration in Pub/Sub increases the flexibility and robustness of the overall system.

Topic: A named resource that represents a feed of messages. You must create a topic before you can publish or subscribe to it.

Subscription: To receive messages published to a topic, you must create a subscription to that topic. The subscriber client receives and processes the messages published to the topic. A topic can have multiple subscriptions, but a given subscription belongs to a single topic.

Google Workspace events

Google Workspace events represent changes to Google Workspace resources, such as when resources are created, updated, or deleted. Apps can subscribe to Google Workspace resources to receive and process relevant events asynchronously.

7816e477b112bfb6.png

Here's how the Google Workspace Events API delivers events to an app through a subscription:

  1. The app subscribes to a resource in a Google Workspace app, such as a space.
  2. The resource to which the app subscribed changes.
  3. The Google Workspace app delivers an event to a topic in Pub/Sub, which serves as the notification endpoint for the app's Google Workspace subscription. The event contains data about what changed in the resource.
  4. The app processes the Pub/Sub message that contains the event and, if necessary, takes action.

Review flows

Create issue (update)

6d7a9d7a68666a80.png

Troubleshoot issue from dedicated space (update)

17e60f052f222456.png

Close issue from dedicated space (update)

742d490ea0b6fe3a.png

Process subscriptions

de3017100dec6401.png

Review source code

The Apps Script project needs to be edited.

appsscript.json

// Enables the Workspace Events service.

"enabledAdvancedServices": [
  ...
  {
    "userSymbol": "WorkspaceEvents",
    "version": "v1",
    "serviceId": "workspaceevents"
  }
  ...
]

Configuration.js

// Adds two constants: the first one is the Pub/Sub topic ID and the second one
// is the Pub/Sub subscription ID to be used to retrieve Google Workspace events.

...
const GWS_PUBSUB_TOPIC_ID = `projects/${PROJECT_ID}/topics/workspace-events`;
const GWS_PUBSUB_SUBSCRIPTION_ID =
  `projects/${PROJECT_ID}/subscriptions/workspace-events-sub`;
...

ChatApp.js

// Edits the function to delete the subscription at issue closure.

function processSlashCommand(event) {
  ...
  if (event.message.slashCommand.commandId == CLOSE_COMMAND_ID
    && event.message.space.type !== "DM") {
    ...
    deleteSubscription(issue.subscriptionId);
    ...
  }
  ...
}
// Edits the function to create the subscription.

function createIssue(event) {
  ...
  const subscriptionId = createSpaceSubscription(spaceUrl);
  const createdIssue = saveCreatedIssue(..., subscriptionId);
  ...
}
// Edits the function to delete the subscription.

function onRemoveFromSpace(event) {
  ...
  deleteSubscription(issue.subscriptionId);
  ...
}

Storage.js

// Edits the function to keep track of the subscription ID.

function saveCreatedIssue(..., spaceId, subscriptionId) {
  ...
  appProperties.setProperty(spaceId, JSON.stringify({
    ...
    subscriptionId: subscriptionId,
    ...
  }));
  ...
}

WorkspaceEvent.js

/**
 * Creates a new subscription to Google Workspace Events associated to a
 * Google Chat space.
 * 
 * The subscription scope includes message creation events and resources.
 * 
 * @param {string} spaceId the space ID to create a subscription for
 * @return the ID of the newly created subscription
 */
function createSpaceSubscription(spaceId) {
  const operation = WorkspaceEvents.Subscriptions.create({
    targetResource: `//chat.googleapis.com/${spaceId}`,
    eventTypes: ["google.workspace.chat.message.v1.created"],
    notificationEndpoint: { pubsubTopic: GWS_PUBSUB_TOPIC_ID },
    payloadOptions: { includeResource: true },
  });

  return operation.response.name;
}
/**
 * Processes events from subscription by using the Google Cloud PubSub API.
 * 
 * It pulls and acknowledges each event.
 */
function processSubscription() {
  const response = UrlFetchApp.fetch(
    `https://pubsub.googleapis.com/v1/${GWS_PUBSUB_SUBSCRIPTION_ID}:pull`,
    {
      method: "POST",
      contentType: "application/json",
      headers: { "Authorization": "Bearer " + ScriptApp.getOAuthToken() },
      payload: JSON.stringify({ maxMessages: 10 })
    }
  );

  const messages = JSON.parse(response.getContentText()).receivedMessages;
  for (var messageIndex in messages) {
    const message = messages[messageIndex];
    const ceType = message.message.attributes["ce-type"];
    const dataStr = Utilities.newBlob(Utilities.base64Decode(message.message.data))
      .getDataAsString();
    if (ceType === "google.workspace.events.subscription.v1.expirationReminder") {
      // Renews subscription.
      renewSubscription(JSON.parse(dataStr).subscription.name);
    } else if (ceType === "google.workspace.chat.message.v1.created") {
      // Processes the message text when it's sent in a space.
      const chatMessage = JSON.parse(dataStr).message;
      if (chatMessage.sender.type !== "BOT") {
        console.log("Message was processed.");
      }
    }
    // Acknowledges successful processing to avoid getting it again next time.
    ackSubscription(message.ackId);
  }
}
/**
 * Acknowledges a subscription event by using the Google Cloud PubSub API.
 * 
 * @param {string} ackId the ID of the event acknowledgment to send
 */
function ackSubscription(ackId) {
  UrlFetchApp.fetch(
    `https://pubsub.googleapis.com/v1/${GWS_PUBSUB_SUBSCRIPTION_ID}:acknowledge`,
    {
      method: "POST",
      contentType: "application/json",
      headers: { "Authorization": "Bearer " + ScriptApp.getOAuthToken() },
      payload: JSON.stringify({
        ackIds: [ackId]
      })
    }
  );
}
/**
 * Renews a subscription to Google Workspace Events.
 * 
 * The default time to live option is used.
 * 
 * @param {string} subscriptionId the ID of the subscription to renew
 */
function renewSubscription(subscriptionId) {
  WorkspaceEvents.Subscriptions.patch({ttl: '0s'}, subscriptionId);
}
/**
 * Deletes a subscription to Google Workspace Events.
 * 
 * @param {string} subscriptionId the ID of the subscription to delete
 */
function deleteSubscription(subscriptionId) {
  WorkspaceEvents.Subscriptions.remove(subscriptionId);
}

Update Google Cloud project

Enable APIs

  1. In the Google Cloud console, enable Google Workspace Events and PubSub.

  1. Click Menu ☰ > APIs & services > Enabled APIs & services and then confirm that both are enabled.

Initiate subscription

You need to create and subscribe to a Pub/Sub topic for all workspace events to be posted.

In the Google Cloud console, follow these steps:

  1. Go to Menu ☰ > Pub/Sub > Topics.

  1. Click Create topic.
  2. Set Topic ID to workspace-events.
  3. Select the Add a default subscription checkbox.
  4. Click Create.

b39f9a0aec7c9939.png

To grant access to publish Pub/Sub messages to your newly created topic from Google Chat, follow these steps:

  1. Select the topic from the list.
  2. Select the Permissions tab.
  3. Add [email protected] to New principals.
  4. Select Pub/Sub Publisher for Role.
  5. Click Save.

8d4016c37532503.png

Update Apps Script project

In the Google Cloud console, follow these steps:

  1. Go to Menu ☰ > IAM & Admin > Settings.

  1. Copy the project ID.

82592fa0bd113469.png

In your local environment, follow these steps:

  1. Change the current directory in your terminal to issue-management/3-message-monitoring. It contains the source code that you need.
  2. Set the string constant named PROJECT_ID in the Configuration.js file to the copied project ID.
  3. Set the JSON constant named CHAT_CREDENTIALS in the Configuration.js file to the private key file content that you downloaded earlier.
  4. Copy the issue-management/2-app-home/.clasp.json file to your current directory.
  5. Run the following command:
clasp push

Try it

In Google Chat, follow these steps:

  1. Send a direct message with the slash command /create to the app. The app opens a dialog.
  2. Set Title to Issue Title 3.
  3. Set Description to Issue Description 3.
  4. Click Create.
  5. In the newly created space, send a few messages that discuss the issue.
  6. Send a message with the slash command /close and resolution such as Fixed.

In the Google Cloud console, follow these steps:

  1. Go to Menu ☰ > Pub/Sub > Subscriptions.

  1. Select the subscription workspace-events-sub.
  2. Select the Messages tab.
  3. Click Pull. The table displays the messages related to what you sent to the newly created space.

82631c9792d83889.png

In the Apps Script console, follow these steps:

  1. Select your project.
  2. Select Editor.
  3. Select the WorkspaceEvent.gs file.
  4. Select processSubscription in the Run section.
  5. Click Run.You can see from the execution log that messages were processed.

c612e8fa2bd0a163.png

In the Google Cloud console, follow these steps:

  1. Go to Menu ☰ > Pub/Sub > Subscriptions.

  1. Select the subscription workspace-events-sub.
  2. Select the Messages tab.
  3. Click Pull. The table no longer displays the messages related to what you sent to the newly created space.

e185454cac862a7b.png

  • In Google Chat, in the space dedicated to the third issue that you created with the slash command /create, send a few more messages that discuss the issue.

In the Google Cloud console, follow these steps:

  1. Go to Menu ☰ > Pub/Sub > Subscriptions.

  1. Select the subscription workspace-events-sub.
  2. Select the Messages tab.
  3. Click Pull. The table doesn't display the messages related to what you sent to the newly created space.

6. Optional: App 1: Add inclusivity help

Review concepts

Gen AI prompting is the art of crafting instructions or questions to guide a generative AI model toward the specific type of desired output. A common practice is to gate answers by adding rules and conditions in the prompts. This can help make the output safe, relevant, consistent, and aligned with expectations.

Review flows

Process subscriptions (update)

780d0802f77dd180.png

Review source code

The Apps Script project needs to be edited.

WorkspaceEvent.js

// Edits the function to replace logging by an actual card message.

function processSubscription() {
  ...
  for (var messageIndex in messages) {
    ...
    } else if (ceType === "google.workspace.chat.message.v1.created") {
      ...
      const inclusivityCheck = getInclusivityFeedback(chatMessage.text);
      if (inclusivityCheck !== "It's inclusive!") {
        createAppMessageUsingChatService({
          cardsV2: [{ cardId: "1", card: { header: {
              title: "Inclusivity",
              subtitle: `The following words are not inclusive: ${inclusivityCheck}`
          }}}]
        },
        chatMessage.space.name);
      }
      ...
    }
    ...
  }
  ...
}

VertexAi.js

/**
 * Gets feedback on inclusivity for a text with the Gemini Pro model using
 * Vertex AI API.
 * 
 * Returns "It's inclusive!" when it is otherwise a list of word(s) that might not
 * be optimal.
 *
 * @param {string} text the text
 * @return {string} the feedback
 */
function getInclusivityFeedback(text) {
  const url = `https://${VERTEX_AI_LOCATION_ID}-aiplatform.googleapis.com/v1`
    + `/projects/${PROJECT_ID}/locations/${VERTEX_AI_LOCATION_ID}`
    + "/publishers/google/models/gemini-1.0-pro:generateContent";
  const options =  {
    method: "POST",
    headers: { Authorization: "Bearer " + ScriptApp.getOAuthToken() },
    contentType: "application/json",
    payload: JSON.stringify({
      contents: {
        role: "user",
        parts: {
          text: "Are there any words that obviously go against inclusivity "
            + "in this text:"
            + `\n\n----------\n${text}\n----------\n\n`
            + "If there are not, answer \"It's inclusive!\" "
            + "otherwise answer by listing them separated by commas. "
            + "Do not answer with any explanation."
        }
      },
      safetySettings: {
        category: "HARM_CATEGORY_SEXUALLY_EXPLICIT",
        threshold: "BLOCK_LOW_AND_ABOVE"
      },
      generationConfig: {
        temperature: 0.2,
        topP: 0.8,
        topK: 40
      }
    })
  };

  return JSON.parse(UrlFetchApp.fetch(url, options).getContentText())
    .candidates[0].content.parts[0].text;
}

Update Apps Script project

In your local environment, follow these steps:

  1. Change the current directory in your terminal to issue-management/4-inclusivity-help. It contains the source code you that you need.
  2. Copy the issue-management/3-message-monitoring/.clasp.json file to your current directory.
  3. Copy the issue-management/3-message-monitoring/Configuration.js file to your current directory so that it replaces the existing one.
  4. Run the following command:
clasp push

Try it

In Google Chat, follow these steps:

  1. Send a direct message with the slash command /create to the app. The app opens a dialog.
  2. Set Title to Issue Title 4.
  3. Set Description to Issue Description 4.
  4. Click Create.
  5. In the newly created space, send It happened to me last week as well.

In the Apps Script console, follow these steps:

  1. Select your project.
  2. Select Editor.
  3. Select the WorkspaceEvent.gs file.
  4. Select processSubscription in the Run section.
  5. Click Run. You can see from the execution log that messages were processed.

In Google Chat, follow these steps:

  1. Notice that the app didn't send any inclusivity help in the newly created space.
  2. In the newly created space, send the message I had to add myself from the master to fix it.

In the Apps Script console, follow these steps:

  1. Select your project.
  2. Select Editor.
  3. Select the WorkspaceEvent.gs file.
  4. Select processSubscription in the Run section.
  5. Click Run. You can see from the execution log that messages were processed. In Google Chat, the app sent an inclusivity help message in the newly created space.

7936342847acbe2d.png

7. Optional: App 1: Add preferences

.

Review concepts

An accessory widget is a borderless widget attached to the bottom of a message sent by an app. This is typically used to enable quick reactions from the user in the specific context of messages. Technically, it's based on the same core principles as card buttons.

eebe88238f6b13f.png

Review flows

Disable inclusivity help

1bb7a8592ee6221e.png

Review source code

The Apps Script project needs to be edited.

ChatApp.js

// Edits the function to handle the inclusivity help disablement action for a
// given space.

function onCardClick(event) {
  ...
  if (event.action.actionMethodName === "disableInclusivityHelp") {
    disableInclusivityHelp(event.common.parameters.spaceId);
  }
}

Storage.js

// Edits the function to keep track of the inclusivity help setting.

function saveCreatedIssue(title, description, spaceId, subscriptionId) {
  appProperties.setProperty(spaceId, JSON.stringify({
    ...
    inclusivityHelp: true,
    ...
  }));
  ...
}
/**
 * Disables inclusivity help in a space.
 * 
 * @param {string} spaceId the ID of dedicated space of the issue
 */
function disableInclusivityHelp(spaceId) {
  var issue = JSON.parse(appProperties.getProperty(spaceId));
  issue.inclusivityHelp = false;
  appProperties.setProperty(spaceId, JSON.stringify(issue));
}
/**
 * Checks whether the app should help with inclusivity in a given space.
 * 
 * @param {string} spaceId the ID of dedicated space of the issue
 * @return whether the app should help with inclusivity
 */
function shouldHelpWithInclusivity(spaceId) {
  return JSON.parse(appProperties.getProperty(spaceId)).inclusivityHelp;
}

WorkspaceEvent.js

// Edits the function to display the accessory widget to the existing card message.

function processSubscription() {
  ...
  for (var messageIndex in messages) {
    ...
    } else if (ceType === "google.workspace.chat.message.v1.created") {
      ...
      if (... && shouldHelpWithInclusivity(chatMessage.space.name)) {
        createAppMessageUsingChatService({
          ...
          accessoryWidgets: [{ buttonList: { buttons: [{
            altText: "Disable inclusivity help",
            icon: {
              iconUrl: "https://upload.wikimedia.org/.../Stop_hand_rugen.png"
            },
            onClick: { action: {
              function: "disableInclusivityHelp",
              parameters: [{
                key: "spaceId",
                value: chatMessage.space.name
              }]
            }}
          }]}}]
        }, ...);
        ...
      }
      ...
    }
    ...
  }
  ...
}

Update Apps Script project

In your local environment, follow these steps:

  1. Change the current directory in your terminal to issue-management/5-disable-help. It contains the source code that you need.
  2. Copy the issue-management/4-inclusivity-help/.clasp.json file to your current directory.
  3. Copy the issue-management/4-inclusivity-help/Configuration.js file to your current directory so that it replaces the existing one.
  4. Run the following command:
clasp push

Try it

Disable help

  • In Google Chat, in the space dedicated to the fourth issue that you created with the slash command /create, send the message I had to add myself from the master to fix.

In the Apps Script console, follow these steps:

  1. Select your project.
  2. Select Editor.
  3. Select the WorkspaceEvent.gs file.
  4. Select processSubscription in the Run section.
  5. Click Run. You can see from the execution log that messages were processed.

In Google Chat, follow these steps:

  1. Notice that the app sent a message with inclusivity help to the space dedicated to the issue with an accessory widget.
  2. Click the accessory widget to disable inclusivity help.

de722cff1928dec9.png

Check disablement

  • In Google Chat, in the space dedicated to the fourth issue that you created with the slash command /create, send the message I had to add myself from the master to fix.

In the Apps Script console, follow these steps:

  1. Select your project.
  2. Select Editor.
  3. Select the WorkspaceEvent.gs file.
  4. Select processSubscription in the Run section.
  5. Click Run. You can see from the execution log that messages were processed. In Google Chat, the app didn't send a message with inclusivity help to the space dedicated to the issue because it was disabled.

347d659db53b73e9.png

8. App 2: Build

Review concepts

Gen AI grounding

It's about making AI models more factual and reliable by connecting them to verifiable sources of knowledge. This technique helps prevent AI from inventing information and can help make responses contextually relevant and less biased.

Natural language

Any language spoken or written by humans for everyday communication, in contrast to artificial or computer-based languages.

Cloud Storage

Cloud Storage allows worldwide storage and retrieval of any amount of data at any time. It can be used for a range of scenarios, including serving website content, storing data for archival and disaster recovery, or distributing large data objects to users through direct download.

Dialogflow CX data store

Dialogflow CX integrates with data stores that are collections of websites and documents used by data store agents to find answers for end user's questions from specific data. For a given question, the data store agent searches for an answer from the given source content and summarizes the findings into a coherent response. It also provides supporting links to the sources of the response for the end user to learn more.

Review architecture

9d3342d12f3b4dda.png

This Google Chat app is built with Dialogflow CX and works as follows:

  1. A user sends a message to the app, either in a direct message or in a space.
  2. The app, which is a Dialogflow CX agent and is associated with a Google Cloud project, processes the message.
  3. The app integrates with a data store located in Cloud Storage.
  4. The app sends a synchronous response, either in a direct message or in the original space.

Review flows

Answer question

aad9fb5a7ca48956.png

Review source code

The only source that you need isn't code, but rather data that you use for grounding.

google-chat-overview.pdf

Contains the unstructured information of Google Chat apps, a printed version of a page from the Google Workspace developers website.

e9b91c4587b1a3a0.png

Update Google Cloud project

In the Google Cloud console, follow these steps:

  1. Enable the Dialogflow and Cloud Storage APIs.

  1. Enable the Vertex AI Agent Builder API.

  1. Click Menu ☰ > APIs & services > Enabled APIs & services and then confirm that all APIS are enabled.

.

Create Dialogflow CX data store agent

Initiate knowledge data

In the Google Cloud console, follow these steps:

  1. Click to Menu ☰ > Cloud Storage > Buckets.

4f15978ae9f1b687.png

  1. Click Create.
  2. Set name to gchat-knowledge.
  3. Click Create.

6b38c6d4d2c41bba.png

  1. Select the gchat-knowledge bucket.
  2. Click Upload files.
  3. Select the knowledge-app/grounding/google-chat-overview.pdf file from your local environment.

df89acb22e1762af.png

Create app

In the Google Cloud console, follow these steps:

  1. Click Menu ☰ > Agent builder > Apps.

  1. Click New app.
  2. Select the Chat type.

44276003074bcf14.png

  1. Set Company name to your company name.
  2. Set Agent name to knowledge.
  3. Click Continue.

c4fedfd7556f723b.png

  1. Click Create new data store.
  2. Select Cloud Storage as the data source.

6e2440ecf0f8f9bd.png

  1. Select File.
  2. Click Browse.
  3. Select the google-chat-overview.pdf file.
  4. Click Continue.
  5. Set the data store name to gchat-knowledge-ds.
  6. Click Create.

a675df7490b83900.png

  1. Select the gchat-knowledge-ds data store in the table.
  2. Click Create.

f121d580771ed96.png

  1. After a couple of minutes, click Menu ☰ > Agent builder > Apps and notice that you can see the app.

d929a7431dd84968.png

  1. Click Menu ☰ > Agent builder > Data stores.

  1. Click the gchat-knowledge-ds data store. The number of documents is 1, which indicates that it's ready.

558319790a0accf2.png

Complete and test app

In the Dialogflow CX console, follow these steps:

  1. Select your Google Cloud project.
  2. Select the knowledge agent.

ca9b2fb4be92e8e4.png

  1. Select Agent settings > Generative AI > Generative agent.
  2. Switch the model from Text Bison to Gemini Pro.
  3. Click Save.

68cc4713ec9b25a0.png

  1. Click Test agent.
  2. Send What is Google Chat?. The agent responds with something meaningful.

8e3a2cb02469041a.png

Integrate Google Chat app

In the Dialogflow CX console, follow these steps:

  1. Select your Google Cloud project.
  2. In the row of the knowledge agent, click 1e7ede7abae4aa3c.png > Copy name.

e19f61185158110d.png

In the Google Cloud console, follow these steps:

  1. Go to Google Chat API configuration.

  1. Under Connection settings, select Dialogflow.
  2. Under Dialogflow settings, select Dialogflow CX.
  3. Set Agent or Environment resource name to the agent name that you copied.
  4. Remove the two slash commands.

505ff39a50880904.png

  1. In Google Chat, send What is Google Chat? in a direct message to the Google Chat app. The agent responds with something meaningful.

abda9e43b81fb0ea.png

9. Optional: App 2: Add sources

Review concepts

Dialogflow CX webhook

A service that hosts business logic or calls other services. During a Dialogflow CX session, webhooks can rely on the data extracted by natural language processing to generate dynamic responses, validate collected data, or trigger actions on the backend.

Cloud Functions

Cloud Functions are great for building serverless backends, doing real-time data processing, and creating intelligent apps. There are no servers to provision, manage, patch, or update. They automatically scale, and are highly available and fault-tolerant.

Review flows

Answer question (update)

92767c07c7b252aa.png

Review source code

The only source code that you need is the function to adapt agent responses to Google Chat messages. It's used as a webhook.

package.json

// The function relies on the Cloud Functions framework to run.

{
  "name": "agent-response-adapter",
  "version": "0.0.1",
  "dependencies": {
    "@google-cloud/functions-framework": "^3.0.0"
  },
  ...
}

index.js

/** 
 * Handles all incoming requests.
 *
 * It takes a Dialogflow CX agent response as input and returns a
 * valid Google Chat card message with both the text and source links
 */
functions.http('agent-response-adapter', (request, response) => {
  // Creates Google Chat buttons based on the data store agent response
  // grounding details.
  var linkTitles = [];
  var linkButtons = [];
  const grounding = request.body.messages[1].payload.richContent[0][0];
  if (grounding.type === "match_citations") {
    // Supports citation match type.
    grounding.citations.forEach((citation) => {
      // Avoid duplications.
      if (linkTitles.indexOf(citation.title) < 0) {
        linkButtons.push({
          text: citation.title,
          onClick: { openLink: {
            url: citation.actionLink
          }}
        });
        linkTitles.push(citation.title);
      }
    });
  } else if (grounding.type === "info") {
    // Supports info type.
    if (linkTitles.indexOf(grounding.title) < 0) {
      linkButtons.push({
        text: grounding.title,
        onClick: { openLink: {
          url: grounding.actionLink
        }}
      });
      linkTitles.push(grounding.title);
    }
  }

  // Sends the Dialogflow CX fulfillment response to replace the agent response
  // with the Chat message with text and source buttons.
  response.send({ fulfillment_response: {
    merge_behavior: "REPLACE",
    messages: [{ payload: {
      // Reuses the original data store agent response text.
      text: request.body.messages[0].text.text[0],
      cardsV2: [{
        cardId: "sourcesCard",
        card: { sections: [{
          header: "Sources",
          widgets: [{ buttonList: {
            buttons: linkButtons
          }}]
        }]}
      }]
    }}]
  }});
});

Update Google Cloud project

In the Google Cloud console, follow these steps:

  1. Enable the Cloud Build, Cloud Functions, Cloud Logging, Artifact Registry, and Cloud Run APIs.

  1. Click Menu ☰ > APIs & services > Enabled APIs & services and then confirm that the APIs are enabled.

Update Dialogflow CX data store agent

You need to deploy a Cloud Function and update the Dialogflow CX webhook to trigger it with multiple sources when possible.

Return multiple sources

By default, a new data store agent only returns one source at maximum, but you can change for more.

In the Dialogflow CX console, follow these steps:

  1. Select your Google Cloud project.
  2. Select the knowledge agent.
  3. Select Start page.
  4. Select Edit data stores.
  5. Under the Agent responses section, set Data store response options to 5.
  6. Click Save.

f5932d03057df645.png

Initiate Cloud Function

In the Google Cloud console, follow these steps:

  1. Click Menu ☰ > Cloud Functions.

  1. Click on Create function.
  2. Under Basics, set name to function-1.
  3. Under Authentication, select the Allow unauthenticated invocations radio button.
  4. Under Runtime, build, connections and security settings, set Maximum number of instances to 3.
  5. Click Next.

bd3790a9285f9c07.png

  1. Set Entry point to agent-response-adapter.
  2. Replace the default content with the files located in the knowledge-app/agent-response-adapter directory.
  3. Click Deploy.

b379bb8ca0fc1079.png

  1. Copy the URL while you wait a couple minutes for the function to deploy.

eaae08cf048b9b1c.png

Initiate webhook

You need to configure the Dialogflow CX agent to use a webhook that triggers the newly deployed function.

In the Dialogflow CX console, follow these steps:

  1. Select your Google Cloud project.
  2. Select the knowledge agent.
  3. Select Manage > Webhooks > Create.
  4. Set Display name to Google Chat Response Adapter.
  5. Set Webhook URL to the URL that you copied previously.
  6. Click Save.

5f3c6804d52b87c1.png

  1. Click Build.
  2. Select Start page.
  3. Select Edit data stores.
  4. Under Webhook settings, click the Enable webhook toggle.
  5. Select Google Chat Response Adapter for Webhook.
  6. Set tag to arbitrary_tag.
  7. Click Save.

442fcaaec9b8f2e3.png

Test app

  • In Google Chat, send What is Google Chat? in a direct message to the Google Chat app. The agent responds with something meaningful and a card with sources, if any.

9468866bfe848bb8.png

10. App 3: Build

Review concepts

Conversational interactions

They are the back-and-forth exchanges of information or ideas between two or more people through natural language. This contrasts to technical interfaces that often rely on stateless, highly structured, and intolerant exchanges.

OpenAPI Specification

It provides a consistent means to carry information through each stage of the API lifecycle. It is a specification language for HTTP APIs that defines structure and syntax in a way that is not wedded to the programming language the API is created in. API specifications are typically written in YAML or JSON, allowing for easy sharing and consumption of the specification.

Dialogflow CX agent

The basic building block of agent apps. An agent app typically has many agents, where each agent is defined to handle specific tasks. The agent data is provided to the LLM, so it has the information it needs to answer questions and execute tasks. Each agent can provide information, send queries to external services, or defer conversation handling to a Dialogflow CX flow or another agent to handle sub-tasks.

Dialogflow CX tool

Tools are used to connect agent apps to external systems. These systems can augment the knowledge of agent apps and empower them to execute complex tasks efficiently.

Review architecture

9d3342d12f3b4dda.png

This Google Chat app is built with Dialogflow CX and works as follows:

  1. A user sends a message to the app, either in a direct message or in a space.
  2. The app, which is a Dialogflow CX agent and is associated with a Google Cloud project, processes the message.
  3. The app integrates with an agent.
  4. The app sends a synchronous response, either in a direct message or in the original space.

Review flows

Collect review

a67a5b8b513bfc2c.png

Review source code

The only source code that you need is the function to mock the backend service that the agent uses as a tool.

package.json

// The function relies on the Cloud Functions framework to run.

{
  "name": "feedback-app-backend",
  "version": "0.0.1",
  "dependencies": {
    "@google-cloud/functions-framework": "^3.0.0"
  },
  ...
}

index.js

/** 
 * Handles all incoming requests.
 * 
 * It always returns OK in plain text.
 */
functions.http('feedback-app-backend', (request, response) => {
    response.send('OK');
});

service-openapi.yaml

// Defines the backend service structure and how to request it.

openapi: 3.1.0
info:
  title: Review Store
  license:
    name: Apache 2.0
    identifier: Apache-2.0
  version: 0.0.1
servers:
  - url: https://us-central1-project-0.cloudfunctions.net
paths:
  /store-review:
    post:
      operationId: storeReview
      summary: Store a new review
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                stars:
                  type: integer
                  format: int64
      responses:
        '200':
          description: success
          content:
            application/json:
              schema:
                type: string

Initiate backend service mock

You deploy a Cloud Function to simulate a backend service that the Dialogflow CX agent app needs to integrate and call as a tool.

In the Google Cloud console, follow these steps:

  1. Click Menu ☰ > Cloud Functions.

  1. Click Create function.
  2. Under Basics, set name to function-2.
  3. Under Authentication, select the Allow unauthenticated invocations radio button.
  4. Under Runtime, build, connections and security settings, set Maximum number of instances to 3.
  5. Click Next.

e8cf0ee7441bf634.png

  1. Set Entry point to feedback-app-backend.
  2. Replace the default content with the files located in the feedback-app directory.
  3. Click Deploy.

bdb5cf9f503aa7f6.png

  1. Copy the URL while you wait a couple minutes for the function to deploy.

Create Dialogflow CX agent app

Create app

In the Google Cloud console, follow these steps:

  1. Click Menu ☰ > Agent builder > Apps.

  1. Click New app.
  2. Select Agent.
  3. Set Display name to Feedback App.
  4. Click Create.

7ef3dbacee96c5aa.png

Initiate tool

In the Google Cloud console, follow these steps:

  1. Click Menu ☰ > Agent builder > Apps.

  1. Select the Feedback App agent.
  2. Click Tools > + Create.
  3. Set Name to review.
  4. Select OpenAPI.
  5. Set description to the following value:
The tool takes the number of stars as a parameter of the store review method and saves it in a database for later use.
  1. Replace $URL in the feedback-app/service-openapi.yaml file with the URL that you copied previously.
  2. Set YAML Schema to the edited content of the feedback-app/service-openapi.yaml file.
  3. Click Save.

58085d6d56b603f7.png

Initiate agent

In the Google Cloud console, follow these steps:

  1. Click Menu ☰ > Agent builder > Apps.

  1. Select the Feedback App agent.
  2. Select Agents > Default Generative Agent.
  3. Set Agent name to Feedback collector.
  4. Set goal to the following value:
You are an agent that collects reviews from Google Chat app developers.
A review may be between 0 and 5 stars. The more stars, the more positive the review.
  1. Set instructions to the following value:
If the developer didn't provide the number of stars, ask for the number of stars.
After the developer provides the number of stars of the review, confirm the number with the developer and use ${TOOL: review} to store the review with the number of stars.
If ${TOOL: review} fails, apologize and ask to try again later. Otherwise, thank the developer for the review.
  1. Click Save.

ebee7fdfa826b487.png

Test app

In the Google Cloud console, follow these steps:

  1. Click Menu ☰ > Agent builder > Apps.

  1. Select the Feedback App agent.
  2. Go to Preview agent.
  3. Under Agent, select Feedback collector.
  4. Under Select generative model, select gemini-pro.
  5. Send the message Hello! to start.

90ca8cb7b2c1cb4b.png

In the Google Cloud console, follow these steps:

  1. Click Menu ☰ > Cloud Functions.

  1. Select function-2 > Logs. Some logs show Google-Dialogflow as caller.

48bfdf1788004d18.png

Integrate Google Chat app

In the Dialogflow CX console, follow these steps:

  1. Select your Google Cloud project.
  2. Click the action menu of the Feedback App agent.
  3. Click Copy name.

In the Google Cloud console, follow these steps:

  1. Go to the Google Chat API configuration.

  1. Set Agent or Environment resource name to the agent name that you copied previously.

df16619a1cb85cf8.png

  • In Google Chat, send Hello! in a direct message to the Google Chat app to start. The agent responds similarly to your test from the Dialogflow CX console.

99a7a0295f122f31.png

11. Clean up

Delete Google Cloud project

To avoid incurring charges to your Google Cloud Account for the resources used in this codelab, we recommend that you delete the Google Cloud project.

In the Google Cloud console, follow these steps:

  1. Click Menu ☰ > IAM & Admin > Settings.

  1. Click Shut down.
  2. Enter the project ID.
  3. Click Shut down anyway.

407699a4e03afea6.png

Delete Apps Script project

We recommend that you delete your Apps Script project, too.

In the Apps Script console, follow these steps:

  1. Select your project.
  2. Click the action menu.
  3. Click Remove.

fa3a42d7d2201eb9.png

12. Congratulations

Congratulations! You built Google Chat apps with Gemini!

What's next?

We only showcased simple use cases in this codelab, but there are plenty of expansion areas that you might want to consider in your Google Chat apps, such as the following:

  • Integrate with other Generative AI models, including customs.
  • Support other types of media, such as audio, image, and video.
  • Use multimodality.
  • Rely on longer context windows and feedback loops.
  • Publish production-ready Google Chat apps on the marketplace. There are plenty of resources available for developers such as YouTube videos, documentation websites, code samples, and tutorials.
  • Enable Google Chat for your organization. The import mode feature makes it easier to get started.

Learn more