Kelola webhook

Semua agen yang dibuat melalui RBM Management API menggunakan satu webhook untuk pemberitahuan secara default. Webhook tingkat partner ini dikonfigurasi di Konsol Developer Business Communications dan berlaku untuk semua agen dalam akun partner Anda.

Atau, Anda dapat menggunakan RBM Management API untuk mengonfigurasi webhook tingkat agen. Opsi ini mungkin merupakan opsi yang baik jika Anda mengelola beberapa agen dengan perilaku yang berbeda.

Cuplikan kode di halaman ini diambil dari contoh Java dan contoh Node.js.

Membuat integrasi webhook

Untuk menambahkan integrasi webhook agen, tentukan URL untuk webhook Anda terlebih dahulu dan tentukan token validasi. Kemudian, konfigurasikan webhook untuk mengikuti langkah-langkah validasi. Setelah dikonfigurasi, panggil metode createWebhookIntegration dengan nilai URL dan token. Jika panggilan tersebut berhasil, Anda dapat melanjutkan dengan memverifikasi dan menangani pesan masuk.

Untuk detail selengkapnya, lihat brands.agents.integrations dan 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);
  }
);

Kode ini menampilkan objek webhook baru:

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

Mencari integrasi webhook agen

Anda dapat mengambil daftar semua integrasi webhook milik agen. Dalam praktiknya, agen RBM hanya memiliki satu integrasi webhook. Untuk detail selengkapnya, lihat 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);
  });

Kode ini menampilkan daftar integrasi webhook agen:

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

Mencari detail integrasi

Anda dapat mengambil detail integrasi jika memiliki referensi ke integrasi. Untuk detail selengkapnya, lihat 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);
  });

Kode ini menampilkan detail integrasi 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"
  }
}

Menghapus webhook

Anda dapat menghapus webhook dari agen menggunakan referensinya. Untuk detail selengkapnya, lihat 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);
  });

Objek kosong akan ditampilkan:

{}