כברירת מחדל, כל הנציגים שנוצרו באמצעות RBM Management API משתמשים ב-webhook אחד לקבלת התראות. ה-webhook ברמת השותף הזה מוגדר במסוף הפיתוח של Business Communications, והוא חל על כל הנציגים בחשבון השותף.
לחלופין, אפשר להשתמש ב-RBM Management API כדי להגדיר webhooks ברמת הסוכנות. זו יכולה להיות אפשרות טובה אם אתם מנהלים כמה סוכני תמיכה עם התנהגות שונה.
קטעי הקוד שבדף הזה לקוחים מדוגמאות Java ודוגמאות Node.js.
יצירת שילוב של webhook
כדי להוסיף שילוב של webhook של סוכן, קודם צריך להגדיר את כתובת ה-URL של ה-webhook ואז להגדיר אסימון אימות. לאחר מכן מגדירים את ה-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); } );
הקוד הזה מחזיר את אובייקט ה-webhook החדש:
{
"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"
}
}
חיפוש שילובי webhook של נציג
אפשר לאחזר רשימה של כל השילובים של ה-webhook ששייכים לסוכנות.
בפועל, לנציג RBM יש רק שילוב אחד של webhook. למידע נוסף, ראו 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); });
הקוד הזה מחזיר רשימה של שילובי ה-webhook של הנציג:
{
"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); });
הקוד הזה מחזיר את פרטי השילוב של ה-webhook:
{
"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"
}
}
הסרת webhook
אפשר להסיר webhook מנציג באמצעות המזהה שלו. למידע נוסף, ראו 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); });
מוחזר אובייקט ריק:
{}