Webhook'ları yönetme

RBM Management API aracılığıyla oluşturulan tüm temsilciler, bildirimler için varsayılan olarak tek bir webhook kullanır. Bu iş ortağı düzeyinde webhook, Business Communications Developer Console'da yapılandırılır ve iş ortağı hesabınızdaki tüm temsilciler için geçerlidir.

Alternatif olarak, aracı düzeyinde webhook'ları yapılandırmak için RBM Management API'yi kullanabilirsiniz. Farklı davranışlara sahip birden fazla aracıyı yönetiyorsanız bu iyi bir seçenek olabilir.

Bu sayfadaki kod snippet'leri Java örneklerinden ve Node.js örneklerinden alınmıştır.

Webhook entegrasyonu oluşturma

Aracı webhook entegrasyonu eklemek için önce webhook'unuzun URL'sini tanımlayın ve bir doğrulama jetonu tanımlayın. Ardından, webhook'u doğrulama adımlarını uygulayacak şekilde yapılandırın. Yapılandırıldığında, URL ve jeton değerleriyle createWebhookIntegration yöntemini çağırın. Bu arama başarılı olursa gelen iletileri doğrulama ve işleme işlemiyle devam edebilirsiniz.

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);
  }
);

Bu kod yeni webhook nesnesini döndürür:

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

Temsilcinin webhook entegrasyonlarını arama

Bir aracıya ait olan tüm webhook entegrasyonlarının listesini alabilirsiniz. Pratikte, bir RBM aracısının yalnızca tek bir webhook entegrasyonu vardır.

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);
  });

Bu kod, temsilcinin webhook entegrasyonlarının bir listesini döndürür:

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

Entegrasyonun ayrıntılarını arama

Bir entegrasyona referans verildiğinde ayrıntıları alınabilir.

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);
  });

Bu kod webhook entegrasyon ayrıntılarını döndürür:

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

Webhook kaldırma

Webhook, referansı kullanılarak bir aracıdan kaldırılabilir:

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);
  });

Boş bir nesne döndürülür:

{}