تمام نمایندگانی که از طریق API مدیریت RBM ایجاد میشوند، به طور پیشفرض از یک وبهوک واحد برای اعلانها استفاده میکنند. این وبهوک در سطح شریک در کنسول توسعهدهندگان RCS برای کسبوکار پیکربندی شده است و برای همه نمایندگان موجود در حساب شریک شما اعمال میشود.
از طرف دیگر، میتوانید از API مدیریت RBM برای پیکربندی وبهوکهای سطح عامل استفاده کنید. اگر چندین عامل با رفتار متمایز را مدیریت میکنید، این میتواند گزینه خوبی باشد.
قطعه کدهای این صفحه از نمونههای جاوا و نمونههای Node.js گرفته شدهاند.
ایجاد یکپارچهسازی وبهوک
برای افزودن ادغام وبهوک عامل، ابتدا URL مربوط به وبهوک خود را تعریف کرده و یک توکن اعتبارسنجی تعریف کنید. سپس وبهوک را برای دنبال کردن مراحل اعتبارسنجی پیکربندی کنید. پس از پیکربندی، متد createWebhookIntegration را با مقادیر URL و توکن فراخوانی کنید. اگر این فراخوانی موفقیتآمیز باشد، میتوانید به تأیید و مدیریت پیامهای ورودی ادامه دهید.
برای جزئیات بیشتر، به brands.agents.integrations و brands.agents.integrations.create مراجعه کنید.
نود جی اس
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 مراجعه کنید.
نود جی اس
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 مراجعه کنید.
نود جی اس
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 مراجعه کنید.
نود جی اس
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); });
یک شیء خالی برگردانده میشود:
{}