Intended Audience:
- Admins
- Marketers
- Service/Support
Billing Plan: Playbook Webhooks are available on the Advanced and Enterprise plans only.
In general, a webhook is an HTTP request that sends data to a specific URL when an event is triggered by a web app. Using a webhook in your playbook allows your Drift bot to send and receive data from a third party application without interrupting the conversation flow. A Playbook Webhook is a playbook skill (similar to Book a meeting, or Email Capture) that triggers a webhook from Drift to an endpoint of your choosing whenever a site visitor reaches the webhook node while engaging with the bot. There are two types of webhooks available within the playbook skill: Configurable and Standard. The differences between the two types is detailed below.
For customers, webhooks are useful to provide unique and engaging experiences via the Drift Chat.
For marketers, webhooks can be used to fetch information from external resources to build dynamic qualification experiences for prospects visiting your website.
For service or support specialists, webhooks can be used to lookup customer input and return accurate and personalized responses, like an account status. Thus deflecting more simple requests from customers so that support specialists can focus on true technical support needs.
The Webhook node is located within the playbook builder. To find the Webhook node:
-
Click the Playbooks > Chat playbooks > select the playbook where you would like to use the webhook.
-
Within the playbook builder, scroll down on the nodes tab to the external data section.
How to Use a Webhook in a Playbook
To use a Webhook in your playbook, drag the Webhook skill from the left side of the screen and place it in your playbook flow. Click into the skill and enter your Webhook URL into the composer bar. Select the webhook type: Standard or Configurable. The Standard type webhook is less complex but has limited configurability.

- If you don’t need to modify the data package or request method of the request Drift sends to your endpoint when the webhook fires
- If you have complete control over the server’s response to the Drift webhook (ie. you own the server and the code responsible for building the response)
- If you don’t have complete control over the server’s response to the Drift webhook (ie. you’re querying a third party API)
- If your endpoint requires something other than POST requests
- If the JSON payload sent to your endpoint must meet specific requirements
More details on how to use each type are included below.
Standard type webhooks have less configuration options within the Drift platform than the configurable type. For example, the Standard type webhook payload sent via the request body will always be a JSON object that includes the following:
{
name: '_qx2gqutl5', //assigned by Drift for each webhook
orgId: 123456, //this is your orgId
contactId: 11003024508,
conversationId: 2502924521,
playbookId: 1122741442
}
Clicking Show advanced options allows you to set the following for your Webhook:
- Method - The default method is POST. POST request are used to send data to a server from a specified resource. Your API endpoint must be capable of receiving and processing POST requests.
- Retry - The number of times Drift will retry if the webhook fails.
- Timeout - How long Drift will wait to receive results before the webhook is considered a failure.
Note: The Timeout setting is not affected by the number of retries set. A retry does not reset the timeout clock. The maximum timeout setting is 9.5 seconds.
After clicking save, click the Outputs tab to configure what happens when the webhook either succeeds or fails.
A successful output proceeds to the next node in the playbook and therefore requires no configuration.
The behavior of a successful webhook is determined by data received in the response from the endpoint you provided. For details on how to configure the API response, see the Configuring your API’s response section below.
For failed webhook requests, the bot can respond with a failure message if desired. Click the Failure output to configure your bot’s response.
The endpoint response can be used to:
- Add or update a value on a contact attribute of the current site visitor’s Contact record in Drift
- Insert one or more messages into the conversation before proceeding to the next node in the playbook
- Assign one or more Conversation Tags to the conversation
In order for the Webhook skill to understand the endpoint’s response, responses must be sent in JSON and be structured as shown below:
{
"sendMessages": [
{
"type": "CHAT",
"body": "Hello from the webhook"
},
{
"type": "CHAT",
"body": "Your order status is: shipped"
}
],
"setContactAttributes": {
"first": "value",
"second": 10,
"third": false
},
"setConversationTags": [ 123456, 343434 ]
}
The top level objects of sendMessages, setContactAttributes, and setconversationTags are not required, however without values in these objects, the webhook will not return any data to the conversation or contact and the playbook will proceed to the next node. You may intentionally return an empty payload if your use of the webhook is to trigger external processes that can run asynchronously from the remaining playbook nodes. However, your endpoint must still return a valid response and payload (even if empty) or the webhook skill will consider its attempt a failure and the failure path will execute.
Note: You must use the API name of the contact attributes you want the webhook to update. The API name in Drift is almost always the display name converted to snake_case. For example, to update the contact attribute field “First Name” in your webhook response, use “first_name” in the setContactAttributes object of your endpoint’s response.
Note: To apply tags to the conversation, you must provide the Tag Id for the desired tag. Contact your Drift customer team if you need help finding your Tag Ids.
The playbook Standard type webhook is a powerful tool to add functionality to your playbooks. In order to fully leverage the feature you must control the API endpoint to which the Playbook Webhook sends data in order to form the responses as described in the previous section. This will likely require help from your dev team to configure. Services such as Zapier and Pipedream offer quick setup of endpoint URLs. For a deeper dive into what can be done with Playbook Webhooks, check out our developer guide here.
Configurable type webhooks allow your webhook skill to send and receive data from API endpoints that you either do not control or have limited ability to modify in order to adhere to the strict formatting requirements of the Standard type webhook. Unlike the Standard type webhook, Configurable type webhooks do not have a default request body- you must build the request body for each Configurable type webhook. Select the Configurable type webhook radio button to expose the options to send additional parameters and construct your webhooks Request body.
First, decide what data should be included in the request body. The webhook can access contact attributes and/or the responses from the site visitor to previous question nodes in your playbook. Click on the
next to either Add contact attribute or Add previous chat message. Then enter a key value and select the appropriate data source. The key value may be any string you desire to clearly label each entry.
Once you’ve labeled the key and selected the source for each data point desired for the request, you can construct the webhook Request body. The body must conform to valid JSON. Use double curly brackets - {{ key_name }} - to refer to the parameters you labeled. The double curly brackets are used by Drift’s templating language, Jinja, to interpret variables. For more details on how to use Jinja jump to Using the Jinja Templating Language. Here’s an example:
Please note that the key names you create in the left column are case-sensitive and must be referred to exactly as they are written when used in the Request body.
Pre-defined parameter keys allow you to access the same default parameters sent in the Request body of the Standard Type webhook. They include:
- orgId
- conversationId
- contactId
- playbookId
- skillName
These parameters do not need to be declared in the parameter mapping and are available to use by default. For example, to send the conversationId in your webhook’s request body, simply use the curly bracket notation to reference conversationId:
{"conversationId": {{ conversationId }} }
Click Show advanced options to modify the webhook method, number of retries and timeout options.
While the Standard type webhook requires a strictly formatted response from your webhook endpoint, the Configurable type webhook can extract data from the webhook response regardless of how the response is shaped. To configure data extraction, click on the Outputs tab, then the Success button.
The webhook can extract data using either JSON parsing or Regular Expression notation (REGEX). If your endpoint does not return data as JSON, you must use REGEX to extract data.
Using JSON to Extract Response Data
If your API endpoint returns data to the playbook webhook in a JSON format you can easily parse this data to be used in Drift. Simply map the JSON values to keys of your own choosing. Refer to the JSON object with the $ notation. As an example, assume your endpoint returns a JSON object such as:
{
"key1": "key1 value",
"key2": [
"key2 value 1",
"key2 value 2"
],
"key3": {
"subKey1": "key3 subKey1 value",
"subKey2": "key3 subKey2 value"
}
}
To reference these values in the Success configuration pane, use the notation as shown below:
If your API endpoint does not return JSON, you can use regular expressions to extract data as necessary. As an example, assume your endpoint returns only a string of “Order status is: Delivered” and you only want to present the status (ie, the text after the : character) to the site visitor. This is possible using REGEX as shown below.
Please note, while REGEX can be powerful, the webhook extractor is limited to expressions of only one capture group. To reference the extracted values from your endpoint’s response, use the double curly brackets notation as shown above.
To assign any of the values extracted from the endpoint response, whether using JSON or REGEX extraction, simply map your extractor key to the Drift Contact attribute.
Why does the webhook skill use double curly brackets to refer to dynamic values? Within the Playbook builder, Drift uses the Jinja templating language to power the delivery of dynamic text at the time of execution of the playbook node. You likely have seen Jinja in templated playbook message nodes where it is commonly used to include personalization tokens in a message and provide an alternate value if a particular contact attribute is unknown. For example:
Jinja can be particularly useful when implementing webhooks as you may not know exactly what your endpoint will return. Jinja can help process responses with conditional logic. For example, assume your endpoint is looking for an order status. If the order number is found and can return a status, you want to deliver the status to the site visitor (as in the example above). But what if the order number isn’t found and your endpoint returns a message saying such. Using Jinja, you can conditionally determine what message is displayed to a site visitor. In this example, assume your order status endpoint can return a JSON payload that looks like this when an order status is found:
"orderLookup": "success",
"orderStatus": "Delivered"}
Or like this if no order is found:
{
"orderLookup": "fail",
"failReason": "Order number not found"
}
To handle these responses in the configurable webhook node, use Jinja templating as shown below:
The templated response will first check the value of requestStatus and display the following when requestStatus = “success”:
And the following when requestStatus = “fail”:
Another feature of the Jinja templating language is the ability to apply filters to Jinja variables. This is useful for situations where you may need to control the formatting of a variable either before it is sent to your Webhook’s endpoint in the request body, or later, in the Webhook response when extracting a value.
Consider the scenario where a value entered by the site visitor in a Drift conversation is sent to your Webhook endpoint and your endpoint is expecting a valid JSON object. If the site visitor enters a value that contains invalid JSON characters, your endpoint may fail. To automatically escape any invalid JSON characters from a value passed in the request body you can use the “escapejson” Jinja filter. Your request body might look like the following:
{
"customer_name": "{{name | escapejson }}",
"customer_responses": [
"{{response1 | escapejson}}",
"{{response2 | escapejson}}",
"{{response3 | escapejson}}"
}
Filters can also be chained together to apply multiple filters to a single variable as needed. For example, to format a “name” value before presenting it to a site visitor, you may want to use filters to replace any unwanted characters and apply title case to the string. For example, in your response to the site visitor you could use:
Hi "{{name | replace("_", " ") | title}}"In the above example, a name value of “ronnie_robot” would be converted to “Ronnie Robot” by the Jinja filters before being presented to the site visitor in the Drift conversation. For more information and assistance with implementing Jinja filters, please reach out to Drift support.
Testing Your Webhook
Once you have an endpoint established that can return JSON payloads formatted correctly, you can test the configuration from within the playbook webhook node.
From within the Webhook configuration modal, click on the Test Connection tab.
Add a name for your test and dummy values for ContactId and ConversationId. The results of the test are displayed at the bottom of the modal.
Your endpoint’s response should include the following headers to ensure the test feature can receive data:
Access-Control-Allow-Origin: "https://app.drift.com"
Access-Control-Allow-Headers: "Origin, Content-Type"
The Playbook Webhook must receive a response from the given endpoint within 9.5 seconds or the playbook will continue to the next skill. Additionally, the Playbook Webhook payload cannot be altered.
Responses from your proxy server must be less than 8mb.
If additional information about the conversation or site visitor are needed, your proxy server can use the Drift Developer API to send or retrieve additional data from/to Drift.
Messages sent into the conversation from the Webhook response must be plain text. However, once a Playbook Webhook has returned data, the native features of the Playbook builder (such as conditional branches and personalization tokens) can be used to create a wide range of experiences that depend on the result of the Webhook’s response.
There is no authentication feature on the outbound POST request from the Drift Playbook Webhook which requires your proxy server endpoint to accept all requests.