RBM Management API를 통해 생성된 모든 에이전트는 기본적으로 알림에 단일 웹훅을 사용합니다. 이 파트너 수준 웹훅은 비즈니스 커뮤니케이션 개발자 콘솔에서 구성되며 파트너 계정 내의 모든 상담사에게 적용됩니다.
또는 RBM Management API를 사용하여 에이전트 수준 웹훅을 구성할 수 있습니다. 고유한 행동으로 여러 상담사를 관리하는 경우 이 옵션이 유용할 수 있습니다.
이 페이지의 코드 스니펫은 자바 샘플 및 Node.js 샘플에서 가져온 것입니다.
웹훅 통합 만들기
에이전트 웹훅 통합을 추가하려면 먼저 웹훅의 URL을 정의하고 검증 토큰을 정의합니다. 그런 다음 유효성 검사 단계를 따르도록 웹훅을 구성합니다.
구성이 완료되면 URL 및 토큰 값을 사용하여 createWebhookIntegration
메서드를 호출합니다. 호출이 성공하면 수신 메시지 확인 및 처리를 진행할 수 있습니다.
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); });
빈 객체가 반환됩니다.
{}