Quản lý webhook

Theo mặc định, tất cả các tác nhân được tạo thông qua API Quản lý RBM đều sử dụng một webhook cho thông báo. Webhook ở cấp đối tác này được định cấu hình trong RCS for Business Developer Console và áp dụng cho tất cả các tác nhân trong tài khoản đối tác của bạn.

Ngoài ra, bạn có thể sử dụng API Quản lý RBM để định cấu hình webhook ở cấp tác nhân. Đây có thể là một lựa chọn phù hợp nếu bạn quản lý nhiều tác nhân có hành vi riêng biệt.

Các đoạn mã trên trang này được lấy từ các mẫu Java và các mẫu Node.js.

Tạo mối liên kết tích hợp webhook

Để thêm chế độ tích hợp webhook của nhân viên hỗ trợ, trước tiên, hãy xác định URL cho webhook và xác định mã thông báo xác thực. Sau đó, hãy định cấu hình webhook để làm theo các bước xác thực. Sau khi định cấu hình, hãy gọi phương thức createWebhookIntegration bằng các giá trị URL và mã thông báo. Nếu lệnh gọi đó thành công, bạn có thể tiếp tục xác minh và xử lý tin nhắn đến.

Để biết thêm thông tin, hãy xem brands.agents.integrations và 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);
  }
);

Đoạn mã này trả về đối tượng webhook mới:

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

Tra cứu các mối liên kết tích hợp webhook của một nhân viên hỗ trợ

Bạn có thể truy xuất danh sách tất cả các chế độ tích hợp webhook thuộc về một tác nhân. Trên thực tế, một tác nhân RBM chỉ có một chế độ tích hợp webhook duy nhất. Để biết thêm thông tin chi tiết, hãy xem 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);
  });

Mã này trả về danh sách các chế độ tích hợp webhook của nhân viên hỗ trợ:

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

Tra cứu thông tin chi tiết về một hoạt động tích hợp

Bạn có thể truy xuất thông tin chi tiết về hoạt động tích hợp nếu có thông tin tham chiếu đến một hoạt động tích hợp. Để biết thêm thông tin, hãy xem 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);
  });

Mã này trả về thông tin chi tiết về việc tích hợp 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"
  }
}

Xoá webhook

Bạn có thể xoá một webhook khỏi một tác nhân bằng cách sử dụng thông tin tham chiếu của webhook đó. Để biết thêm thông tin chi tiết, hãy xem 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);
  });

Một đối tượng trống sẽ được trả về:

{}