ตอบสนองต่อเหตุการณ์ต่างๆ ด้วย Google Chat, Vertex AI และ Apps Script

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

บทแนะนำนี้ใช้ขอบเขตการให้สิทธิ์ที่ขึ้นต้นด้วย https://www.googleapis.com/auth/chat.app.* ซึ่งพร้อมใช้งานเป็นส่วนหนึ่งของ Developer Preview แอป Chat ของคุณต้องได้รับการอนุมัติจากผู้ดูแลระบบแบบครั้งเดียว

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

  • มีการสร้างเคสที่ต้องดำเนินการอย่างเร่งด่วนในแพลตฟอร์มการจัดการลูกค้าสัมพันธ์ (CRM) ซึ่งกำหนดให้ทีมบริการต้องทำงานร่วมกันเพื่อแก้ไข
  • ระบบออฟไลน์ ทำให้มีการแจ้งเตือนกลุ่มวิศวกรความเสถียรสำหรับเว็บไซต์ (SRE) เพื่อให้วิศวกรทำงานร่วมกันเพื่อนำระบบกลับมาออนไลน์
  • เกิดแผ่นดินไหวรุนแรง และเจ้าหน้าที่กู้ภัยต้อง ประสานงานการตอบสนอง

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

ดูการทำงานของแอป Chat สำหรับการจัดการเหตุการณ์

  • เว็บไซต์ที่เริ่มเหตุการณ์
    รูปที่ 1 เว็บไซต์ที่ผู้ใช้รายงานเหตุการณ์ได้
  • การแจ้งเตือนว่ามีการสร้างพื้นที่ใน Chat สำหรับเหตุการณ์
    รูปที่ 2 การแจ้งเตือนว่ามีการสร้างพื้นที่ใน Chat สำหรับเหตุการณ์
  • พื้นที่ใน Chat สำหรับการตอบสนองต่อเหตุการณ์
    รูปที่ 3 พื้นที่ใน Chat สำหรับการตอบสนองต่อเหตุการณ์
  • การแก้ไขเหตุการณ์ด้วยคำสั่งเครื่องหมายทับ
    รูปที่ 4 การแก้ไขเหตุการณ์ด้วยคำสั่งเครื่องหมายทับ
  • กล่องโต้ตอบการแก้ไขเหตุการณ์
    รูปที่ 5 กล่องโต้ตอบการแก้ไขเหตุการณ์
  • เอกสาร Google เอกสารเกี่ยวกับการแก้ไขเหตุการณ์ที่แชร์ในพื้นที่ทำงาน
    รูปที่ 6 เอกสาร Google เอกสารเกี่ยวกับการแก้ไขเหตุการณ์ที่แชร์ในพื้นที่ทำงาน
  • เอกสารใน Google เอกสารเกี่ยวกับการแก้ไขเหตุการณ์ที่สรุปโดย AI
    รูปที่ 7 เอกสาร Google เอกสารเกี่ยวกับวิธีแก้ไขเหตุการณ์ที่เกี่ยวข้องกับข้อมูลสรุปโดย 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. บริการ Admin SDK ของ Apps Script จะรับข้อมูลสมาชิกในทีม เช่น รหัสผู้ใช้และอีเมล

    2. เมื่อใช้ชุดคำขอ HTTP ไปยัง Chat API โดยใช้ บริการ Chat ขั้นสูงของ Apps Script แอป Google Chat สำหรับการตอบสนองต่อเหตุการณ์ จะสร้างพื้นที่ทำงานใน Chat สำหรับเหตุการณ์ เพิ่มสมาชิกในทีมลงในพื้นที่ทำงาน และส่งข้อความไปยังพื้นที่ทำงาน

  4. สมาชิกในทีมพูดคุยเกี่ยวกับเหตุการณ์ในพื้นที่ใน Chat

  5. สมาชิกในทีมเรียกใช้คำสั่ง Slash เพื่อส่งสัญญาณการแก้ไขปัญหา

    1. การเรียก HTTP ไปยัง Chat API โดยใช้บริการ Chat ขั้นสูงของ Apps Script จะแสดงข้อความทั้งหมดในพื้นที่ทำงานของ Chat

    2. Vertex AI จะรับข้อความที่แสดงและสร้างข้อมูลสรุป

    3. บริการ DocumentApp ของ Apps Script จะสร้างเอกสารใน Docs และเพิ่มข้อมูลสรุปของ Vertex AI ลงในเอกสาร

    4. แอป Google Chat สำหรับการตอบสนองต่อเหตุการณ์จะเรียกใช้ Chat API เพื่อส่งข้อความที่แชร์ลิงก์ไปยังเอกสารสรุป ในเอกสาร

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

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

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

คอนโซล Google Cloud

  1. ใน Google Cloud Console ให้ไปที่เมนู > IAM และผู้ดูแลระบบ > สร้างโปรเจ็กต์

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

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

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

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

gcloud CLI

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

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

เปิดใช้การเรียกเก็บเงินสำหรับโปรเจ็กต์ Cloud

คอนโซล Google Cloud

  1. ในคอนโซล Google Cloud ให้ไปที่การเรียกเก็บเงิน คลิก เมนู > การเรียกเก็บเงิน > โปรเจ็กต์ของฉัน

    ไปที่การเรียกเก็บเงินสำหรับโปรเจ็กต์ของฉัน

  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 คือรหัสบัญชีสำหรับการเรียกเก็บเงินที่จะลิงก์กับ โปรเจ็กต์ Google Cloud

เปิดใช้ API

คอนโซล Google Cloud

  1. ในคอนโซล Google Cloud ให้เปิดใช้ Google Chat API, Google Docs API, Admin SDK API, Google Workspace Marketplace SDK และ Vertex AI API

    เปิดใช้ API

  2. ยืนยันว่าคุณกำลังเปิดใช้ API ในโปรเจ็กต์ Cloud ที่ถูกต้อง จากนั้นคลิกถัดไป

  3. ยืนยันว่าคุณเปิดใช้ API ที่ถูกต้อง แล้วคลิกเปิดใช้

gcloud CLI

  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, Google Workspace Marketplace SDK และ Vertex AI API ด้วยคำสั่ง gcloud services enable

    gcloud services enable chat.googleapis.com docs.googleapis.com admin.googleapis.com aiplatform.googleapis.com appsmarket-component.googleapis.com

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

แอปใน Chat จะเข้าถึง Google Chat API โดยใช้ข้อมูลเข้าสู่ระบบของแอปใน Chat แอปจะเข้าถึง Admin SDK API และ Google Docs API ด้วยข้อมูลเข้าสู่ระบบของผู้ใช้

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

การตรวจสอบสิทธิ์และการให้สิทธิ์ช่วยให้แอป Chat เข้าถึงทรัพยากรใน Google Workspace และ Google Cloud เพื่อประมวลผลการตอบสนองต่อเหตุการณ์ได้ โดยเฉพาะอย่างยิ่ง การตรวจสอบสิทธิ์ผู้ใช้จะใช้เพื่อเรียก Google Docs API และ Admin SDK API

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

  1. ใน Google Cloud Console ให้ไปที่เมนู > > การสร้างแบรนด์

    ไปที่การสร้างแบรนด์

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

    1. ในส่วนข้อมูลแอป ในชื่อแอป ให้พิมพ์ Incident Management
    2. ในอีเมลสำหรับการสนับสนุนผู้ใช้ ให้เลือกอีเมลหรือ กลุ่ม Google ที่เหมาะสม
    3. คลิกถัดไป
    4. เลือกภายในในส่วนผู้ชม หากเลือกภายในไม่ได้ ให้เลือกภายนอก
    5. คลิกถัดไป
    6. ในส่วนข้อมูลติดต่อ ให้ป้อนอีเมลที่คุณต้องการ รับการแจ้งเตือนเกี่ยวกับการเปลี่ยนแปลงในโปรเจ็กต์
    7. คลิกถัดไป
    8. ในส่วนเสร็จสิ้น ให้อ่าน นโยบายข้อมูลผู้ใช้ของบริการ Google API และหากยอมรับ ให้เลือก ฉันยอมรับบริการ Google API: นโยบายข้อมูลผู้ใช้
    9. คลิกต่อไป
    10. คลิกสร้าง
    11. หากเลือกภายนอกสำหรับประเภทผู้ใช้ ให้เพิ่มผู้ใช้ทดสอบโดยทำดังนี้
      1. คลิกกลุ่มเป้าหมาย
      2. ในส่วนผู้ใช้ทดสอบ ให้คลิกเพิ่มผู้ใช้
      3. ป้อนอีเมลและผู้ใช้ทดสอบที่ได้รับอนุญาตอื่นๆ แล้วคลิกบันทึก
  3. คลิกการเข้าถึงข้อมูล > เพิ่มหรือนำขอบเขตออก แผงจะปรากฏขึ้นพร้อมรายการขอบเขตสำหรับ API แต่ละรายการที่คุณ เปิดใช้ในโปรเจ็กต์ Google Cloud

    1. ในส่วนเพิ่มขอบเขตด้วยตนเอง ให้วางขอบเขตต่อไปนี้

      • 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
    2. คลิกเพิ่มลงในตาราง

    3. คลิกอัปเดต

    4. หลังจากเลือกขอบเขตที่แอปของคุณต้องการแล้ว ให้คลิกบันทึกในหน้าการเข้าถึงข้อมูล

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

การตรวจสอบสิทธิ์แอปใช้เพื่อเรียก Google Chat API

สร้างบัญชีบริการในคอนโซล Google Cloud

หากต้องการสร้างบัญชีบริการ ให้ทำตามขั้นตอนต่อไปนี้

คอนโซล Google Cloud

  1. ใน Google Cloud Console ให้ไปที่เมนู > IAM และผู้ดูแลระบบ > บัญชีบริการ

    ไปที่บัญชีบริการ

  2. คลิกสร้างบัญชีบริการ
  3. กรอกรายละเอียดบัญชีบริการ แล้วคลิกสร้างและต่อไป
  4. ไม่บังคับ: มอบหมายบทบาทให้กับบัญชีบริการเพื่อให้สิทธิ์เข้าถึงทรัพยากรของโปรเจ็กต์ Google Cloud ดูรายละเอียดเพิ่มเติมได้ที่การให้ เปลี่ยน และเพิกถอนสิทธิ์เข้าถึงทรัพยากร
  5. คลิกต่อไป
  6. ไม่บังคับ: ป้อนผู้ใช้หรือกลุ่มที่จัดการและดำเนินการกับบัญชีบริการนี้ได้ โปรดดูรายละเอียดเพิ่มเติมที่หัวข้อการจัดการการแอบอ้างเป็นบัญชีบริการ
  7. คลิกเสร็จสิ้น จดอีเมลของบัญชีบริการไว้

gcloud CLI

  1. สร้างบัญชีบริการโดยทำดังนี้
    gcloud iam service-accounts create SERVICE_ACCOUNT_NAME \
      --display-name="SERVICE_ACCOUNT_NAME"
  2. ไม่บังคับ: มอบหมายบทบาทให้กับบัญชีบริการเพื่อให้สิทธิ์เข้าถึงทรัพยากรของโปรเจ็กต์ Google Cloud ดูรายละเอียดเพิ่มเติมได้ที่การให้ เปลี่ยน และเพิกถอนสิทธิ์เข้าถึงทรัพยากร

บัญชีบริการจะปรากฏในหน้าบัญชีบริการ จากนั้นสร้างคีย์ส่วนตัว สำหรับบัญชีบริการ

สร้างคีย์ส่วนตัว

หากต้องการสร้างและดาวน์โหลดคีย์ส่วนตัวสำหรับบัญชีบริการ ให้ทำตามขั้นตอนต่อไปนี้

  1. ใน Google Cloud Console ให้ไปที่เมนู > IAM และผู้ดูแลระบบ > บัญชีบริการ

    ไปที่บัญชีบริการ

  2. เลือกบัญชีบริการ
  3. คลิกคีย์ > เพิ่มคีย์ > สร้างคีย์ใหม่
  4. เลือก JSON แล้วคลิกสร้าง

    ระบบจะสร้างคู่คีย์สาธารณะ/ส่วนตัวใหม่และดาวน์โหลดลงในเครื่องของคุณเป็นไฟล์ใหม่ บันทึกไฟล์ JSON ที่ดาวน์โหลดเป็น credentials.json ใน ไดเรกทอรีการทำงาน ไฟล์นี้เป็นสำเนาเดียวของคีย์นี้ ดูข้อมูลเกี่ยวกับวิธีจัดเก็บคีย์อย่างปลอดภัยได้ที่การจัดการคีย์ของบัญชีบริการ

  5. คลิกปิด

ดูข้อมูลเพิ่มเติมเกี่ยวกับบัญชีบริการได้ที่ บัญชีบริการ ในเอกสารประกอบของ Google Cloud IAM

สร้างไคลเอ็นต์ OAuth ที่เข้ากันได้กับ Google Workspace Marketplace

หากต้องการสร้างไคลเอ็นต์ OAuth ที่เข้ากันได้กับ Google Workspace Marketplace ให้ทำตามขั้นตอนต่อไปนี้

  1. ใน Google Cloud Console ให้ไปที่เมนู > IAM และผู้ดูแลระบบ > บัญชีบริการ

    ไปที่บัญชีบริการ

  2. คลิกบัญชีบริการที่คุณสร้างไว้สำหรับ แอป Chat

  3. คลิกการตั้งค่าขั้นสูง

  4. คลิกสร้างไคลเอ็นต์ OAuth ที่เข้ากันได้กับ Google Workspace Marketplace

  5. คลิกต่อไป

ข้อความยืนยันจะปรากฏขึ้นเพื่อแจ้งว่าระบบได้สร้างไคลเอ็นต์ OAuth ที่เข้ากันได้กับ Google Workspace Marketplace แล้ว

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

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

ฟังก์ชันบางอย่างมีขีดล่างที่ท้ายชื่อ เช่น processSlashCommand_() จาก ChatApp.gs ขีดล่างจะซ่อนฟังก์ชัน จากหน้าเว็บการเริ่มต้นเหตุการณ์เมื่อเปิดในเบราว์เซอร์ ดูข้อมูลเพิ่มเติมได้ที่ ฟังก์ชันส่วนตัว

Apps Script รองรับไฟล์ 2 ประเภท ได้แก่ .gsสคริปต์และ.html ไฟล์ หากต้องการปฏิบัติตามการรองรับนี้ ระบบจะรวม JavaScript ฝั่งไคลเอ็นต์ของแอปไว้ ในแท็ก <script /> และรวม CSS ไว้ในแท็ก <style /> ภายใน ไฟล์ HTML

คุณดูทั้งโปรเจ็กต์ได้ใน GitHub (ไม่บังคับ)

ดูใน GitHub

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

Consts.gs

กำหนดค่าคงที่ที่ไฟล์โค้ดอื่นๆ อ้างอิง รวมถึงรหัสโปรเจ็กต์ Cloud, รหัสตำแหน่ง Vertex AI, ข้อมูลเข้าสู่ระบบแอปสำหรับบัญชีบริการ และรหัสคำสั่ง Slash สำหรับปิดเหตุการณ์

ดูรหัส Consts.gs

apps-script/incident-response-app-auth/Consts.gs
const PROJECT_ID = 'replace-with-your-project-id';
const CLOSE_INCIDENT_COMMAND_ID = 1;
const APP_CREDENTIALS = 'replace-with-your-app-credentials';
const APP_CREDENTIALS_SCOPES = 'https://www.googleapis.com/auth/chat.bot https://www.googleapis.com/auth/chat.app.memberships https://www.googleapis.com/auth/chat.app.spaces.create';
const VERTEX_AI_LOCATION_ID = 'us-central1';
const MODEL_ID = 'gemini-1.5-flash-002';
ChatApp.gs

จัดการเหตุการณ์การโต้ตอบในแชท ซึ่งรวมถึง ข้อความ การคลิกการ์ด คำสั่ง Slash และกล่องโต้ตอบ ตอบกลับคำสั่งเครื่องหมายทับ /closeIncidentโดยเปิดกล่องโต้ตอบเพื่อรวบรวมรายละเอียดการแก้ไข เหตุการณ์ อ่านข้อความในพื้นที่โดยเรียกใช้เมธอด spaces.messages.list ใน Chat API รับรหัสผู้ใช้โดยใช้บริการไดเรกทอรี Admin SDK ใน Apps Script

ดูรหัส ChatApp.gs

apps-script/incident-response-app-auth/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-app-auth/ChatSpaceCreator.gs
/**
 * Handles an incident by creating a chat space, adding members, and posting a message.
 * All the actions are done using application credentials.
 *
 * @param {Object} formData - The data submitted by the user. It should contain the fields:
 *                           - title: The display name of the chat space.
 *                           - description: The description of the incident.
 *                           - users: A comma-separated string of user emails to be added to the space.
 * @return {string} The resource name of the new space.
 */
function handleIncident(formData) {
  const users = formData.users.trim().length > 0 ? formData.users.split(',') : [];
  const service = getService_();
  if (!service.hasAccess()) {
    console.error(service.getLastError());
    return;
   }
  const spaceName = createChatSpace_(formData.title, service);
  createHumanMembership_(spaceName, getUserEmail(), service);
  for (const user of users ){
    createHumanMembership_(spaceName, user, service);
  }
  createMessage_(spaceName, formData.description, service);
  return spaceName;
}
/**
 * Creates a chat space with application credentials.
 *
 * @param {string} displayName - The name of the chat space.
 * @param {object} service - The credentials of the service account.
 * @returns {string} The resource name of the new space.
*/
function createChatSpace_(displayName, service) {
  try {
    // For private apps, the alias can be used
    const my_customer_alias = "customers/my_customer";
    // Specify the space to create.
    const space = {
        displayName: displayName,
        spaceType: 'SPACE',                
        customer: my_customer_alias
    };
    // Call Chat API with a service account to create a message.
    const createdSpace = Chat.Spaces.create(
        space,
        {},
        // Authenticate with the service account token.
        {'Authorization': 'Bearer ' + service.getAccessToken()});
    return createdSpace.name;
  } catch (err) {
    // TODO (developer) - Handle exception.
    console.log('Failed to create space with error %s', err.message);
  }
}
/*
 * Creates a chat message with application credentials.
 *
 * @param {string} spaceName - The resource name of the space.
 * @param {string} message - The text to be posted.
 * @param {object} service - The credentials of the service account.
 * @return {string} the resource name of the new space.
 */
function createMessage_(spaceName, message, service) {
  try {
    // Call Chat API with a service account to create a message.
    const result = Chat.Spaces.Messages.create(
        {'text': message},
        spaceName,
        {},
        // Authenticate with the service account token.
        {'Authorization': 'Bearer ' + service.getAccessToken()});

  } catch (err) {
    // TODO (developer) - Handle exception.
    console.log('Failed to create message with error %s', err.message);
  }
}
/**
 * Creates a human membership in a chat space with application credentials.
 *
 * @param {string} spaceName - The resource name of the space.
 * @param {string} email - The email of the user to be added.
 * @param {object} service - The credentials of the service account.
 */
function createHumanMembership_(spaceName, email, service){
  try{
    const membership = {
      member: {
        name: 'users/'+email,
        // User type for the membership
        type: 'HUMAN'
      }
    };
    const result = Chat.Spaces.Members.create(
      membership,
      spaceName,
      {},
      {'Authorization': 'Bearer ' + service.getAccessToken()}
    );
  } catch (err){
    console.log('Failed to create membership with error %s', err.message)
  }

}

 /*
 * Creates a service for the service account.
 * @return {object}  - The credentials of the service account.
 */
function getService_() {
  return OAuth2.createService(APP_CREDENTIALS.client_email)
      .setTokenUrl('https://oauth2.googleapis.com/token')
      .setPrivateKey(APP_CREDENTIALS.private_key)
      .setIssuer(APP_CREDENTIALS.client_email)
      .setSubject(APP_CREDENTIALS.client_email)
      .setScope(APP_CREDENTIALS_SCOPES)
      .setPropertyStore(PropertiesService.getScriptProperties());
}
DocsApi.gs

เรียกใช้ Google เอกสาร API เพื่อสร้างเอกสาร Google เอกสารใน Google ไดรฟ์ของผู้ใช้ และเขียนสรุปข้อมูลเหตุการณ์ที่สร้างใน VertexAiApi.gs ลงในเอกสาร

ดูรหัส DocsApi.gs

apps-script/incident-response-app-auth/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 API ระบบจะโพสต์ข้อมูลสรุปนี้ในเอกสารที่สร้างขึ้นเป็นพิเศษใน DocsAPI.gs

ดูรหัส VertexAiApi.gs

apps-script/incident-response-app-auth/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 API_ENDPOINT = `https://${VERTEX_AI_LOCATION_ID}-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/${VERTEX_AI_LOCATION_ID}/publishers/google/models/${MODEL_ID}:generateContent`;
  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;
  // Get the access token.
  const accessToken = ScriptApp.getOAuthToken();

  const headers = {
    'Authorization': 'Bearer ' + accessToken,
    'Content-Type': 'application/json',
  };
  const payload = {
    'contents': {
      'role': 'user',
      'parts' : [
        {
          'text': prompt
        }
      ]
    }
  }
  const options = {
    'method': 'post',
    'headers': headers,
    'payload': JSON.stringify(payload),
    'muteHttpExceptions': true,
  };
  try {
    const response = UrlFetchApp.fetch(API_ENDPOINT, options);
    const responseCode = response.getResponseCode();
    const responseText = response.getContentText();

    if (responseCode === 200) {
      const jsonResponse = JSON.parse(responseText);
      console.log(jsonResponse)
      if (jsonResponse.candidates && jsonResponse.candidates.length > 0) {
        return jsonResponse.candidates[0].content.parts[0].text; // Access the summarized text
      } else {
        return "No summary found in response.";
      }

    } else {
      console.error("Vertex AI API Error:", responseCode, responseText);
      return `Error: ${responseCode} - ${responseText}`;
    }
  } catch (e) {
    console.error("UrlFetchApp Error:", e);
    return "Error: " + e.toString();
  }
}
WebController.gs

แสดงเว็บไซต์การเริ่มต้นเหตุการณ์

ดูรหัส WebController.gs

apps-script/incident-response-app-auth/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-app-auth/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-app-auth/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)
      .handleIncident(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-app-auth/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. ไปที่โปรเจ็กต์ Cloud ใน Google Cloud Console

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

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

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

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

วิธีสร้างโปรเจ็กต์ Apps Script และเชื่อมต่อกับโปรเจ็กต์ Cloud

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

    1. คลิกสำเนาของตอบสนองต่อเหตุการณ์ด้วย Google Chat

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

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

  5. ในสำเนาโปรเจ็กต์ Apps Script ให้ไปที่Consts.gs ไฟล์ แล้วแทนที่ YOUR_PROJECT_ID ด้วยรหัสของโปรเจ็กต์ Cloud

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

  1. ในโปรเจ็กต์ Apps Script ให้ คลิก ไอคอนสำหรับการตั้งค่าโปรเจ็กต์ การตั้งค่าโปรเจ็กต์
  2. ในส่วนโปรเจ็กต์ Google Cloud Platform (GCP) ให้คลิกเปลี่ยนโปรเจ็กต์
  3. ในหมายเลขโปรเจ็กต์ GCP ให้วางหมายเลขโปรเจ็กต์ของโปรเจ็กต์ Cloud
  4. คลิกตั้งค่าโปรเจ็กต์ ตอนนี้โปรเจ็กต์ระบบคลาวด์และโปรเจ็กต์ 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. คลิกทำให้ใช้งานได้ Apps Script จะรายงานการติดตั้งใช้งานที่สำเร็จ และระบุรหัสการติดตั้งใช้งานและ URL สำหรับหน้าเว็บเริ่มต้นของเหตุการณ์

  8. จด URL ของเว็บแอปไว้เพื่อเข้าชมในภายหลังเมื่อคุณเริ่มเหตุการณ์ คัดลอกรหัสการติดตั้งใช้งาน คุณใช้รหัสนี้ขณะกําหนดค่าแอป Chat ในคอนโซล Google Cloud

  9. คลิกเสร็จสิ้น

กำหนดค่าแอป Chat ใน Google Cloud Console

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

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

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

  2. ในส่วนชื่อแอป ให้พิมพ์ Incident Management

  3. ใน URL ของอวตาร ให้พิมพ์ https://developers.google.com/chat/images/quickstart-app-avatar.png

  4. ในคำอธิบาย ให้พิมพ์ Responds to incidents.

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

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

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

  8. ในรหัสการทำให้ใช้งานได้ ให้วางรหัสการทำให้ใช้งานได้ของ Apps Script ที่คัดลอกไว้ก่อนหน้านี้จากการทำให้ใช้งานได้ของโปรเจ็กต์ Apps Script

  9. ลงทะเบียนคำสั่งเครื่องหมายทับที่แอป Chat ที่ใช้งานได้อย่างเต็มรูปแบบใช้โดยทำดังนี้

    1. ในส่วนคำสั่ง ให้คลิกเพิ่มคำสั่ง

    2. ในรหัสคำสั่ง ให้พิมพ์ 1

    3. ในคำอธิบาย ให้พิมพ์ Closes the incident being discussed in the space.

    4. ในส่วนประเภทคำสั่ง ให้เลือกคำสั่ง Slash

    5. ในชื่อคำสั่งเครื่องหมายทับ ให้พิมพ์ /closeIncident

    6. เลือกเปิดกล่องโต้ตอบ

    7. คลิกเสร็จสิ้น ระบบจะลงทะเบียนและแสดงคำสั่งเครื่องหมายทับ

  10. ในส่วนระดับการเข้าถึง ให้เลือก ทำให้แอป Chat นี้พร้อมใช้งานสำหรับบุคคลและกลุ่มที่เฉพาะเจาะจงในโดเมน Workspace ของคุณ แล้วป้อนอีเมล

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

  12. คลิกบันทึก ข้อความว่าบันทึกการกำหนดค่าแล้วจะปรากฏขึ้น ซึ่งหมายความว่าแอป พร้อมทดสอบแล้ว

รับการอนุมัติจากผู้ดูแลระบบ

หากต้องการได้รับการอนุมัติจากผู้ดูแลระบบ คุณต้องกำหนดค่า แอป Chat ใน SDK ของ Google Workspace Marketplace

กำหนดค่าแอป Chat ใน SDK ของ Google Workspace Marketplace

หากต้องการกำหนดค่าแอป Chat ใน SDK ของ Google Workspace Marketplace ให้ทำตามขั้นตอนต่อไปนี้

  1. ในคอนโซล Google Cloud ให้ไปที่ เมนู > API และบริการ > API และบริการที่เปิดใช้ > Google Workspace Marketplace SDK > การกำหนดค่าแอป

    ไปที่การกำหนดค่าแอป

  2. กรอกข้อมูลในหน้าการกำหนดค่าแอปให้ครบถ้วน วิธีกำหนดค่าแอปแชท ขึ้นอยู่กับกลุ่มเป้าหมายที่คุณต้องการ และปัจจัยอื่นๆ หากต้องการความช่วยเหลือในการกรอกข้อมูลในหน้าการกำหนดค่าแอป โปรดดูกำหนดค่าแอปใน SDK ของ Google Workspace Marketplace สำหรับวัตถุประสงค์ของคู่มือนี้ ให้ป้อนข้อมูลต่อไปนี้

    1. เลือกส่วนตัวในส่วนระดับการมองเห็นแอป
    2. ในส่วนการตั้งค่าการติดตั้ง ให้เลือกการติดตั้งของผู้ดูแลระบบ
    3. เลือกแอปใน Chat ในส่วนการผสานรวมแอป
    4. ในส่วนขอบเขต OAuth ให้ป้อนขอบเขตต่อไปนี้
      • https://www.googleapis.com/auth/chat.app.spaces
      • https://www.googleapis.com/auth/chat.app.memberships
    5. ในส่วนข้อมูลนักพัฒนาแอป ให้ป้อนชื่อนักพัฒนาแอป URL เว็บไซต์ของนักพัฒนาแอป และอีเมลของนักพัฒนาแอป
    6. คลิกบันทึกฉบับร่าง

หลังจากกำหนดค่าแอปแล้ว ให้อัปเดตข้อมูลผลิตภัณฑ์ใน Store ดังนี้

  1. ในคอนโซล Google Cloud ให้ไปที่เมนู > API และบริการ > API และบริการที่เปิดใช้ > Google Workspace Marketplace SDK > ข้อมูลใน Store
  2. ในรายละเอียดแอป ให้เลือกการพัฒนาเว็บเป็นหมวดหมู่
  3. ในเนื้อหากราฟิก ให้อัปโหลดไอคอนแอปพลิเคชันในรูปแบบที่ขอ
  4. ในภาพหน้าจอ ให้อัปโหลดภาพหน้าจอของแอปพลิเคชัน
  5. ในลิงก์สนับสนุน ให้ป้อน URL ของข้อกำหนดในการให้บริการ, URL ของนโยบายความเป็นส่วนตัว และ URL ของการสนับสนุน
  6. ในการจัดจำหน่าย ให้เลือกภูมิภาคที่จะให้บริการแอปพลิเคชันนี้
  7. คลิกเผยแพร่

ขอการอนุมัติจากผู้ดูแลระบบ

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

ทดสอบแอป 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. หากต้องการสิ้นสุดการตอบสนองต่อเหตุการณ์และเริ่มกระบวนการแก้ไข ให้พิมพ์ /closeIncident ในพื้นที่แชท กล่องโต้ตอบการจัดการเหตุการณ์จะเปิดขึ้น

  8. ในปิดเหตุการณ์ ให้ป้อนคำอธิบายสำหรับการแก้ไขเหตุการณ์ เช่น Test complete

  9. คลิกปิดเหตุการณ์

แอปการจัดการเหตุการณ์จะแสดงข้อความในพื้นที่ สรุปข้อความเหล่านั้นด้วย Vertex AI วางสรุปในเอกสาร Google เอกสาร และแชร์เอกสารในพื้นที่

ล้างข้อมูล

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

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

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

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