จัดการเว็บฮุค

โดยค่าเริ่มต้น ตัวแทนทั้งหมดที่สร้างผ่าน RBM Management API จะใช้เว็บฮุคเดียวสำหรับการแจ้งเตือน เว็บฮุคระดับพาร์ทเนอร์นี้ได้รับการกำหนดค่าในคอนโซลของนักพัฒนาซอฟต์แวร์ Business Communications และมีผลบังคับใช้กับตัวแทนทั้งหมดภายในบัญชีพาร์ทเนอร์

หรือคุณสามารถใช้ RBM Management API เพื่อกำหนดค่าเว็บฮุคระดับตัวแทนได้ นี่อาจเป็นตัวเลือกที่ดีหากคุณจัดการตัวแทนหลายรายที่มีลักษณะการทำงานที่ต่างกัน

ข้อมูลโค้ดในหน้านี้มาจากตัวอย่าง Java และตัวอย่าง Node.js

สร้างการผสานรวมเว็บฮุค

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

Node.js


const businessCommunicationsApiHelper =
  require('@google/rbm-businesscommunications');

const privateKey =
  require('../../resources/businesscommunications-service-account-credentials.json');

businessCommunicationsApiHelper.initBusinessCommunucationsApi(privateKey);

const url = 'https://myrbmserviceendpoint.somewhere.com/callback';

const token = '123456';

businessCommunicationsApiHelper
  .createWebhookIntegration(agent.name, url, token)
  .then((response) => {
    console.log(JSON.stringify(response.data, null, 2));
  }).catch((err) => {
    console.log(err);
  }
);

โค้ดนี้จะแสดงออบเจ็กต์เว็บฮุคใหม่

{
  "name": "brands/40bd963f-ff92-425c-b273-8f0892d2d017/agents/my_new_agent_hfaoplpu_agent/integrations/4efdb82f-fd6d-4ba4-8ea3-f2f4a60d1547",
  "status": "ENABLED",
  "agentWebhookIntegration": {
    "webhookUri": "https://myrbmserviceendpoint.somewhere.com/callback"
  }
}

ค้นหาการผสานรวมเว็บฮุคของ Agent

คุณเรียกข้อมูลรายการการผสานรวมเว็บฮุคทั้งหมดที่เป็นของ Agent ได้ ในทางปฏิบัติ ตัวแทน RBM มีการผสานรวมเว็บฮุคเพียงรายการเดียวเท่านั้น

Node.js


const businessCommunicationsApiHelper =
  require('@google/rbm-businesscommunications');

const privateKey =
  require('../../resources/businesscommunications-service-account-credentials.json');

businessCommunicationsApiHelper.initBusinessCommunucationsApi(privateKey);

businessCommunicationsApiHelper
  .listAgentIntegrations(agent.name)
  .then((response) => {
    console.log(JSON.stringify(response.data, null, 2));
    datastore.saveJsonData('integrations', response.data);
  }).catch((err) => {
    console.log(err);
  });

โค้ดนี้จะแสดงรายการการผสานรวมเว็บฮุคของ Agent ดังนี้

{
  "integrations": [
    {
      "name": "brands/40bd963f-ff92-425c-b273-8f0892d2d017/agents/my_new_agent_hfaoplpu_agent/integrations/4efdb82f-fd6d-4ba4-8ea3-f2f4a60d1547",
      "status": "ENABLED",
      "agentWebhookIntegration": {
        "webhookUri": "https://myrbmserviceendpoint.somewhere.com/callback"
      }
    }
  ]
}

ค้นหารายละเอียดการผสานรวม

ระบบดึงรายละเอียดของการผสานรวมได้เนื่องจากมีการอ้างอิงไปยังการผสานรวม

Node.js


const businessCommunicationsApiHelper =
  require('@google/rbm-businesscommunications');

const privateKey =
  require('../../resources/businesscommunications-service-account-credentials.json');

businessCommunicationsApiHelper.initBusinessCommunucationsApi(privateKey);

businessCommunicationsApiHelper
  .getAgentIntegration(integrations.integrations[0].name)
  .then((response) => {
    console.log(JSON.stringify(response.data, null, 2));
  }).catch((err) => {
    console.log(err);
  });

โค้ดนี้จะแสดงรายละเอียดการผสานรวมเว็บฮุค

{
  "name": "brands/40bd963f-ff92-425c-b273-8f0892d2d017/agents/my_new_agent_hfaoplpu_agent/integrations/4efdb82f-fd6d-4ba4-8ea3-f2f4a60d1547",
  "status": "ENABLED",
  "agentWebhookIntegration": {
    "webhookUri": "https://myrbmserviceendpoint.somewhere.com/callback"
  }
}

นำเว็บฮุคออก

คุณนำเว็บฮุคออกจาก Agent ได้โดยใช้ข้อมูลอ้างอิงต่อไปนี้

Node.js


const businessCommunicationsApiHelper =
  require('@google/rbm-businesscommunications');

const privateKey =
  require('../../resources/businesscommunications-service-account-credentials.json');

businessCommunicationsApiHelper.initBusinessCommunucationsApi(privateKey);

businessCommunicationsApiHelper
  .deleteAgentIntegration(integrations.integrations[0].name)
  .then((response) => {
    console.log(JSON.stringify(response.data, null, 2));
  }).catch((err) => {
    console.log(err);
  });

ระบบจะแสดงผลออบเจ็กต์ว่าง:

{}