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:
- Open the Business Communications Developer Console and sign in with your Business Messages Google account.
- Open the Account settings.
- Make sure the correct partner account is selected.
- For Business Messages webhook URL, click Configure.
- For Webhook endpoint URL, enter your application's URL + "/callback/". For example, it might be something like "https://PROJECT_ID.appspot.com/callback/".
- Note your
clientToken
value. You need it to verify that messages you receive are coming from Google. Configure your webhook to accept a POST request with the specified
clientToken
parameter and send a200 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, ifclientToken
is correct, return a200 OK
response with0123456789
as the response body.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.
- Open the Business Communications Developer Console and sign in with your Business Messages Google account.
- Click your agent.
- Click Integrations.
- For Webhook, click Configure.
- For Webhook endpoint URL, enter your webhook's URL, beginning with "https://".
- Note your
clientToken
value. You need it to verify that messages you receive are coming from Google. 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, ifclientToken
is correct, return a200 OK
response with the secret URL parameter set to0123456789
.In the console, click Verify. When Business Messages verifies your webhook, the dialog closes.