웹훅 관리

RBM Management API를 통해 생성된 모든 에이전트는 기본적으로 알림에 단일 웹훅을 사용합니다. 이 파트너 수준 웹훅은 비즈니스용 RCS Developer Console에서 구성되며 파트너 계정 내의 모든 에이전트에 적용됩니다.

또는 RBM Management API를 사용하여 에이전트 수준 웹훅을 구성할 수 있습니다. 동작이 서로 다른 여러 에이전트를 관리하는 경우 이 옵션이 적합할 수 있습니다.

이 페이지의 코드 스니펫은 Java 샘플 및 Node.js 샘플에서 가져온 것입니다.

웹훅 통합 만들기

에이전트 웹훅 통합을 추가하려면 먼저 웹훅의 URL을 정의하고 인증 토큰을 정의합니다. 그런 다음 유효성 검사 단계를 따르도록 웹훅을 구성합니다. 구성되면 URL 및 토큰 값을 사용하여 createWebhookIntegration 메서드를 호출합니다. 이 호출이 성공하면 수신 메시지 확인 및 처리를 진행할 수 있습니다.

자세한 내용은 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);
  });

빈 객체가 반환됩니다.

{}