Updates: Check the release notes for new features and product updates.

Set up Cloud Pub/Sub

RBM agents receive messages and events through a publish/subscribe relationship with Cloud Pub/Sub. When a user sends a message to your agent or generates an event, their messaging app sends the information to your agent's Pub/Sub subscription, where your agent can access the message or event. See Receive messages.

The user sends a message to the agent

Your agent's Pub/Sub subscription type determines how your agent receives messages, and you need to configure your Pub/Sub subscription before your agent can receive messages. RBM agents support both pull and push subscriptions.

Pull subscription

With a pull subscription, your agent contacts Cloud Pub/Sub and fetches messages, events, and other requests.

Prerequisites

Before you get started, you need an RBM agent.

Setup

  1. Open the Business Communications Developer Console, sign in with your RBM Google account, and click your agent.
  2. In the left navigation, click Integrations.
  3. Click Edit subscription.
  4. Choose Pull, then click Save.
  5. Configure your agent to use the pull subscription:
    • If you use a sample agent with a pull subscription, follow the instructions in the sample's README file.
    • If you don't use a sample agent, see Receiving messages using Pull for code to enable your agent to use the pull subscription. Depending on your programming language, you may need your agent's project ID.

Find your project ID

Some pull subscription mechanisms require you to specify your agent's GCP project ID. Your agent's project ID is embedded in the pull subscription name following project/.

  1. Open the Business Communications Developer Console, sign in with your RBM Google account, and click your agent.
  2. In the left navigation, click Integrations.
  3. Find your agent's Subscription name.
  4. Identify the text segment between project/ and the following /. This is your agent's project ID.

    For example, if the subscription name is projects/rbm-growing-tree-bank-nbdjkl6t/subscriptions/rbm-agent-subscription, your agent's project ID is rbm-growing-tree-bank-nbdjkl6t.

Push subscription

With a push subscription, Cloud Pub/Sub pushes messages, events, and other requests to a webhook URL that you specify.

Prerequisites

Before you get started, you need the following items:

  • An RBM agent
  • A live webhook endpoint URL that supports
    • HTTPS with a valid SSL certificate
    • POST requests
    • The ability to echo a parameter in response to a validation request

Setup

  1. Open the Business Communications Developer Console, sign in with your RBM Google account, and click your agent.
  2. In the left navigation, click Integrations.
  3. Click Edit subscription.
  4. Choose Push.
  5. For Webhook endpoint URL, enter your webhook's URL, beginning with "https://".
  6. Configure your webhook to accept a POST request with the specified clientToken parameter and send a 200 OK response with the value of the secret parameter.

    For example, if your webhook receives a POST request with the following body content

    {
      "clientToken":"SJENCPGJESMGUFPY",
      "secret":"1234567890"
    }
    

    your webhook should confirm the clientToken value and, if clientToken is correct, return a 200 OK response with 1234567890 as the secret parameter.

  7. In the console, click Verify.

    When the RBM platform verifies your webhook, the Configure your webhook dialog closes.

  8. Click Save.

  9. Configure your agent to receive messages from your webhook:

    • If you use a sample agent with a push subscription, follow the instructions in the sample's README file.
    • If don't use a sample agent, configure your infrastructure to pass messages from your webhook to your agent.

Verify incoming messages

Because webhooks can receive messages from any senders, you should verify that Google sent incoming messages before processing message content.

To verify that Google sent a message you received,

  1. Parse the message's X-Goog-Signature header. This is a hashed, base64-encoded copy of the message body payload.
  2. Using your webhook's client token (which you specified when you set up your push subscription) as a key, create a SHA512 HMAC of the bytes of the message payload and base64-encode the result.
  3. Compare the X-Goog-Signature hash with the hash you created.

    • If the hashes match, you've confirmed that Google sent the message.
    • If the hashes don't match, check your hashing process on a known-good message. If your hashing process is working correctly and you receive a message that you believe was fraudulently sent to you, contact us.

Next steps

Once you configure your subscription and set up your agent to communicate with Cloud Pub/Sub, your agent can receive messages from your test devices. Send a message to validate y