מענה לתקריות שימוש ב-Google Chat, ב-Vertex AI וב-Apps Script

במדריך הזה תלמדו איך ליצור אפליקציית Google Chat מגיבים לאירועים בזמן אמת. כשמגיבים לאירוע, האפליקציה יוצר ומאכלס מרחב ב-Chat, שמאפשר אירוע של הודעות, פקודות ותיבות דו-שיח, ומשתמשת ב-AI כדי לסכם על התגובה לאירוע במסמך Google Docs.

אירוע הוא אירוע שמחייב טיפול מיידי של צוות. של אנשים לפתור. דוגמאות לאירועים:

  • בקשת תמיכה תלוית זמן נוצרת במערכת לניהול קשרי לקוחות (CRM) כך שצוות השירות צריך לשתף פעולה כדי להגיע לפתרון.
  • מערכת עוברת למצב אופליין ומתריעה לקבוצה של מהנדסי Site Reliability (SRE) כדי שיוכלו לפעול יחד כדי להחזיר אותו לאינטרנט.
  • מתרחשת רעידת אדמה בעוצמה גבוהה, ועובדי שירותי החירום צריכים כדי לתאם את התגובה שלהם.

למטרות המדריך הזה, ההתראה על אירוע מתחילה כשמישהו מדווח על התקרית בלחיצה על לחצן מדף אינטרנט. דף האינטרנט מדמה פרטי האירוע צריכים להזין את הפרטים הבסיסיים של האירוע: כותרת, וכתובות האימייל של המשיבים.

רוצה לראות את אפליקציית Chat לניהול אירועים?

  • האתר שבו מתחיל האירוע.
    איור 1. האתר שבו אפשר לדווח על אירוע.
  • התראה על כך שנוצר מרחב משותף ב-Chat.
    איור 2. התראה על כך שנוצר מרחב משותף ב-Chat.
  • המרחב ב-Chat של התגובה לאירוע.
    איור 3. המרחב ב-Chat של התגובה לאירוע.
  • פתרון התקרית באמצעות פקודת קו נטוי.
    איור 4. פתרון התקרית באמצעות פקודת קו נטוי.
  • תיבת דו-שיח לפתרון האירוע.
    איור 5. תיבת דו-שיח לפתרון התקרית.
  • מסמך Google Docs של Google Docs משותף במרחב המשותף.
    איור 6. מסמך Google Docs של Google Docs משותף במרחב.
  • סיכום האירוע של האירוע שנוצר על ידי AI ב-Google Docs.
    איור 7. מסמך ב-Google Docs של סיכום האירוע על ידי AI.

דרישות מוקדמות

אם צריך להפעיל בארגון את הדרישות המוקדמות האלה, עליך לבקש כדי שהאדמין ב-Google Workspace יפעיל אותם:

  • עסק או ארגון חשבון Google Workspace עם גישה אל Google Chat.
  • כדי ספרייה (שיתוף אנשי קשר) מופעל ב-Google Workspace. אפליקציית האירוע משתמשת את הספרייה כדי לחפש את המגיבים פרטים ליצירת קשר, כמו שם וכתובת אימייל. המשיבים חייבים להיות משתמשים עם צ'אט של Google Chat חשבון Google Workspace של הארגון.

מטרות

  • לפתח אפליקציה ל-Chat שמגיבה לתקריות.
  • כדי לעזור למשתמשים להגיב לאירועים, צריך לבצע את הפעולות הבאות:
    • יצירת מרחבי תגובה לתקריות.
    • פרסום הודעות עם סיכום של אירועים ותגובות.
    • תמיכה בשיתוף פעולה עם כלים אינטראקטיביים התכונות של אפליקציית Chat.
  • סיכום שיחות ופתרונות באמצעות Vertex AI.

ארכיטקטורה

בתרשים הבא מוצגת הארכיטקטורה של Google Workspace המשאבים של Google Cloud שמשמשים את התגובה לאירוע אפליקציית Google Chat.

הארכיטקטורה של אפליקציית Google Chat בתגובה לאירוע

בארכיטקטורה אפשר לראות איך התגובה לאירוע אפליקציית Google Chat מעבדת את האירוע ואת הפתרון שלו.

  1. משתמש מתחיל אירוע מאתר חיצוני שמתארח ב- Apps Script.

  2. האתר שולח בקשת HTTP אסינכרונית אל אפליקציית Google Chat, גם מתארחת ב-Apps Script.

  3. התגובה לאירוע Google Chat מעבדת את הבקשה:

    1. שירות Apps Script Admin SDK מקבל חבר צוות מידע כמו מזהה משתמש וכתובת אימייל.

    2. באמצעות קבוצה של בקשות HTTP ל-Chat API באמצעות שירות צ'אט מתקדם של Apps Script, התגובה לאירוע אפליקציית Google Chat יוצרת אירוע ב-Chat יאכלס אותו בחברי הצוות ושולח הודעה למרחב המשותף.

  4. חברי הצוות מדברים על האירוע במרחב המשותף ב-Chat.

  5. חבר צוות מפעיל פקודת לוכסן כדי לסמן שיש פתרון נוסף לתקרית.

    1. קריאת HTTP ל-Chat API באמצעות Apps Script שירות Chat מתקדם מציג את כל רשימות הצ'אט הודעות במרחב המשותף.

    2. Vertex AI מקבל את ההודעות שברשימה ויוצר סיכום.

    3. שירות Apps Script DocumentApp יוצר ב-Docs ומוסיף את הסיכום של Vertex AI מהמסמך.

    4. התגובות לשיחות באפליקציית Google Chat Chat API לשליחת הודעה עם קישור לסיכום ב-Docs.

מכינים את הסביבה

בקטע הזה נסביר איך ליצור ולהגדיר פרויקט ב-Google Cloud עבור אפליקציית Chat.

יצירת פרויקט של Google Cloud

מסוף Google Cloud

  1. במסוף Google Cloud, נכנסים לתפריט > IAM & אדמין > יצירת פרויקט.

    כניסה לדף Create a Project

  2. בשדה Project Name (שם הפרויקט), מזינים שם תיאורי לפרויקט.

    אופציונלי: כדי לערוך את Project ID, לוחצים על Edit (עריכה). לא ניתן לשנות את מזהה הפרויקט אחרי שהפרויקט נוצר, לכן בחר מזהה שעונה על הצרכים שלך לכל משך החיים של הפרויקט פרויקט.

  3. בשדה מיקום לוחצים על עיון כדי להציג את המיקומים האפשריים של פרויקט. לאחר מכן לוחצים על בחירה.
  4. לוחצים על יצירה. במסוף Google Cloud עוברים לדף Dashboard ונוצר הפרויקט תוך כמה דקות.

CLI של gcloud

נכנסים ל-Google Cloud באחת מסביבות הפיתוח הבאות CLI (`gcloud`):

  • Cloud Shell: כדי להשתמש בטרמינל אונליין באמצעות ה-CLI של gcloud כבר הוגדר, צריך להפעיל את Cloud Shell.
    הפעלת Cloud Shell
  • Local Shell: כדי להשתמש בסביבת פיתוח מקומית, התקנה ו אתחול ב-CLI של gcloud.
    כדי ליצור פרויקט ב-Cloud, משתמשים בפקודה 'gcloud projects create':
    gcloud projects create PROJECT_ID
    מחליפים את PROJECT_ID על ידי הגדרת המזהה של הפרויקט שרוצים ליצור.

הפעלת החיוב בפרויקט ב-Cloud

מסוף Google Cloud

  1. נכנסים לקטע Billing במסוף Google Cloud. לוחצים על תפריט > חיוב > הפרויקטים שלי.

    לדף Billing for My Projects

  2. בקטע בחירת ארגון, בוחרים את הארגון שמשויך אליו. את הפרויקט ב-Google Cloud.
  3. בשורת הפרויקט, פותחים את התפריט Actions (פעולות) (), לוחצים על שינוי החיוב ובוחרים לחשבון לחיוב ב-Cloud.
  4. לוחצים על Set account.

CLI של gcloud

  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 הוא מזהה החשבון לחיוב שאליו יש לקשר בפרויקט ב-Google Cloud.

הפעלת ממשקי ה-API

מסוף Google Cloud

  1. במסוף Google Cloud, מפעילים את Google Chat API, את Google Docs API, Admin SDK API ו-Vertex AI API.

    הפעלת ממשקי ה-API

  2. עליכם לוודא שאתם מפעילים את ממשקי ה-API פרויקט ב-Cloud ולוחצים על Next.

  3. מוודאים שאתם מפעילים את ממשקי ה-API הנכונים ולוחצים על הפעלה.

CLI של gcloud

  1. אם צריך, מגדירים את הפרויקט הנוכחי ב-Cloud לפרויקט שיצרתם באמצעות הפקודה gcloud config set project:

    gcloud config set project PROJECT_ID
    

    מחליפים את PROJECT_ID במזהה הפרויקט של הפרויקט ב-Cloud שיצרתם.

  2. הפעלה של Google Chat API, Google Docs 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
    

הגדרת אימות והרשאה

האימות וההרשאה מאפשרים משאבי גישה לאפליקציות Chat ב-Google Workspace Google Cloud לעיבוד התגובה לאירוע.

במדריך הזה נפרסם את האפליקציה באופן פנימי, ולכן מותר להשתמש ב-placeholder מידע. לפני פרסום האפליקציה באופן חיצוני, צריך להחליף את ה-placeholder עם מידע אמיתי למסך ההסכמה.

  1. במסוף Google Cloud, נכנסים אל תפריט > ממשקי API ו- שירותים > מסך ההסכמה של OAuth

    מעבר למסך ההסכמה ל-OAuth

  2. בקטע סוג משתמש, בוחרים באפשרות פנימי ולוחצים על יצירה.

  3. בשדה App name, מקלידים Incident Management.

  4. בקטע User support email (אימייל לתמיכת משתמשים), בוחרים את כתובת האימייל שלכם או כתובת אחרת קבוצה ב-Google.

  5. בקטע פרטים ליצירת קשר עם המפתח, מזינים את כתובת האימייל.

  6. לוחצים על שמירה והמשך.

  7. לוחצים על הוספה או הסרה של היקפי הרשאות. תופיע חלונית עם רשימה של היקפים לכל API שהפעלתם בפרויקט ב-Cloud.

  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. לוחצים על הוספה לטבלה.

  10. לוחצים על עדכון.

  11. לוחצים על שמירה והמשך.

  12. מעיינים בסיכום הרישום של האפליקציה ולוחצים על חזרה למרכז השליטה.

יצירה ופריסה של אפליקציית Chat

בקטע הבא מעתיקים ומעדכנים חשבון שלם פרויקט Apps Script שמכיל את כל האפליקציה הנדרשת לאפליקציה ל-Chat, כך שלא צריך להעתיק מדביקים כל קובץ.

פונקציות מסוימות כוללות קווים תחתונים בסוף השמות, למשל processSlashCommand_() מ-ChatApp.gs. הקו התחתון מסתיר את הפונקציה מדף האינטרנט של אתחול האירוע כשהוא פתוח בדפדפן. לקבלת מידע נוסף מידע נוסף, ראה פונקציות פרטיות.

ב-Apps Script יש תמיכה בשני סוגי קבצים: .gs סקריפטים ו-.html . כדי לציית לתמיכה הזו, ה-JavaScript בצד הלקוח כלול באפליקציה בתוך תגי <script /> וה-CSS שלו כלול בתוך תגי <style /> שבתוכו בקובץ HTML.

לחלופין, אפשר להציג את הפרויקט כולו ב-GitHub.

הצגת הקוד ב-GitHub

לפניכם סקירה כללית של כל אחד מהקבצים:

Consts.gs

מגדיר קבועים שקובצי קוד אחרים מפנים אליהם, כולל מזהה הפרויקט ב-Cloud, מזהה המיקום ב-Vertex AI מזהה הפקודה לסגירת אירוע.

הצגת הקוד מהאפליקציה 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 מאפשרת לפתוח תיבת דו-שיח לאיסוף אירוע פרטי הרזולוציה. רוצה לקרוא את ההודעות במרחב המשותף? ה-method spaces.messages.list ב-Chat API. מקבל מזהי משתמשים באמצעות השירות Admin SDK Directory ב- Apps Script.

הצגת הקוד מהאפליקציה 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

מקבלים את נתוני הטופס שהמשתמשים מזינים באירוע של דף האינטרנט החדש, ומשתמשת בו כדי להגדיר צ'אט. ליצור ואכלס אותו, ולאחר מכן לפרסם הודעה לגבי נוסף לתקרית.

הצגת הקוד מהאפליקציה 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 Docs API כדי ליצור מסמך Google Docs משתמש Google Drive של המשתמש וכותב סיכום של פרטי האירוע, נוצר ב-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 באמצעות Vertex AI. הסיכום הזה מפורסם בקובץ שנוצר במיוחד במסמך 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

טיפול בהתנהגות הטפסים, כולל שליחות, וכל השגיאות באתר של אתחול התקרית. כלולה בתוך Index.html באמצעות הפונקציה include בהתאמה אישית בפונקציה WebController.gs.

הצגת הקוד מהאפליקציה 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 של האתר לאתחול התקרית. זו נכללים בתוך Index.html על ידי הפונקציה include בהתאמה אישית במסגרת WebController.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 והמזהה שלו

  1. במסוף Google Cloud, נכנסים לפרויקט ב-Cloud.

    כניסה למסוף Google Cloud

  2. לוחצים על 'הגדרות ותוכניות שירות'. &gt; הגדרות הפרויקט.

  3. שימו לב לערכים בשדות Project number ו-Project ID. שלך להשתמש בהם בקטעים הבאים.

יצירת פרויקט Apps Script

כדי ליצור פרויקט ב-Apps Script ולחבר אותו אל פרויקט ב-Cloud:

  1. לוחצים על הלחצן הבא כדי לפתוח את הפרויקט מענה לאירועים באמצעות Google Chat ב-Apps Script.
    פתיחת הפרויקט
  2. לוחצים על סקירה כללית.
  3. בדף הסקירה הכללית לוחצים על הסמל של יצירת עותק יצירת עותק.
  4. נותנים שם לעותק של פרויקט Apps Script:

    1. לוחצים על עותק של התשובה לאירועים באמצעות Google Chat.

    2. בשדה Project title, מקלידים Incident Management Chat app.

    3. לוחצים על Rename.

  5. בעותק של פרויקט Apps Script, עוברים אל Consts.gs ומחליפים את YOUR_PROJECT_ID במזהה של פרויקט בענן.

הגדרת פרויקט Cloud של פרויקט Apps Script

  1. בפרויקט Apps Script, לוחצים על הסמל של הגדרות הפרויקט Project Settings (הגדרות הפרויקט).
  2. בקטע פרויקט ב-Google Cloud Platform (GCP), לוחצים על שינוי פרויקט.
  3. בקטע מספר הפרויקט ב-GCP, מדביקים את מספר הפרויקט ב-Cloud.
  4. לוחצים על Set project (הגדרת פרויקט). הפרויקט ב-Cloud ו-Apps Script הפרויקטים מחוברים עכשיו.

יצירת פריסה של Apps Script

עכשיו, כשכל הקוד מוכן, פורסים את Apps Script פרויקט. משתמשים במזהה הפריסה כשמגדירים את של אפליקציית Chat ב-Google Cloud.

  1. ב-Apps Script, פותחים את הפרויקט של אפליקציית התגובה לאירוע.

    מעבר אל Apps Script

  2. לוחצים על פריסה > פריסה חדשה.

  3. אם עדיין לא נבחרו תוסף ואפליקציית אינטרנט, לצד בחירת סוג, לוחצים על סוגי הפריסה הסמל של הגדרות הפרויקט ובוחרים באפשרות תוסף ואפליקציית אינטרנט.

  4. בקטע תיאור, מזינים תיאור של הגרסה הזו, למשל Complete version of incident management app.

  5. בקטע ביצוע כ, בוחרים באפשרות משתמש שניגש לאפליקציית האינטרנט.

  6. בקטע למי יש גישה, בוחרים באפשרות כל אחד בארגון ב-Workspace. שבו 'הארגון ב-Workspace' הוא השם של ארגון ב-Google Workspace.

  7. לוחצים על Deploy (פריסה). הדוחות של Apps Script בוצעו בהצלחה של האירוע, ומספק את מזהה הפריסה וכתובת ה-URL של האירוע דף האינטרנט לאתחול.

  8. מומלץ לרשום לפניכם את כתובת ה-URL של אפליקציית האינטרנט כדי להיכנס אליה מאוחר יותר כשמתחילים אירוע. מעתיקים את Deployment ID. אתם משתמשים במזהה הזה בזמן שמגדירים את אפליקציית Chat במסוף Google Cloud.

  9. לוחצים על סיום.

איך מגדירים את אפליקציית Chat במסוף Google Cloud

בקטע הזה מוסבר איך מגדירים את Google Chat API במסוף Google Cloud עם מידע על אפליקציית Chat, כולל מזהה הפריסה שיצרת עכשיו מה-Apps Script פרויקט.

  1. במסוף Google Cloud, לוחצים על תפריט. &gt; מוצרים נוספים &gt; Google Workspace &gt; ספריית המוצרים &gt; Google Chat API &gt; ניהול &gt; הגדרה.

    להגדרת Chat API

  2. בשדה App name, מקלידים Incident Management.

  3. בשדה כתובת URL של הדמות, מקלידים https://developers.google.com/chat/images/quickstart-app-avatar.png.

  4. בשדה Description, מקלידים Responds to incidents..

  5. מעבירים את המתג הפעלת תכונות אינטראקטיביות למצב פעיל.

  6. בקטע פונקציונליות, בוחרים באפשרות קבלת הודעות אישיות והצטרפות למרחבים משותפים ולשיחות קבוצתיות.

  7. בקטע Connection settings (הגדרות חיבור), בוחרים באפשרות Apps Script project (פרויקט Apps Script).

  8. בקטע Deployment ID (מזהה הפריסה), מדביקים את מזהה הפריסה של Apps Script שהעתקת קודם לכן מפרויקט Apps Script בפריסה גמישה.

  9. רושמים פקודת של קו נטוי אפליקציית Chat שהוטמעה במלואה כוללת:

    1. בקטע SlashCommand, לוחצים על Add a לוכסן הפקודה.

    2. בשדה Name, מקלידים /closeIncident.

    3. בשדה Command ID, מקלידים 1.

    4. בשדה תיאור, מקלידים Closes the incident being discussed in the space.

    5. בוחרים באפשרות פתיחה של תיבת דו-שיח.

    6. לוחצים על סיום. הפקודה של הלוכסן רשומה ומופיעה.

  10. בקטע חשיפה, בוחרים רוצה שאפליקציית Chat הזו תהיה זמינה לאנשים ספציפיים ולקבוצות ספציפיות? הדומיין ב-Workspace ומזינים את כתובת האימייל שלכם.

  11. בקטע Logs (יומנים), בוחרים באפשרות Log errors to Logging (רישום שגיאות ביומן).

  12. לוחצים על שמירה. תופיע הודעה שנשמרה לגבי ההגדרות, כלומר האפליקציה מוכן לבדיקה.

בדיקת האפליקציה של Chat

כדי לבדוק את אפליקציית Chat לניהול אירועים, צריך להפעיל אירוע בדף האינטרנט ואימות שאפליקציית Chat פועלת כמצופה:

  1. מעבר לכתובת ה-URL של אפליקציית האינטרנט לפריסת Apps Script.

  2. כאשר Apps Script מבקש הרשאה לגשת לנתונים שלכם, לוחצים על בדיקת הרשאות ונכנסים באמצעות חשבון Google מתאים. בדומיין Google Workspace, ולוחצים על אישור.

  3. דף האינטרנט של אתחול האירוע ייפתח. מזינים את פרטי הבדיקה:

    1. בקטע שם האירוע, מקלידים The First Incident.
    2. אופציונלי: בשדה משיבים לאירוע, מזינים את כתובות האימייל של לצוותי החירום העמיתים שלכם. הם חייבים להיות משתמשים עם חשבון Google Chat שמשויך לארגון שלכם ב-Google Workspace, או יצירת המרחב המשותף נכשלה. אל תזין את כתובת האימייל שלך, כי נכללים אוטומטית.
    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. לוחצים על סגירת האירוע.

באפליקציית ניהול האירועים יופיעו רשימת ההודעות במרחב המשותף ומסכמת אותן. ב-Vertex AI, מדביק את הסיכום במסמך Google Docs ומשתף את את המסמך במרחב המשותף.

הסרת המשאבים

כדי להימנע מצבירת חיובים בחשבון Google Cloud עבור במשאבים שנעשה בהם שימוש במדריך הזה, מומלץ למחוק את פרויקט בענן.

  1. במסוף Google Cloud, עוברים לדף Manage resources. לוחצים על תפריט &gt; IAM & Admin (אדמין) &gt; לניהול משאבים

    מעבר למנהל המשאבים

  2. ברשימת הפרויקטים, בוחרים את הפרויקט שרוצים למחוק ולוחצים על הסמל. מחיקה של .
  3. כדי למחוק, כותבים את מזהה הפרויקט בתיבת הדו-שיח ולוחצים על Shut down. את הפרויקט.