รวบรวมและจัดการรายชื่อติดต่อใน Google Chat

บทแนะนำนี้จะแสดงวิธีสร้างแอป Google Chat ที่ช่วยผู้ใช้ Google Chat จัดการรายชื่อติดต่อส่วนตัวและทางธุรกิจ แอป Chat จะแจ้งให้ผู้ใช้กรอกแบบฟอร์มติดต่อในข้อความการ์ดและกล่องโต้ตอบเพื่อรวบรวมข้อมูล

ดูการทำงานของแอป Chat ดังนี้

  • แบบฟอร์มติดต่อจากคำสั่งเครื่องหมายทับ
    รูปที่ 1 แอป Chat ตอบสนองต่อคำสั่งขีดกลาง /about ด้วยข้อความและปุ่มที่เปิดแบบฟอร์มติดต่อ
  • แบบฟอร์มติดต่อในกล่องโต้ตอบ
    รูปที่ 2 แอป Chat จะเปิดกล่องโต้ตอบที่ผู้ใช้สามารถ กรอกข้อมูลรายชื่อติดต่อ
  • กล่องโต้ตอบสำหรับยืนยันและตรวจสอบ
    รูปที่ 3 แอป Chat แสดงกล่องโต้ตอบการยืนยัน ที่ผู้ใช้จะตรวจสอบและยืนยันข้อมูลได้ การส่ง
  • SMS ที่ยืนยันรายชื่อติดต่อใหม่
    รูปที่ 4 หลังจากผู้ใช้ส่ง แบบฟอร์ม แล้วแอปแชทจะส่งหมายเลข SMS เพื่อยืนยันการส่ง
  • แบบฟอร์มติดต่อจากข้อความการ์ด
    รูปที่ 5 แอป Chat ยังแจ้งให้ผู้ใช้เพิ่มรายชื่อติดต่อ จากการ์ดในข้อความ

ข้อกำหนดเบื้องต้น

  • ธุรกิจหรือองค์กร บัญชี Google Workspace ที่มีสิทธิ์เข้าถึง Google Chat

วัตถุประสงค์

สถาปัตยกรรม

แอป Chat สร้างขึ้นใน Google Apps Script และใช้เหตุการณ์การโต้ตอบเพื่อประมวลผลและตอบกลับผู้ใช้ Chat

ต่อไปนี้คือวิธีที่ผู้ใช้อาจโต้ตอบกับแอปแชทตามปกติ

  1. ผู้ใช้เปิดข้อความส่วนตัวด้วยแอป Chat หรือเพิ่มแอป Chat ไปยังพื้นที่ทำงานที่มีอยู่

  2. แอป Chat จะแจ้งให้ผู้ใช้เพิ่มรายชื่อติดต่อโดยการสร้างและแสดงแบบฟอร์มติดต่อเป็นออบเจ็กต์ card แอป Chat จะตอบสนองต่อผู้ใช้ด้วยวิธีต่อไปนี้เพื่อแสดงแบบฟอร์มติดต่อ

    • ตอบกลับการ @พูดถึงและข้อความส่วนตัวด้วยข้อความการ์ดที่ มีแบบฟอร์มติดต่อ
    • ตอบคำสั่งเครื่องหมายทับ /addContact โดยเปิดกล่องโต้ตอบที่มี แบบฟอร์มติดต่อ
    • ตอบคำสั่งเครื่องหมายทับ /about ด้วย SMS ที่มีแอตทริบิวต์ ปุ่มเพิ่มรายชื่อติดต่อที่ผู้ใช้สามารถคลิกเพื่อเปิดกล่องโต้ตอบที่มี แบบฟอร์มติดต่อ
  3. เมื่อเห็นแบบฟอร์มติดต่อ ผู้ใช้จะป้อนข้อมูลติดต่อในช่องและวิดเจ็ตต่อไปนี้

    • ชื่อและนามสกุล: ก textInput เป็นวิดเจ็ตที่ยอมรับสตริง
    • วันเกิด: dateTimePicker วิดเจ็ตที่รับเฉพาะวันที่
    • ประเภทรายชื่อติดต่อ: ก selectionInput วิดเจ็ตของปุ่มตัวเลือกที่ให้ผู้ใช้เลือกและส่งสตริงเดียวได้ (Personal หรือ Work)
    • ปุ่มตรวจสอบและส่ง: อาร์เรย์ buttonList ที่มีวิดเจ็ต button ที่ผู้ใช้คลิกเพื่อส่งค่าที่ป้อน
  4. แอป Google Chat จะจัดการCARD_CLICKEDเหตุการณ์การโต้ตอบเพื่อประมวลผลค่าที่ผู้ใช้ป้อน และแสดงค่าในการ์ดยืนยัน

  5. ผู้ใช้ตรวจสอบการ์ดยืนยันและคลิกปุ่มส่ง เพื่อสรุปข้อมูลติดต่อ

  6. แอป Google Chat จะส่งข้อความส่วนตัวเพื่อยืนยันการส่ง

เตรียมสภาพแวดล้อม

ส่วนนี้จะแสดงวิธีสร้างและกำหนดค่าโปรเจ็กต์ Google Cloud สำหรับ แอป Chat

สร้างโปรเจ็กต์ Google Cloud

คอนโซล Google Cloud

  1. ในคอนโซล Google Cloud ให้ไปที่เมนู > IAM และ ผู้ดูแลระบบ > สร้างโครงการ

    ไปที่ "สร้างโปรเจ็กต์"

  2. ในช่องชื่อโปรเจ็กต์ ให้ป้อนชื่อที่สื่อความหมายสำหรับโปรเจ็กต์ของคุณ

    ไม่บังคับ: หากต้องการแก้ไขรหัสโปรเจ็กต์ ให้คลิกแก้ไข เปลี่ยนรหัสโปรเจ็กต์ไม่ได้ หลังจากสร้างโปรเจ็กต์แล้ว ดังนั้นให้เลือกรหัสที่ตรงกับความต้องการของคุณตลอดอายุการใช้งาน

  3. ในช่องสถานที่ ให้คลิกเรียกดูเพื่อแสดงสถานที่ที่เป็นไปได้สำหรับโปรเจ็กต์ จากนั้นคลิกเลือก
  4. คลิกสร้าง คอนโซล Google Cloud จะไปยังหน้าแดชบอร์ดและสร้างโปรเจ็กต์แล้ว ภายในไม่กี่นาที

gcloud CLI

เข้าถึง Google Cloud CLI (gcloud) ในสภาพแวดล้อมการพัฒนาอย่างใดอย่างหนึ่งต่อไปนี้

  • Cloud Shell: หากต้องการใช้เทอร์มินัลออนไลน์ที่มีการตั้งค่า gcloud CLI ไว้แล้ว ให้เปิดใช้งาน Cloud Shell
    เปิดใช้งาน Cloud Shell
  • เชลล์ในเครื่อง: หากต้องการใช้สภาพแวดล้อมการพัฒนาซอฟต์แวร์ในเครื่อง ให้ติดตั้งและเริ่มต้น CLI ของ gcloud
    หากต้องการสร้างโปรเจ็กต์ที่อยู่ในระบบคลาวด์ ให้ใช้คำสั่ง gcloud projects create:
    gcloud projects create PROJECT_ID
    แทนที่ PROJECT_ID ด้วยการตั้งค่ารหัสสำหรับโปรเจ็กต์ที่ต้องการสร้าง

ตั้งค่าการตรวจสอบสิทธิ์และการให้สิทธิ์

แอป Google Chat กำหนดให้คุณกำหนดค่าหน้าจอขอความยินยอม OAuth เพื่อให้ผู้ใช้สามารถให้สิทธิ์แอปของคุณในแอปพลิเคชัน Google Workspace ซึ่งรวมถึง Google Chat

ในบทแนะนำนี้ คุณจะได้ทำให้แอป Chat ใช้งานได้สำหรับ และการใช้งานภายใน ดังนั้นสามารถใช้ข้อมูลตัวยึดตำแหน่งสำหรับ หน้าจอคำยินยอม ก่อนเผยแพร่แอป Chat ให้แทนที่ ข้อมูลตัวยึดตำแหน่งที่มีข้อมูลจริง

  1. ในคอนโซล Google Cloud ให้ไปที่ เมนู > API และ บริการ > หน้าจอขอความยินยอม OAuth

    ไปที่หน้าจอขอความยินยอม OAuth

  2. ในส่วนประเภทผู้ใช้ ให้เลือกภายใน แล้วคลิกสร้าง

  3. ในชื่อแอป ให้พิมพ์ Contact Manager

  4. ในอีเมลการสนับสนุนผู้ใช้ ให้เลือกที่อยู่อีเมลของคุณหรืออีเมล กลุ่ม Google

  5. ป้อนอีเมลของคุณในส่วนข้อมูลติดต่อของนักพัฒนาแอป

  6. คลิกบันทึกและต่อไป

  7. ในหน้าขอบเขต ให้คลิกบันทึกและต่อไป (แอปแชทไม่จําเป็นต้องใช้ขอบเขต OAuth)

  8. ตรวจสอบสรุป แล้วคลิกกลับไปที่หน้าแดชบอร์ด

สร้างและติดตั้งใช้งานแอป Chat

ในส่วนต่อไปนี้ ให้คัดลอกและอัปเดต โครงการ Apps Script ที่มีแอปพลิเคชันที่จำเป็นทั้งหมด สำหรับแอป Chat เพื่อจะได้ไม่ต้องคัดลอก วางแต่ละไฟล์

นอกจากนี้ คุณยังดูทั้งโปรเจ็กต์ได้ใน GitHub

ดูใน GitHub

ภาพรวมของแต่ละไฟล์มีดังนี้

main.gs

จัดการตรรกะของแอปทั้งหมด รวมถึงเหตุการณ์การโต้ตอบเกี่ยวกับเวลาที่ผู้ใช้ส่งข้อความ ไปยังแอป Chat ให้คลิกปุ่มจาก ข้อความแอปใน Chat หรือเปิดและปิดกล่องโต้ตอบ

ดูรหัส main.gs

apps-script/contact-form-app/main.gs
/**
 * Copyright 2024 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * Responds to a MESSAGE interaction event in Google Chat.
 *
 * @param {Object} event the MESSAGE interaction event from Chat API.
 * @return {Object} message response that opens a dialog or sends private
 *                          message with text and card.
 */
function onMessage(event) {
  if (event.message.slashCommand) {
    switch (event.message.slashCommand.commandId) {
      case 1:
        // If the slash command is "/about", responds with a text message and button
        // that opens a dialog.
        return {
          text: "Manage your personal and business contacts 📇. To add a " +
                  "contact, use the slash command `/addContact`.",
          accessoryWidgets: [{ buttonList: { buttons: [{
            text: "Add Contact",
            onClick: { action: {
              function: "openDialog",
              interaction: "OPEN_DIALOG"
            }}
          }]}}]
        }
      case 2:
        // If the slash command is "/addContact", opens a dialog.
        return openDialog(event);
    }
  }

  // If user sends the Chat app a message without a slash command, the app responds
  // privately with a text and card to add a contact.
  return {
    privateMessageViewer: event.user,
    text: "To add a contact, try `/addContact` or complete the form below:",
    cardsV2: [{
      cardId: "addContactForm",
      card: {
        header: { title: "Add a contact" },
        sections:[{ widgets: CONTACT_FORM_WIDGETS.concat([{
          buttonList: { buttons: [{
            text: "Review and submit",
            onClick: { action: { function : "openNextCard" }}
          }]}
        }])}]
      }
    }]
  };
}

/**
 * Responds to CARD_CLICKED interaction events in Google Chat.
 *
 * @param {Object} event the CARD_CLICKED interaction event from Google Chat
 * @return {Object} message responses specific to the dialog handling.
 */
function onCardClick(event) {
  // Initial dialog form page
  if (event.common.invokedFunction === "openDialog") {
    return openDialog(event);
  // Second dialog form page
  } else if (event.common.invokedFunction === "openNextCard") {
    return openNextCard(
      event.user,
      fetchFormValue(event, "contactName"),
      fetchFormValue(event, "contactBirthdate"),
      fetchFormValue(event, "contactType"),
      event.isDialogEvent
    );
  // Dialog form submission
  } else if (event.common.invokedFunction === "submitForm") {
    const userInputs = event.common.parameters;
    return submitForm(event.user, userInputs, event.dialogEventType);
  }
}

/**
 * Extracts form input value for a given widget.
 *
 * @param {Object} event the CARD_CLICKED interaction event from Google Chat.
 * @param {String} widgetName a unique ID for the widget, specified in the widget's name field.
 * @returns the value inputted by the user, null if no value can be found.
 */
function fetchFormValue(event, widgetName) {
  const formItem = event.common.formInputs[widgetName][""];
  // For widgets that receive StringInputs data, the value input by the user.
  if (formItem.hasOwnProperty("stringInputs")) {
    const stringInput = event.common.formInputs[widgetName][""].stringInputs.value[0];
    if (stringInput != null) {
      return stringInput;
    }
  // For widgets that receive dateInput data, the value input by the user.
  } else if (formItem.hasOwnProperty("dateInput")) {
    const dateInput = event.common.formInputs[widgetName][""].dateInput.msSinceEpoch;
     if (dateInput != null) {
       return dateInput;
     }
  }

  return null;
}

/**
 * Opens a dialog that prompts users to add details about a contact.
 *
 * @return {Object} a message with an action response to open a dialog.
 */
function openDialog() {
  return { actionResponse: {
    type: "DIALOG",
    dialogAction: { dialog: { body: { sections: [{
      header: "Add new contact",
      widgets: CONTACT_FORM_WIDGETS.concat([{
        buttonList: { buttons: [{
          text: "Review and submit",
          onClick: { action: { function: "openNextCard" }}
        }]}
      }])
    }]}}}
  }};
}

/**
 * Returns a dialog or card message that displays a confirmation of contact
 * details before users submit.
 *
 * @param {String} user the user who submitted the information.
 * @param {String} contactName the contact name from the previous dialog or card.
 * @param {String} contactBirthdate the birthdate from the previous dialog or card.
 * @param {String} contactType the contact type from the previous dialog or card.
 * @param {boolean} fromDialog whether the information was submitted from a dialog.
 *
 * @return {Object} returns a dialog or private card message.
 */
function openNextCard(user, contactName, contactBirthdate, contactType, fromDialog) {
  const name = contactName ?? "<i>Not provided</i>";
  const birthdate = contactBirthdate ?? "<i>Not provided</i>";
  const type = contactType ?? "<i>Not provided</i>";
  const cardConfirmation = {
    header: "Your contact",
    widgets: [{
      textParagraph: { text: "Confirm contact information and submit:" }}, {
      textParagraph: { text: "<b>Name:</b> " + name }}, {
      textParagraph: {
        text: "<b>Birthday:</b> " + convertMillisToDateString(birthdate)
      }}, {
      textParagraph: { text: "<b>Type:</b> " + type }}, {
      buttonList: { buttons: [{
        text: "Submit",
        onClick: { action: {
          function: "submitForm",
          parameters: [{
            key: "contactName", value: name }, {
            key: "contactBirthdate", value: birthdate }, {
            key: "contactType", value: type
          }]
        }}
      }]}
    }]
  };

  // Returns a dialog with contact information that the user input.
  if (fromDialog) {
    return { action_response: {
      type: "DIALOG",
      dialogAction: { dialog: { body: { sections: [ cardConfirmation ]}}}
    }};
  }

  // Updates existing card message with contact information that the user input.
  return {
    actionResponse: { type: "UPDATE_MESSAGE" },
    privateMessageViewer: user,
    cardsV2: [{
      card: { sections: [cardConfirmation]}
    }]
  }
}

/**
  * Submits information from a dialog or card message.
  *
  * @param {Object} user the person who submitted the information.
  * @param {Object} userInputs the form input values from event parameters.
  * @param {boolean} dialogEventType "SUBMIT_DIALOG" if from a dialog.
  * @return {Object} a message response that opens a dialog or posts a private
  *                  message.
  */
function submitForm(user, userInputs, dialogEventType) {
  const contactName = userInputs["contactName"];
  // Checks to make sure the user entered a contact name.
  // If no name value detected, returns an error message.
  if (!contactName) {
    const errorMessage = "Don't forget to name your new contact!";
    if (dialogEventType === "SUBMIT_DIALOG") {
      return { actionResponse: {
        type: "DIALOG",
        dialogAction: { actionStatus: {
          statusCode: "INVALID_ARGUMENT",
          userFacingMessage: errorMessage
        }}
      }};
    } else {
      return {
        privateMessageViewer: user,
        text: errorMessage
      };
    }
  }

  // The Chat app indicates that it received form data from the dialog or card.
  // Sends private text message that confirms submission.
  const confirmationMessage = " " + contactName + " has been added to your contacts.";
  if (dialogEventType === "SUBMIT_DIALOG") {
    return {
      actionResponse: {
        type: "NEW_MESSAGE",
        dialogAction: { actionStatus: {
          statusCode: "OK",
          userFacingMessage: "Success " + JSON.stringify(contactName)
        }}
      },
      privateMessageViewer: user,
      text: confirmationMessage
    }
  } else {
    return {
      actionResponse: { type: "NEW_MESSAGE" },
      privateMessageViewer: user,
      text: confirmationMessage
    };
  }
}

/**
 * Converts date in milliseconds since epoch to user-friendly string.
 *
 * @param {Object} millis the milliseconds since epoch time.
 * @return {string} Display-friend date (English US).
 */
function convertMillisToDateString(millis) {
  const date = new Date(millis);
  const options = { year: 'numeric', month: 'long', day: 'numeric' };
  return date.toLocaleDateString('en-US', options);
}
contactForm.gs

มีวิดเจ็ตที่รับข้อมูลแบบฟอร์มจากผู้ใช้ วิดเจ็ตการป้อนข้อมูลแบบฟอร์มเหล่านี้จะแสดงในการ์ดที่ปรากฏในข้อความและกล่องโต้ตอบ

ดูรหัส contactForm.gs

apps-script/contact-form-app/contactForm.gs
/**
 * Copyright 2024 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * The section of the contact card that contains the form input widgets. Used in a dialog and card message.
 * To add and preview widgets, use the Card Builder: https://addons.gsuite.google.com/uikit/builder
 */
const CONTACT_FORM_WIDGETS = [
  {
    "textInput": {
      "name": "contactName",
      "label": "First and last name",
      "type": "SINGLE_LINE"
    }
  },
  {
    "dateTimePicker": {
      "name": "contactBirthdate",
      "label": "Birthdate",
      "type": "DATE_ONLY"
    }
  },
  {
    "selectionInput": {
      "name": "contactType",
      "label": "Contact type",
      "type": "RADIO_BUTTON",
      "items": [
        {
          "text": "Work",
          "value": "Work",
          "selected": false
        },
        {
          "text": "Personal",
          "value": "Personal",
          "selected": false
        }
      ]
    }
  }
];
appsscript.json

ไฟล์ Manifest ของ Apps Script ที่กําหนดค่าและกำหนดค่าโปรเจ็กต์ Apps Script สําหรับแอป Chat

ดูรหัส appsscript.json

apps-script/contact-form-app/appsscript.json
{
  "timeZone": "America/Los_Angeles",
  "dependencies": {},
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8",
  "chat": {}
}

ค้นหาหมายเลขและรหัสโปรเจ็กต์ในระบบคลาวด์

  1. ไปที่โปรเจ็กต์ที่อยู่ในระบบคลาวด์ในคอนโซล Google Cloud

    ไปที่คอนโซล Google Cloud

  2. คลิกการตั้งค่าและยูทิลิตี > การตั้งค่าโปรเจ็กต์

  3. ดูค่าต่างๆ ในช่องหมายเลขโปรเจ็กต์และรหัสโปรเจ็กต์ คุณ ใช้ในส่วนต่อไปนี้

สร้างโปรเจ็กต์ Apps Script

วิธีสร้างโครงการ Apps Script และเชื่อมต่อกับ โปรเจ็กต์ที่อยู่ในระบบคลาวด์:

  1. คลิกปุ่มต่อไปนี้เพื่อเปิดโปรเจ็กต์ Apps Script จัดการรายชื่อติดต่อใน Google Chat
    เปิดโปรเจ็กต์
  2. คลิก ภาพรวม
  3. ในหน้าภาพรวม ให้คลิก ไอคอนสำหรับทำสำเนา ทําสําเนา
  4. ตั้งชื่อสำเนาโครงการ Apps Script ดังนี้

    1. คลิกสำเนาของ "จัดการรายชื่อติดต่อใน Google Chat"

    2. ในชื่อโปรเจ็กต์ ให้พิมพ์ Contact Manager - Google Chat app

    3. คลิกเปลี่ยนชื่อ

ตั้งค่าโปรเจ็กต์ Cloud ของโปรเจ็กต์ Apps Script

  1. ในโปรเจ็กต์ Apps Script ให้คลิก ไอคอนสำหรับการตั้งค่าโปรเจ็กต์ Project Settings
  2. ในส่วนโปรเจ็กต์ Google Cloud Platform (GCP) ให้คลิกเปลี่ยนโปรเจ็กต์
  3. วางหมายเลขโปรเจ็กต์ GCP ในหมายเลขโปรเจ็กต์ GCP
  4. คลิกตั้งค่าโปรเจ็กต์ โปรเจ็กต์ที่อยู่ในระบบคลาวด์และ Apps Script เชื่อมต่อโปรเจ็กต์แล้ว

สร้าง Apps Script ที่นำไปใช้งาน

เมื่อใส่โค้ดทั้งหมดแล้ว ให้นำ Apps Script ไปใช้งาน คุณจะใช้รหัสการทำให้ใช้งานได้เมื่อกำหนดค่า แอป Chat ใน Google Cloud

  1. ใน Apps Script ให้เปิด

    ไปที่ Apps Script

  2. คลิกทำให้ใช้งานได้ > ทำให้ใช้งานได้ใหม่

  3. หากยังไม่ได้เลือกส่วนเสริม ให้ดำเนินการดังนี้ เลือกประเภท คลิกประเภทการทำให้ใช้งานได้ ไอคอนสำหรับการตั้งค่าโปรเจ็กต์ แล้วเลือกส่วนเสริม

  4. ในคำอธิบาย ให้ป้อนคำอธิบายสำหรับเวอร์ชันนี้ เช่น Test of Contact Manager

  5. คลิกทำให้ใช้งานได้ รายงาน Apps Script สำเร็จแล้ว การทำให้ใช้งานได้ และระบุรหัสการทำให้ใช้งานได้

  6. คลิก คัดลอกเพื่อคัดลอก รหัสการทำให้ใช้งานได้ แล้วคลิกเสร็จสิ้น

กำหนดค่าแอป Chat ในคอนโซล Google Cloud

ส่วนนี้จะแสดงวิธีกำหนดค่า Google Chat API ในคอนโซล Google Cloud ที่มีข้อมูลเกี่ยวกับแอป Chat ของคุณ รวมถึง รหัสการทำให้ใช้งานได้ที่คุณเพิ่งสร้างจาก Apps Script

  1. ในคอนโซล Google Cloud ให้คลิกเมนู > ผลิตภัณฑ์เพิ่มเติม > Google Workspace > คลังผลิตภัณฑ์ > Google Chat API > จัดการ > การกำหนดค่า

    ไปที่การกำหนดค่า Chat API

  2. ในชื่อแอป ให้พิมพ์ Contact Manager

  3. ใน URL รูปโปรไฟล์ ให้พิมพ์ https://developers.google.com/chat/images/contact-icon.png

  4. พิมพ์ Manage your personal and business contacts ในคำอธิบาย

  5. คลิกปุ่มสลับเปิดใช้ฟีเจอร์แบบอินเทอร์แอกทีฟไปที่ตำแหน่งเปิด

  6. ในส่วนฟังก์ชัน ให้เลือกช่องทําเครื่องหมายรับข้อความแบบ 1:1 และ เข้าร่วมพื้นที่ทำงานและการสนทนากลุ่ม

  7. เลือก Apps Script ในส่วนการตั้งค่าการเชื่อมต่อ

  8. วางรหัสการทำให้ใช้งานได้ของ Apps Script ในรหัสการทำให้ใช้งานได้ ที่คุณคัดลอกในส่วนก่อนหน้านี้เมื่อสร้าง การทำให้ Apps Script ใช้งานได้

  9. ในส่วนคำสั่งเครื่องหมายทับ ให้ตั้งค่าคำสั่งเครื่องหมายทับ /about และ /addContact ดังนี้

    1. คลิกเพิ่มคำสั่งเครื่องหมายทับเพื่อตั้งค่าคำสั่งเครื่องหมายทับรายการแรก
    2. ใน ชื่อ ให้พิมพ์ /about
    3. ใน Command ID ให้พิมพ์ 1
    4. ในคำอธิบาย ให้พิมพ์ Learn how to use this Chat app to manage your contacts
    5. เลือกเปิดกล่องโต้ตอบ
    6. คลิกเสร็จสิ้น
    7. คลิกเพิ่มคำสั่งเครื่องหมายทับเพื่อตั้งค่าคำสั่งเครื่องหมายทับอื่น
    8. พิมพ์ /addContact ในชื่อ
    9. ในรหัสคําสั่ง ให้พิมพ์ 2
    10. ในคำอธิบาย ให้พิมพ์ Submit information about a contact
    11. เลือกเปิดกล่องโต้ตอบ
    12. คลิกเสร็จสิ้น
  10. ในส่วนระดับการเข้าถึง ให้เลือก ทำให้แอป Chat นี้ใช้งานได้กับบุคคลหรือกลุ่มที่ต้องการใน YOUR DOMAIN และป้อนอีเมลของคุณ

  11. เลือกบันทึกข้อผิดพลาดในการบันทึกในส่วนบันทึก

  12. คลิกบันทึก ข้อความที่บันทึกไว้สำหรับการกำหนดค่าจะปรากฏขึ้น

แอป Chat พร้อมให้ติดตั้งและทดสอบใน Chat แล้ว

ทดสอบแอป Chat

หากต้องการทดสอบแอป Chat ให้เปิดพื้นที่ทำงานของข้อความส่วนตัวด้วยแอป Chat แล้วส่งข้อความ โดยทำดังนี้

  1. เปิด Google Chat โดยใช้บัญชี Google Workspace ที่คุณให้ไว้เมื่อเพิ่มตัวเองเป็นผู้ทดสอบที่เชื่อถือได้

    ไปที่ Google Chat

  2. คลิก แชทใหม่
  3. ในช่องเพิ่มผู้คนอย่างน้อย 1 คน ให้พิมพ์ชื่อ แอป Chat
  4. เลือกแอปใน Chat จากผลการค้นหา โดยตรง ข้อความจะเปิดขึ้น

  1. ในข้อความส่วนตัวใหม่ที่มีแอป Chat พิมพ์ /addContact แล้วกด Enter

  2. ในกล่องโต้ตอบที่เปิดขึ้น ให้ป้อนข้อมูลติดต่อ:

    1. ป้อนชื่อในช่องข้อความชื่อและนามสกุล
    2. เลือกวันที่ในเครื่องมือเลือกวันที่วันเกิด
    3. ในส่วนประเภทรายชื่อติดต่อ ให้เลือกปุ่มตัวเลือกที่ทำงานหรือส่วนตัว
  3. คลิกตรวจสอบและส่ง

  4. ในกล่องโต้ตอบการยืนยัน ให้ตรวจสอบข้อมูลที่คุณส่ง แล้วคลิกส่ง แอป Chat ตอบกลับด้วยข้อความ ข้อความว่า CONTACT NAME has been added to your contacts.

  5. นอกจากนี้ คุณยังทดสอบและส่งแบบฟอร์มติดต่อในรายการต่อไปนี้ได้ ด้วยวิธีต่อไปนี้

    • ใช้คำสั่งเครื่องหมายทับ /about การตอบกลับของแอป Chat ด้วยข้อความและปุ่มวิดเจ็ตอุปกรณ์เสริมที่เขียนว่า Add a contact คุณสามารถคลิกปุ่มเพื่อเปิดกล่องโต้ตอบที่มีแบบฟอร์มติดต่อ
    • ส่งข้อความส่วนตัวหาแอป Chat โดยไม่มี คําสั่งเครื่องหมายทับ เช่น Hello แอป Chat การตอบกลับด้วยข้อความและการ์ดที่มีแบบฟอร์มติดต่อ

ล้างข้อมูล

เราขอแนะนำให้คุณลบโปรเจ็กต์ Cloud เพื่อหลีกเลี่ยงการเรียกเก็บเงินจากบัญชี Google Cloud สำหรับทรัพยากรที่ใช้ในบทแนะนำนี้

  1. ในคอนโซล Google Cloud ให้ไปที่หน้าจัดการทรัพยากร คลิก เมนู > IAM และผู้ดูแลระบบ > จัดการทรัพยากร

    ไปที่เครื่องมือจัดการทรัพยากร

  2. ในรายการโปรเจ็กต์ ให้เลือกโปรเจ็กต์ที่ต้องการลบแล้วคลิก ลบ
  3. ในกล่องโต้ตอบ ให้พิมพ์รหัสโปรเจ็กต์ แล้วคลิกปิดเพื่อลบโปรเจ็กต์