ניהול של webhooks

כברירת מחדל, כל הנציגים שנוצרו דרך RBM Management API משתמשים בתגובה לפעולה מאתר אחר (webhook) יחיד. התגובה לפעולה מאתר אחר (webhook) ברמת השותף מוגדרת ב-Business Communications Developer Console וחלה על כל הנציגים בחשבון השותף שלכם.

לחלופין, אפשר להשתמש ב-RBM Management API כדי להגדיר webhook ברמת הסוכן. כדאי להשתמש באפשרות הזו אם אתם מנהלים כמה נציגים עם התנהגות ייחודית.

קטעי הקוד שבדף הזה נלקחים מדוגמאות Java ומדוגמאות של Node.js.

יצירת שילוב של תגובה לפעולה מאתר אחר (webhook)

כדי להוסיף שילוב של תגובה לפעולה מאתר אחר (webhook) של נציג, קודם צריך להגדיר את כתובת ה-URL של ה-webhook ולהגדיר אסימון אימות. לאחר מכן מגדירים את התגובה לפעולה מאתר אחר (webhook) כך שיפעלו לפי שלבי האימות. אחרי ההגדרה, קוראים לשיטה 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);
  }
);

הקוד הזה מחזיר את האובייקט החדש של ה-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).

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"
      }
    }
  ]
}

חיפוש פרטים של שילוב

בהתייחס לשילוב, ניתן לאחזר את הפרטים שלו.

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 מנציג תמיכה באמצעות ההפניה שלו:

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);
  });

מוחזר אובייקט ריק:

{}