利用 Google Chat、Vertex AI 和 Apps Script 应对突发事件

本教程介绍了如何构建符合以下条件的 Google Chat 应用: 实时对突发事件做出响应。在响应突发事件时,应用 创建和填充 Chat 聊天室,助长突发事件 通过消息、斜杠命令和对话框解析问题,并使用 AI 总结 在 Google 文档文档中记录突发事件响应。

突发事件是指需要团队立即关注的事件 来解决这个问题。突发事件的示例包括:

  • 在客户关系管理 (CRM) 系统中创建一个具有时效性的案例 需要服务团队通力协作,共同找出一个解决方案。
  • 系统离线,向一组站点可靠性工程师 (SRE) 发出警报 这样他们就可以共同努力,使其恢复在线状态。
  • 发生高震级地震,应急工作者需要 协调他们的响应方式。

在本教程中,突发事件提醒会在有人 点击网页上的按钮来报告该事件。网页模拟 通过要求用户输入基本的突发事件信息(标题、 回复者的说明和电子邮件地址。

查看事件管理 Chat 应用的运行情况:

  • <ph type="x-smartling-placeholder">
    </ph> 引发突发事件的网站。
    图 1.可供他人举报事件的网站。
  • 关于已创建突发事件 Chat 聊天室的通知。
    图 2.说明已创建突发事件 Chat 聊天室的通知。
  • 突发事件响应的 Chat 聊天室。
    图 3.突发事件响应 Chat 聊天室。
  • 使用斜杠命令解决突发事件。
    图 4.使用斜杠命令解决突发事件。
  • 突发事件解决对话框。
    图 5.突发事件解决对话框。
  • 突发事件解决 Google 文档已在聊天室中共享。
    图 6.突发事件解决 Google 文档已在聊天室中共享。
  • AI 突发事件解决方案摘要 Google 文档。
    图 7.Google 文档中的 AI 突发事件解决摘要文档。

前提条件

如果您需要为组织启用以下任一前提条件,请询问 您的 Google Workspace 管理员来开启这些设置:

  • Business 或 Enterprise 有权访问以下内容的 Google Workspace 账号: Google Chat
  • 目录 已为 Google Workspace 启用(联系人共享)。突发事件应用使用 以便查询突发事件响应者的联系信息,如姓名 和电子邮件地址。突发事件响应者必须是使用 Google Chat 的用户 您的 Google Workspace 组织中的账号。

目标

  • 构建响应突发事件的 Chat 应用。
  • 通过执行以下操作,帮助用户对突发事件做出响应: <ph type="x-smartling-placeholder">
      </ph>
    • 创建突发事件响应空间。
    • 发布总结突发事件和响应的消息。
    • 通过互动功能支持协作 Chat 应用功能。
  • 使用 Vertex AI 总结对话和解决方案。

架构

下图显示了 Google Workspace 的架构和 突发事件响应使用的 Google Cloud 资源 Google Chat 应用。

突发事件响应 Google Chat 应用的架构

此架构展示了事件响应方式, Google Chat 应用会处理突发事件和解决方案。

  1. 用户从托管在 Apps 脚本。

  2. 该网站会向 同样托管在 Apps 脚本上的 Google Chat 应用。

  3. 突发事件响应 Google Chat 应用会处理该请求:

    1. Apps Script Admin SDK 服务获取团队成员 用户 ID 和电子邮件地址等信息。

    2. 使用 Apps 脚本高级聊天服务, 事件响应 Google Chat 应用创建突发事件 Chat 添加团队成员,并向该聊天室发送消息。

  4. 团队成员在 Chat 聊天室中讨论该事件。

  5. 一名团队成员调用正斜线命令,向 事件。

    1. 使用 Apps 脚本对 Chat API 进行 HTTP 调用 高级聊天服务会列出 创建聊天室消息

    2. Vertex AI 会收到列出的消息并生成摘要。

    3. Apps 脚本 DocumentApp 服务会创建 文档,并将 Vertex AI 的摘要添加到 文档。

    4. Google Chat 应用调用的突发事件响应 使用 Chat API 发送分享摘要链接的消息 Google 文档。

准备环境

本部分介绍如何为 Chat 应用。

创建 Google Cloud 项目

Google Cloud 控制台

  1. 在 Google Cloud 控制台中,点击“菜单”图标 &gt; IAM 和管理 &gt; 创建项目

    转到“创建项目”

  2. 项目名称字段中,为您的项目输入描述性名称。

    可选:要修改项目 ID,请点击修改。项目 ID 无法更改 创建项目后,请选择一个满足您需求的 ID 项目。

  3. 地理位置字段中,点击浏览以显示适合您的潜在地理位置 项目。然后,点击选择。 <ph type="x-smartling-placeholder">
  4. 点击创建。Google Cloud 控制台会转到“信息中心”页面,并且您的项目已创建完毕 就会出现这种问题

gcloud CLI

在以下某个开发环境中,访问 Google Cloud CLI (`gcloud`):

  • Cloud Shell:通过 gcloud CLI 使用在线终端 请激活 Cloud Shell。
    激活 Cloud Shell
  • Local Shell:如需使用本地开发环境, 安装初始化 gcloud CLI
    如需创建 Cloud 项目,请使用“gcloud projects create”命令:
    gcloud projects create PROJECT_ID
    通过设置要创建的项目的 ID 来替换 PROJECT_ID

为 Cloud 项目启用结算功能

<ph type="x-smartling-placeholder">

Google Cloud 控制台

  1. 在 Google Cloud 控制台中,前往结算。点击 菜单 &gt; 结算 &gt; 我的项目

    转到“我的项目的结算”

  2. 选择组织中,选择与 Google Cloud 项目。
  3. 在项目行中,打开操作菜单 (), 点击更改结算信息,然后选择 Cloud Billing 账号。
  4. 点击设置账号

gcloud CLI

  1. 如需列出可用的结算账号,请运行以下命令:
    gcloud billing accounts list
  2. 将结算账号与 Google Cloud 项目相关联:
    gcloud billing projects link PROJECT_ID --billing-account=BILLING_ACCOUNT_ID

    替换以下内容:

    • PROJECT_ID 您要为其启用结算功能的 Cloud 项目。
    • BILLING_ACCOUNT_ID 是要关联的结算账号 ID Google Cloud 项目。

启用 API

Google Cloud 控制台

  1. 在 Google Cloud 控制台中,启用 Google Chat API、Google 文档 API、 Admin SDK API 和 Vertex AI API。

    启用 API

  2. 确认您是在正确的 Cloud 项目,然后点击下一步

  3. 确认您启用的 API 正确无误,然后点击启用

gcloud CLI

  1. 如有必要,将当前 Cloud 项目设置为您创建的项目 替换为 gcloud config set project 命令:

    gcloud config set project PROJECT_ID
    

    PROJECT_ID 替换为项目 ID 您创建的 Cloud 项目。

  2. 启用 Google Chat API、Google 文档 API、Admin SDK API 和 Vertex AI API 替换为 gcloud services enable 命令:

    gcloud services enable chat.googleapis.com docs.googleapis.com admin.googleapis.com aiplatform.googleapis.com
    

设置身份验证和授权

身份验证和授权可让 Google Workspace 中的聊天应用访问权限资源,以及 Google Cloud 处理突发事件响应。

在本教程中,您将在内部发布应用,因此可以使用占位符 信息。对外发布应用之前,请先替换占位符 提供真实信息。

  1. 在 Google Cloud 控制台中,前往 菜单 &gt; API 和服务 &gt; OAuth 同意屏幕

    转到 OAuth 同意屏幕

  2. 用户类型下,选择内部,然后点击创建

  3. 应用名称中,输入 Incident Management

  4. 用户支持电子邮件中,选择您的电子邮件地址或相应的 Google 群组。

  5. 开发者联系信息下方,输入您的电子邮件地址。

  6. 点击保存并继续

  7. 点击添加或移除范围。此时会显示一个面板,其中包含范围列表 您在 Cloud 项目中启用的每个 API 的配额。

  8. 手动添加范围下方,粘贴以下范围:

    • https://www.googleapis.com/auth/chat.spaces.create
    • https://www.googleapis.com/auth/chat.memberships
    • https://www.googleapis.com/auth/chat.memberships.app
    • https://www.googleapis.com/auth/chat.messages
    • https://www.googleapis.com/auth/documents
    • https://www.googleapis.com/auth/admin.directory.user.readonly
    • https://www.googleapis.com/auth/script.external_request
    • https://www.googleapis.com/auth/userinfo.email
    • https://www.googleapis.com/auth/cloud-platform
  9. 点击 Add to Table

  10. 点击更新

  11. 点击保存并继续

  12. 查看应用注册摘要,然后点击返回信息中心

创建和部署 Chat 扩展应用

在下一部分,您将复制并更新整个 包含所有必需应用的 Apps 脚本项目 因此无需复制 粘贴每个文件。

有些函数的名称末尾会包含下划线,例如 来自ChatApp.gsprocessSlashCommand_()。函数会用下划线隐藏 。有关 请参阅 私有函数

Apps 脚本支持两种文件类型:.gs 脚本和 .html 文件。为了遵守这项支持,我们提供了应用的客户端 JavaScript 位于 <script /> 标记内,且其 CSS 包含在 <style /> 标记内 HTML 文件。

或者,您也可以在 GitHub 上查看整个项目。

在 GitHub 上查看

以下是对每个文件的概述:

Consts.gs

定义其他代码文件引用的常量, 包括您的 Cloud 项目 ID、Vertex AI 位置 ID 以及 用于关闭突发事件的斜杠命令 ID。

查看 Consts.gs 个代码

apps-script/incident-response/Consts.gs
const PROJECT_ID = 'replace-with-your-project-id';
const VERTEX_AI_LOCATION_ID = 'us-central1';
const CLOSE_INCIDENT_COMMAND_ID = 1;
ChatApp.gs

处理 Chat 互动事件,包括 消息、卡片点击、斜杠命令和对话框。响应 通过打开对话框收集突发事件 /closeIncident 斜杠命令 分辨率详细信息。通过调用 spaces.messages.list 方法。 使用 Admin SDK Directory 服务获取 User-ID Apps 脚本。

查看 ChatApp.gs 个代码

apps-script/incident-response/ChatApp.gs
/**
 * Responds to a MESSAGE event in Google Chat.
 *
 * This app only responds to a slash command with the ID 1 ("/closeIncident").
 * It will respond to any other message with a simple "Hello" text message.
 *
 * @param {Object} event the event object from Google Chat
 */
function onMessage(event) {
  if (event.message.slashCommand) {
    return processSlashCommand_(event);
  }
  return { "text": "Hello from Incident Response app!" };
}

/**
 * Responds to a CARD_CLICKED event in Google Chat.
 *
 * This app only responds to one kind of dialog (Close Incident).
 *
 * @param {Object} event the event object from Google Chat
 */
function onCardClick(event) {
  if (event.isDialogEvent) {
    if (event.dialogEventType == 'SUBMIT_DIALOG') {
      return processSubmitDialog_(event);
    }
    return {
      actionResponse: {
        type: "DIALOG",
        dialogAction: {
          actionStatus: "OK"
        }
      }
    };
  }
}

/**
 * Responds to a MESSAGE event with a Slash command in Google Chat.
 *
 * This app only responds to a slash command with the ID 1 ("/closeIncident")
 * by returning a Dialog.
 *
 * @param {Object} event the event object from Google Chat
 */
function processSlashCommand_(event) {
  if (event.message.slashCommand.commandId != CLOSE_INCIDENT_COMMAND_ID) {
    return {
      "text": "Command not recognized. Use the command `/closeIncident` to close the incident managed by this space."
    };
  }
  const sections = [
    {
      header: "Close Incident",
      widgets: [
        {
          textInput: {
            label: "Please describe the incident resolution",
            type: "MULTIPLE_LINE",
            name: "description"
          }
        },
        {
          buttonList: {
            buttons: [
              {
                text: "Close Incident",
                onClick: {
                  action: {
                    function: "closeIncident"
                  }
                }
              }
            ]
          }
        }
      ]
    }
  ];
  return {
    actionResponse: {
      type: "DIALOG",
      dialogAction: {
        dialog: {
          body: {
            sections,
          }
        }
      }
    }
  };
}

/**
 * Responds to a CARD_CLICKED event with a Dialog submission in Google Chat.
 *
 * This app only responds to one kind of dialog (Close Incident).
 * It creates a Doc with a summary of the incident information and posts a message
 * to the space with a link to the Doc.
 *
 * @param {Object} event the event object from Google Chat
 */
function processSubmitDialog_(event) {
  const resolution = event.common.formInputs.description[""].stringInputs.value[0];
  const chatHistory = concatenateAllSpaceMessages_(event.space.name);
  const chatSummary = summarizeChatHistory_(chatHistory);
  const docUrl = createDoc_(event.space.displayName, resolution, chatHistory, chatSummary);
  return {
    actionResponse: {
      type: "NEW_MESSAGE",
    },
    text: `Incident closed with the following resolution: ${resolution}\n\nHere is the automatically generated post-mortem:\n${docUrl}`
  };
}

/**
 * Lists all the messages in the Chat space, then concatenate all of them into
 * a single text containing the full Chat history.
 *
 * For simplicity for this demo, it only fetches the first 100 messages.
 *
 * Messages with slash commands are filtered out, so the returned history will
 * contain only the conversations between users and not app command invocations.
 *
 * @return {string} a text containing all the messages in the space in the format:
 *          Sender's name: Message
 */
function concatenateAllSpaceMessages_(spaceName) {
  // Call Chat API method spaces.messages.list
  const response = Chat.Spaces.Messages.list(spaceName, { 'pageSize': 100 });
  const messages = response.messages;
  // Fetch the display names of the message senders and returns a text
  // concatenating all the messages.
  let userMap = new Map();
  return messages
    .filter(message => message.slashCommand === undefined)
    .map(message => `${getUserDisplayName_(userMap, message.sender.name)}: ${message.text}`)
    .join('\n');
}

/**
 * Obtains the display name of a user by using the Admin Directory API.
 *
 * The fetched display name is cached in the provided map, so we only call the API
 * once per user.
 *
 * If the user does not have a display name, then the full name is used.
 *
 * @param {Map} userMap a map containing the display names previously fetched
 * @param {string} userName the resource name of the user
 * @return {string} the user's display name
 */
function getUserDisplayName_(userMap, userName) {
  if (userMap.has(userName)) {
    return userMap.get(userName);
  }
  let displayName = 'Unknown User';
  try {
    const user = AdminDirectory.Users.get(
      userName.replace("users/", ""),
      { projection: 'BASIC', viewType: 'domain_public' });
    displayName = user.name.displayName ? user.name.displayName : user.name.fullName;
  } catch (e) {
    // Ignore error if the API call fails (for example, because it's an
    // out-of-domain user or Chat app)) and just use 'Unknown User'.
  }
  userMap.set(userName, displayName);
  return displayName;
}
ChatSpaceCreator.gs

接收用户在突发事件中输入的表单数据 初始化网页,并用它来设置 Chat 来创建和填充聊天室,然后发布一条消息 事件。

查看 ChatSpaceCreator.gs 个代码

apps-script/incident-response/ChatSpaceCreator.gs
/**
 * Creates a space in Google Chat with the provided title and members, and posts an
 * initial message to it.
 *
 * @param {Object} formData the data submitted by the user. It should contain the fields
 *                          title, description, and users.
 * @return {string} the resource name of the new space.
 */
function createChatSpace(formData) {
  const users = formData.users.trim().length > 0 ? formData.users.split(',') : [];
  const spaceName = setUpSpace_(formData.title, users);
  addAppToSpace_(spaceName);
  createMessage_(spaceName, formData.description);
  return spaceName;
}

/**
 * Creates a space in Google Chat with the provided display name and members.
 *
 * @return {string} the resource name of the new space.
 */
function setUpSpace_(displayName, users) {
  const memberships = users.map(email => ({
    member: {
      name: `users/${email}`,
      type: "HUMAN"
    }
  }));
  const request = {
    space: {
      displayName: displayName,
      spaceType: "SPACE",
      externalUserAllowed: true
    },
    memberships: memberships
  };
  // Call Chat API method spaces.setup
  const space = Chat.Spaces.setup(request);
  return space.name;
}

/**
 * Adds this Chat app to the space.
 *
 * @return {string} the resource name of the new membership.
 */
function addAppToSpace_(spaceName) {
  const request = {
    member: {
      name: "users/app",
      type: "BOT"
    }
  };
  // Call Chat API method spaces.members.create
  const membership = Chat.Spaces.Members.create(request, spaceName);
  return membership.name;
}

/**
 * Posts a text message to the space on behalf of the user.
 *
 * @return {string} the resource name of the new message.
 */
function createMessage_(spaceName, text) {
  const request = {
    text: text
  };
  // Call Chat API method spaces.messages.create
  const message = Chat.Spaces.Messages.create(request, spaceName);
  return message.name;
}
DocsApi.gs

调用 Google 文档 API 以在 用户的 Google 云端硬盘,并撰写事件信息摘要, (在 VertexAiApi.gs 中创建)到文档。

查看 DocsApi.gs 个代码

apps-script/incident-response/DocsApi.gs
/**
 * Creates a Doc in the user's Google Drive and writes a summary of the incident information to it.
 *
 * @param {string} title The title of the incident
 * @param {string} resolution Incident resolution described by the user
 * @param {string} chatHistory The whole Chat history be included in the document
 * @param {string} chatSummary A summary of the Chat conversation to be included in the document
 * @return {string} the URL of the created Doc
 */
function createDoc_(title, resolution, chatHistory, chatSummary) {
  let doc = DocumentApp.create(title);
  let body = doc.getBody();
  body.appendParagraph(`Post-Mortem: ${title}`).setHeading(DocumentApp.ParagraphHeading.TITLE);
  body.appendParagraph("Resolution").setHeading(DocumentApp.ParagraphHeading.HEADING1);
  body.appendParagraph(resolution);
  body.appendParagraph("Summary of the conversation").setHeading(DocumentApp.ParagraphHeading.HEADING1);
  body.appendParagraph(chatSummary);
  body.appendParagraph("Full Chat history").setHeading(DocumentApp.ParagraphHeading.HEADING1);
  body.appendParagraph(chatHistory);
  return doc.getUrl();
}
VertexAiApi.gs

总结 Chat 中的对话 进行训练。此摘要发布在专门创建的 DocsAPI.gs 中的文档。

查看 VertexAiApi.gs 个代码

apps-script/incident-response/VertexAiApi.gs
/**
 * Summarizes a Chat conversation using the Vertex AI text prediction API.
 *
 * @param {string} chatHistory The Chat history that will be summarized.
 * @return {string} The content from the text prediction response.
 */
function summarizeChatHistory_(chatHistory) {
  const prompt =
    "Summarize the following conversation between Engineers resolving an incident"
      + " in a few sentences. Use only the information from the conversation.\n\n"
      + chatHistory;
  const request = {
    instances: [
      { prompt: prompt }
    ],
    parameters: {
      temperature: 0.2,
      maxOutputTokens: 256,
      topK: 40,
      topP: 0.95
    }
  }
  const fetchOptions = {
    method: 'POST',
    headers: { Authorization: 'Bearer ' + ScriptApp.getOAuthToken() },
    contentType: 'application/json',
    payload: JSON.stringify(request)
  }
  const response = UrlFetchApp.fetch(
    `https://${VERTEX_AI_LOCATION_ID}-aiplatform.googleapis.com/v1`
      + `/projects/${PROJECT_ID}/locations/${VERTEX_AI_LOCATION_ID}`
      + "/publishers/google/models/text-bison:predict",
    fetchOptions);
  const payload = JSON.parse(response.getContentText());
  return payload.predictions[0].content;
}
WebController.gs

提供突发事件初始化网站。

查看 WebController.gs 个代码

apps-script/incident-response/WebController.gs
/**
 * Serves the web page from Index.html.
 */
function doGet() {
  return HtmlService
    .createTemplateFromFile('Index')
    .evaluate();
}

/**
 * Serves the web content from the specified filename.
 */
function include(filename) {
  return HtmlService
    .createHtmlOutputFromFile(filename)
    .getContent();
}

/**
 * Returns the email address of the user running the script.
 */
function getUserEmail() {
  return Session.getActiveUser().getEmail();
}
Index.html

包含事件初始化网站的 HTML。

查看 Index.html 个代码

apps-script/incident-response/Index.html
<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet'>
    <?!= include('Stylesheet'); ?>
  </head>
  <body>
    <div class="container">
      <div class="content">
        <h1>Incident Manager</h1>
        <form id="incident-form" onsubmit="handleFormSubmit(this)">
          <div id="form">
            <p>
              <label for="title">Incident title</label><br/>
              <input type="text" name="title" id="title" />
            </p>
            <p>
              <label for="users">Incident responders</label><br/>
              <small>
                Please enter a comma-separated list of email addresses of the users
                that should be added to the space.
                Do not include <?= getUserEmail() ?> as it will be added automatically.
              </small><br/>
              <input type="text" name="users" id="users" />
            </p>
            <p>
              <label for="description">Initial message</label></br>
              <small>This message will be posted after the space is created.</small><br/>
              <textarea name="description" id="description"></textarea>
            </p>
            <p class="text-center">
              <input type="submit" value="CREATE CHAT SPACE" />
            </p>
          </div>
          <div id="output" class="hidden"></div>
          <div id="clear" class="hidden">
            <input type="reset" value="CREATE ANOTHER INCIDENT" onclick="onReset()" />
          </div>
        </form>
      </div>
    </div>
    <?!= include('JavaScript'); ?>
  </body>
</html>
JavaScript.html

处理表单行为,包括提交、 事件初始化网站上的错误和清除信息已包含 由 WebController.gs 中的自定义 include 函数转换为 Index.html

查看 JavaScript.html 个代码

apps-script/incident-response/JavaScript.html
<script>
  var formDiv = document.getElementById('form');
  var outputDiv = document.getElementById('output');
  var clearDiv = document.getElementById('clear');

  function handleFormSubmit(formObject) {
    event.preventDefault();
    outputDiv.innerHTML = 'Please wait while we create the space...';
    hide(formDiv);
    show(outputDiv);
    google.script.run
      .withSuccessHandler(updateOutput)
      .withFailureHandler(onFailure)
      .createChatSpace(formObject);
  }

  function updateOutput(response) {
    var spaceId = response.replace('spaces/', '');
    outputDiv.innerHTML =
      '<p>Space created!</p><p><a href="https://mail.google.com/chat/#chat/space/'
        + spaceId
        + '" target="_blank">Open space</a></p>';
    show(outputDiv);
    show(clearDiv);
  }

  function onFailure(error) {
    outputDiv.innerHTML = 'ERROR: ' + error.message;
    outputDiv.classList.add('error');
    show(outputDiv);
    show(clearDiv);
  }

  function onReset() {
    outputDiv.innerHTML = '';
    outputDiv.classList.remove('error');
    show(formDiv);
    hide(outputDiv);
    hide(clearDiv);
  }

  function hide(element) {
    element.classList.add('hidden');
  }

  function show(element) {
    element.classList.remove('hidden');
  }
</script>
Stylesheet.html

突发事件初始化网站的 CSS。时间是 由自定义 include 函数添加到 Index.htmlWebController.gs

查看 Stylesheet.html 个代码

apps-script/incident-response/Stylesheet.html
<style>
  * {
    box-sizing: border-box;
  }
  body {
    font-family: Roboto, Arial, Helvetica, sans-serif;
  }
  div.container {
    display: flex;
    justify-content: center;
    align-items: center;
    position: absolute;
    top: 0; bottom: 0; left: 0; right: 0;
  }
  div.content {
    width: 80%;
    max-width: 1000px;
    padding: 1rem;
    border: 1px solid #999;
    border-radius: 0.25rem;
    box-shadow: 0 2px 2px 0 rgba(66, 66, 66, 0.08), 0 2px 4px 2px rgba(66, 66, 66, 0.16);
  }
  h1 {
    text-align: center;
    padding-bottom: 1rem;
    margin: 0 -1rem 1rem -1rem;
    border-bottom: 1px solid #999;
  }
 #output {
    text-align: center;
    min-height: 250px;
  }
  div#clear {
    text-align: center;
    padding-top: 1rem;
    margin: 1rem -1rem 0 -1rem;
    border-top: 1px solid #999;
  }
  input[type=text], textarea {
    width: 100%;
    padding: 1rem 0.5rem;
    margin: 0.5rem 0;
    border: 0;
    border-bottom: 1px solid #999;
    background-color: #f0f0f0;
  }
  textarea {
    height: 5rem;
  }
  small {
    color: #999;
  }
  input[type=submit], input[type=reset] {
    padding: 1rem;
    border: none;
    background-color: #6200ee;
    color: #fff;
    border-radius: 0.25rem;
    width: 25%;
  }
  .hidden {
    display: none;
  }
  .text-center {
    text-align: center;
  }
  .error {
    color: red;
  }
</style>

查找您的 Cloud 项目编号和 ID

  1. 在 Google Cloud 控制台中,前往您的 Cloud 项目。

    转到 Google Cloud 控制台

  2. 点击 设置和实用程序 &gt; 项目设置

  3. 记下项目编号项目 ID 字段中的值。您 请在以下各部分中使用它们。

创建 Apps 脚本项目

要创建 Apps 脚本项目并将其与您的 Cloud 项目:

  1. 点击以下按钮,打开 Reply toidents with Google Chat Apps Script 项目。
    打开项目
  2. 点击 概览
  3. 在概览页面上,点击 用于制作副本的图标 复制
  4. 为 Apps 脚本项目副本命名:

    1. 点击“通过 Google Chat 响应突发事件”的副本

    2. 项目标题中,输入 Incident Management Chat app

    3. 点击重命名

  5. 在您的 Apps 脚本项目副本中,前往 Consts.gs 并将 YOUR_PROJECT_ID 替换为您的 Cloud 项目中。

设置 Apps 脚本项目的 Cloud 项目

  1. 在您的 Apps 脚本项目中, 点击 项目设置的图标 项目设置
  2. Google Cloud Platform (GCP) 项目下,点击更改项目
  3. GCP 项目编号中,粘贴您的 Cloud 项目的项目编号。
  4. 点击设置项目。Cloud 项目和 Apps 脚本 项目现已连接。

创建 Apps 脚本部署

现在所有代码都已设置妥当,接下来部署 Apps 脚本 项目。您在配置 Google Cloud 中的聊天应用。

  1. 在 Apps 脚本中,打开突发事件响应应用的项目。

    前往 Apps 脚本

  2. 点击部署 >新建部署

  3. 如果尚未选择插件Web 应用选择类型,点击部署类型 项目设置的图标,然后选择插件 Web 应用

  4. 说明中,输入此版本的说明,例如 Complete version of incident management app

  5. 执行方式中,选择用户访问 Web 应用

  6. 有权使用的人部分,选择您 Workspace 组织中的任何人。 其中,“您的 Workspace 组织”是你的 Google Workspace 组织。

  7. 点击部署。Apps 脚本报告成功 Deployment ID,并提供相应突发事件的部署 ID 和网址 初始化网页。

  8. 记下 Web 应用网址,以便稍后在启动突发事件时访问。 复制部署 ID。您在配置 Google Cloud 控制台中的聊天应用。

  9. 点击完成

在 Google Cloud 控制台中配置 Chat 应用

本部分介绍如何在 Google Cloud 控制台中配置 Google Chat API 其中包含有关您的 Chat 应用的信息,包括 您刚刚通过 Apps 脚本创建的部署的 ID 项目。

  1. 在 Google Cloud 控制台中,点击菜单 &gt; 更多产品 &gt; Google Workspace &gt; 产品库 &gt; Google Chat API &gt; 管理 &gt; 配置

    前往 Chat API 配置

  2. 应用名称中,输入 Incident Management

  3. 头像网址中输入 https://developers.google.com/chat/images/quickstart-app-avatar.png

  4. 说明中,输入 Responds to incidents.

  5. 点击启用互动功能开关,将其切换到“开启”位置。

  6. 功能下方,依次选择接收 1 对 1 消息加入聊天室和群组对话

  7. 连接设置下,选择 Apps 脚本项目

  8. 部署 ID 中,粘贴 Apps 脚本部署 ID 之前从 Apps 脚本项目复制的 部署。

  9. 注册一个斜杠命令,以便 全面实现的 Chat 应用:

    1. 斜杠命令下,点击添加斜杠命令

    2. 名称中,输入 /closeIncident

    3. 命令 ID 中,输入 1

    4. 说明中,输入 Closes the incident being discussed in the space.

    5. 选择打开对话框

    6. 点击完成。系统会注册并列出斜杠命令。

  10. 公开范围下,选择 将此聊天应用设为允许特定用户和群组使用 Workspace 网域,然后输入您的电子邮件地址。

  11. 日志下,选择将错误记录到 Logging

  12. 点击保存。系统会显示一条配置已保存的消息,表明应用 测试。

测试 Chat 应用

如需测试突发事件管理 Chat 应用,请发起 从网页中发起突发事件,并验证 Chat 应用 按预期运行:

  1. 前往 Apps 脚本部署 Web 应用网址。

  2. 当 Apps 脚本请求访问您的数据时, 点击查看权限,使用相应的 Google 账号登录 ,然后点击 Allow(允许)。

  3. 系统会打开突发事件初始化网页。输入测试信息:

    1. 突发事件标题中,输入 The First Incident
    2. (可选)在突发事件响应者中,输入 其他事件响应者这些用户必须是 您的 Google Workspace 组织中的 Google Chat 账号,或 创建聊天室失败。请勿输入您自己的电子邮件地址,因为 自动包含。
    3. 初始消息中,输入 Testing the incident management Chat app.
  4. 点击创建 Chat 聊天室。系统会显示 creating space 消息。

  5. 创建聊天室后,系统会显示 Space created! 消息。点击 打开聊天室:系统会在新标签页中打开 Chat 中的聊天室。

  6. (可选)您和其他突发事件响应者可以在 空间。该应用使用 Vertex AI 总结这些消息,并分享 回顾文档。

  7. 如需结束突发事件响应并开始解决流程,请在 Chat 聊天室,输入“/closeIncident”。突发事件管理 对话框。

  8. 关闭突发事件中,输入突发事件解决方案的说明。 例如Test complete

  9. 点击 Close Incident(关闭突发事件)。

Incident Management 应用会列出聊天室中的消息,并进行总结。 将摘要粘贴到 Google 文档中,然后分享 文档。

清理

为避免系统因 我们建议您删除 Cloud 项目中。

  1. 在 Google Cloud 控制台中,前往管理资源页面。点击 菜单 &gt; IAM 和管理员 &gt; 管理资源

    <ph type="x-smartling-placeholder"></ph> 前往 Resource Manager

  2. 在项目列表中,选择要删除的项目,然后点击 删除
  3. 在对话框中输入项目 ID,然后点击关停以删除项目 项目。