RBM Management API aracılığıyla oluşturulan tüm temsilciler, varsayılan olarak bildirimler için tek bir webhook kullanır. Bu iş ortağı düzeyindeki 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, temsilci düzeyinde webhook'ları yapılandırmak için RBM Management API'yi de kullanabilirsiniz. Farklı davranışları olan birden fazla müşteri temsilcisi yönetiyorsanız bu seçenek iyi bir tercih olabilir.
Bu sayfadaki kod snippet'leri Java örneklerinden ve Node.js örneklerinden alınmıştır.
Webhook entegrasyonu oluşturma
Temsilci webhook entegrasyonu eklemek için önce webhook'unuzun URL'sini ve doğrulama jetonunu tanımlayın. Ardından doğrulama adımlarını uygulayacak şekilde webhook'u yapılandırın.
Yapılandırdıktan sonra, URL ve jeton değerlerini kullanarak createWebhookIntegration
yöntemini çağırın. Bu arama başarılı olursa gelen mesajları doğrulamaya ve işlemeye devam edebilirsiniz.
Daha fazla bilgi için brands.agents.integrations
ve brands.agents.integrations.create
başlıklı makaleleri inceleyin.
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 temsilciye ait tüm webhook entegrasyonlarının listesini alabilirsiniz.
Uygulamada, bir RBM aracısının yalnızca tek bir webhook entegrasyonu vardır. Daha fazla bilgi için brands.agents.integrations.list
başlıklı makaleyi inceleyin.
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"
}
}
]
}
Bir entegrasyonla ilgili ayrıntıları arama
Bir entegrasyona referansınız varsa entegrasyon ayrıntılarını alabilirsiniz. Daha fazla bilgi için brands.agents.integrations.get
başlıklı makaleyi inceleyin.
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'u kaldırma
Referansını kullanarak bir webhook'u müşteri temsilcisinden kaldırabilirsiniz. Daha fazla bilgi için brands.agents.integrations.delete
başlıklı makaleyi inceleyin.
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:
{}