Webhooks verwalten

Alle Agents, die über die RBM Management API erstellt werden, verwenden standardmäßig einen einzelnen Webhook für Benachrichtigungen. Dieser Webhook auf Partnerebene wird in der Business Communications Developer Console konfiguriert und gilt für alle Agents in Ihrem Partnerkonto.

Alternativ können Sie mit der RBM Management API Webhooks auf Agent-Ebene konfigurieren. Dies kann eine gute Option sein, wenn Sie mehrere Agents mit unterschiedlichem Verhalten verwalten.

Die Code-Snippets auf dieser Seite stammen aus den Java-Beispielen und Node.js-Beispielen.

Webhook-Integration erstellen

Wenn Sie eine Agent-Webhook-Integration hinzufügen möchten, definieren Sie zuerst die URL für den Webhook und ein Validierungstoken. Konfigurieren Sie dann den Webhook so, dass er die Validierungsschritte ausführt. Rufen Sie nach der Konfiguration die Methode createWebhookIntegration mit den URL- und Tokenwerten auf. Wenn dieser Aufruf erfolgreich ist, können Sie mit der Überprüfung und Verarbeitung eingehender Nachrichten fortfahren.

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

Dieser Code gibt das neue Webhook-Objekt zurück:

{
  "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-Integrationen eines Agents suchen

Sie können eine Liste aller Webhook-Integrationen abrufen, die zu einem Agent gehören. In der Praxis hat ein RBM-Agent immer nur einen einzigen Webhook.

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

Dieser Code gibt eine Liste der Webhook-Integrationen des Agents zurück:

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

Details zu einer Integration suchen

Anhand des Verweises auf eine Integration können die zugehörigen Details abgerufen werden.

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

Dieser Code gibt die Details zur Webhook-Integration zurück:

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

Ein Webhook kann mithilfe seiner Referenz aus einem Agent entfernt werden:

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

Ein leeres Objekt wird zurückgegeben:

{}