वेबहुक मैनेज करें

RBM Management API के ज़रिए बनाए गए सभी एजेंट, सूचनाओं के लिए डिफ़ॉल्ट रूप से एक ही वेबहुक का इस्तेमाल करते हैं. यह पार्टनर-लेवल का वेबहुक, RCS for Business Developer Console में कॉन्फ़िगर किया गया है. यह आपके पार्टनर खाते के सभी एजेंट पर लागू होता है.

इसके अलावा, एजेंट-लेवल के वेबहुक को कॉन्फ़िगर करने के लिए, RBM Management API का इस्तेमाल किया जा सकता है. अगर आपको अलग-अलग तरह के व्यवहार वाले कई एजेंट मैनेज करने हैं, तो यह एक अच्छा विकल्प हो सकता है.

इस पेज पर दिए गए कोड स्निपेट, Java के सैंपल और Node.js के सैंपल से लिए गए हैं.

वेबबुक इंटिग्रेशन बनाना

एजेंट वेबहुक इंटिग्रेशन जोड़ने के लिए, सबसे पहले अपने वेबहुक के लिए यूआरएल तय करें. इसके बाद, मंज़ूरी वाला कोड तय करें. इसके बाद, पुष्टि करने के चरणों का पालन करने के लिए, वेबुक कॉन्फ़िगर करें. कॉन्फ़िगर करने के बाद, यूआरएल और टोकन की वैल्यू के साथ createWebhookIntegration तरीके को कॉल करें. अगर कॉल कनेक्ट हो जाता है, तो आने वाले मैसेज की पुष्टि करने और उन्हें मैनेज करने की प्रोसेस शुरू करें.

ज़्यादा जानकारी के लिए, brands.agents.integrations और 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);
  }
);

यह कोड, नया वेबहुक ऑब्जेक्ट दिखाता है:

{
  "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 देखें.

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

इस कोड से, एजेंट के वेबहुक इंटिग्रेशन की सूची मिलती है:

{
  "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 देखें.

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

यह कोड, वेबहुक इंटिग्रेशन की जानकारी दिखाता है:

{
  "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 देखें.

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

खाली ऑब्जेक्ट दिखाया जाता है:

{}