ניהול של webhooks

כל הסוכנים שנוצרו באמצעות RBM Management API משתמשים בwebhook אחד כברירת מחדל לקבלת התראות. ה-webhook ברמת השותף מוגדר ב-RCS for Business Developer Console והוא חל על כל הסוכנים בחשבון השותף.

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

קטעי הקוד בדף הזה נלקחו מדוגמאות 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);
  });

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

{}