Управление веб-перехватчиками

Все агенты, созданные с помощью 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"
  }
}

Найдите интеграцию веб-перехватчика агента

Вы можете получить список всех интеграций веб-перехватчиков, принадлежащих агенту. На практике агент 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);
  });

Этот код возвращает список интеграций веб-перехватчиков агента:

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

Удаление вебхука

Вебхук можно удалить из агента, используя его ссылку:

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

Возвращается пустой объект:

{}