เอเจนต์ทั้งหมดที่สร้างผ่าน RBM Management API จะใช้ Webhook เดียว สำหรับการแจ้งเตือนโดยค่าเริ่มต้น เว็บฮุคระดับพาร์ทเนอร์ ได้รับการกำหนดค่าใน RCS for Business Developer Console และมีผลกับตัวแทนทั้งหมด ในบัญชีพาร์ทเนอร์
หรือจะใช้ RBM Management API เพื่อกำหนดค่าWebhook ระดับตัวแทนก็ได้ ตัวเลือกนี้อาจเหมาะกับคุณหากจัดการเอเจนต์หลายรายที่มีลักษณะการทำงานแตกต่างกัน
ข้อมูลโค้ดในหน้านี้มาจากตัวอย่าง Java และตัวอย่าง Node.js
สร้างการผสานรวมเว็บฮุค
หากต้องการเพิ่มการผสานรวมเว็บฮุคของตัวแทน ให้กําหนด URL สําหรับเว็บฮุคและกําหนดโทเค็นสําหรับตรวจสอบความถูกต้องก่อน จากนั้นกำหนดค่า Webhook ให้ทำตาม
ขั้นตอนการตรวจสอบ
เมื่อกำหนดค่าแล้ว ให้เรียกใช้เมธอด createWebhookIntegration ด้วย URL และค่าโทเค็น หากการโทรสำเร็จ คุณจะดำเนินการต่อเพื่อยืนยันและจัดการข้อความขาเข้าได้
ดูรายละเอียดเพิ่มเติมได้ที่
brands.agents.integrations
และ brands.agents.integrations.create
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"
}
}
ค้นหาการผสานรวมเว็บฮุคของตัวแทน
คุณสามารถดึงรายการการผสานรวมเว็บฮุกทั้งหมดที่เป็นของเอเจนต์ได้
ในทางปฏิบัติแล้ว เอเจนต์ RBM จะมีการผสานรวมเว็บฮุกเพียงรายการเดียวเสมอ ดูรายละเอียดเพิ่มเติมได้ที่ brands.agents.integrations.list
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); });
โค้ดนี้จะแสดงรายการการผสานรวมเว็บฮุคของตัวแทน
{
"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"
}
}
]
}
ค้นหารายละเอียดของการผสานรวม
คุณสามารถดึงรายละเอียดการผสานรวมได้หากมีข้อมูลอ้างอิงถึงการผสานรวม ดูรายละเอียดเพิ่มเติมได้ที่ brands.agents.integrations.get
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"
}
}
นำเว็บฮุคออก
คุณสามารถนำเว็บฮุกออกจากเอเจนต์ได้โดยใช้การอ้างอิงของเว็บฮุก ดูรายละเอียดเพิ่มเติมได้ที่ brands.agents.integrations.delete
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); });
ระบบจะแสดงผลออบเจ็กต์ที่ว่างเปล่า
{}