Set your webhook

A webhook is a partner-created HTTPS callback that specifies how your agent should respond to messages and events. Unless you're using a pre-built automated solution like Dialogflow, you need to set a custom webhook to define the behavior for your agent.

Partner-level and agent-level webhooks

You can set your webhook either at the partner level or at the agent level. Partner-level webhooks apply to every agent you maintain, while agent-level webhooks each apply to one individual agent.

If you operate multiple agents with distinct behavior, you may wish to set a different webhook for each agent using the agent-level setting. On the other hand, if your agents have similar behavior, or if you only have one agent, you can use the partner-level webhook.

If you have both a partner-level webhook and an agent-level webhook configured, the agent-level webhook takes precedence on its specific agent, while the partner-level webhook applies to agents that don't have an agent-level webhook.

Set your partner-level webhook

To set your partner-level webhook, follow these steps:

  1. Open the Business Communications Developer Console and sign in with your Business Messages Google account.
  2. Open the Account settings.
  3. Make sure the correct partner account is selected.
  4. For Business Messages webhook URL, click Configure.
  5. For Webhook endpoint URL, enter your application's URL + "/callback/". For example, it might be something like "https://PROJECT_ID.appspot.com/callback/".
  6. Note your clientToken value. You need it to verify that messages you receive are coming from Google.
  7. Configure your webhook to accept a POST request with the specified clientToken parameter and send a 200 OK response with the plain text value of the secret parameter as the response body. For example, suppose your webhook receives a POST request with the following body content:

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

    In that case, your webhook should confirm the clientToken value and, if clientToken is correct, return a 200 OK response with 0123456789 as the response body.

  8. In the console, click Verify. When Business Messages verifies your webhook, the dialog closes.

Set an agent-level webhook

You receive messages sent to your agent at your partner-level webhook. If you want messages for a specific agent to arrive at a different webhook instead, you can set an agent-level webhook.

  1. Open the Business Communications Developer Console and sign in with your Business Messages Google account.
  2. Click your agent.
  3. Click Integrations.
  4. For Webhook, click Configure.
  5. For Webhook endpoint URL, enter your webhook's URL, beginning with "https://".
  6. Note your clientToken value. You need it to verify that messages you receive are coming from Google.
  7. 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, suppose your webhook receives a POST request with the following body content:

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

    In that case, your webhook should confirm the clientToken value and, if clientToken is correct, return a 200 OK response with the secret URL parameter set to 0123456789.

  8. In the console, click Verify. When Business Messages verifies your webhook, the dialog closes.