Все агенты, созданные через API управления RBM, по умолчанию используют единый веб-перехватчик для уведомлений. Этот веб-перехватчик на уровне партнера настраивается в консоли разработчика RCS for Business и применяется ко всем агентам в вашей партнерской учетной записи.
В качестве альтернативы вы можете использовать API управления RBM для настройки веб-хуков на уровне агентов . Это может быть хорошим вариантом, если вы управляете несколькими агентами с различным поведением.
Приведенные на этой странице фрагменты кода взяты из примеров на Java и Node.js.
Создайте интеграцию веб-перехватчика.
Чтобы добавить интеграцию с веб-перехватчиком агента, сначала определите URL-адрес для вашего веб-перехватчика и задайте токен проверки. Затем настройте веб-перехватчик для выполнения шагов проверки . После настройки вызовите метод 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); });
Возвращается пустой объект:
{}