Conversation Scoped Webhook Resource
Conversation Scoped Webhooks provide a way to attach a unique monitor, bot, or other integration to each conversation.
Each individual Conversation can have as many as five such webhooks, as needed for your use case. This is your go-to tool for adding integrations with third-party bots or Twilio Studio.
For bot integrations, in particular, pay specific attention to the ReplayAfter parameter to ensure that you don't miss any messages that arrive while you're configuring the integration.
Info
Only post-event webhooks are supported by the Conversation-Scoped Webhooks.
All URLs in the reference documentation use the following base URL:
https://conversations.twilio.com/v1
Using the REST API, you can interact with Conversation Scoped Webhook resources in the default Conversation Service instance via a "shortened" URL that does not include the Conversation Service instance SID ("ISXXX..."). If you are only using one Conversation Service (the default), you do not need to include the Conversation Service SID in your URL, e.g.
1GET /v1/Conversations/CHxxx/Webhooks2
For Conversations applications that build on more than one Conversation Service instance, you will need to specify the Conversation Service SID in the REST API call:
GET /v1/Services/ISxx/Conversations/CHxx/Webhooks
A 34 character string that uniquely identifies this resource.
^WH[0-9a-fA-F]{32}$Min length: 34Max length: 34The unique ID of the Account responsible for this conversation.
^AC[0-9a-fA-F]{32}$Min length: 34Max length: 34The unique ID of the Conversation for this webhook.
^CH[0-9a-fA-F]{32}$Min length: 34Max length: 34The date that this resource was last updated.
POST https://conversations.twilio.com/v1/Conversations/{ConversationSid}/Webhooks
The unique ID of the Conversation for this webhook.
application/x-www-form-urlencodedThe target of this webhook: webhook, studio, trigger
webhooktriggerstudioThe list of events, firing webhook event for this Conversation.
The list of keywords, firing webhook event for this Conversation.
The studio flow SID, where the webhook should be sent to.
^FW[0-9a-fA-F]{32}$Min length: 34Max length: 34The message index for which and it's successors the webhook will be replayed. Not set by default
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function createConversationScopedWebhook() {11const webhook = await client.conversations.v112.conversations("ConversationSid")13.webhooks.create({14"configuration.filters": ["onMessageAdded", "onConversationRemoved"],15"configuration.method": "get",16"configuration.url": "https://example.com",17target: "webhook",18});1920console.log(webhook.sid);21}2223createConversationScopedWebhook();
Response
1{2"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"conversation_sid": "ConversationSid",4"sid": "WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",5"target": "webhook",6"configuration": {7"url": "https://example.com",8"method": "get",9"filters": [10"onMessageSent",11"onConversationDestroyed"12]13},14"date_created": "2016-03-24T21:05:50Z",15"date_updated": "2016-03-24T21:05:50Z",16"url": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks/WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"17}
GET https://conversations.twilio.com/v1/Conversations/{ConversationSid}/Webhooks/{Sid}
A 34 character string that uniquely identifies this resource.
^WH[0-9a-fA-F]{32}$Min length: 34Max length: 341// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function fetchConversationScopedWebhook() {11const webhook = await client.conversations.v112.conversations("ConversationSid")13.webhooks("WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")14.fetch();1516console.log(webhook.sid);17}1819fetchConversationScopedWebhook();
Response
1{2"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"conversation_sid": "ConversationSid",4"sid": "WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",5"target": "studio",6"configuration": {7"flow_sid": "FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"8},9"date_created": "2016-03-24T21:05:50Z",10"date_updated": "2016-03-24T21:05:50Z",11"url": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks/WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"12}
GET https://conversations.twilio.com/v1/Conversations/{ConversationSid}/Webhooks
The unique ID of the Conversation for this webhook.
How many resources to return in each list page. The default is 5, and the maximum is 5.
1Maximum: 5The page token. This is provided by the API.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function listConversationScopedWebhook() {11const webhooks = await client.conversations.v112.conversations("ConversationSid")13.webhooks.list({ limit: 20 });1415webhooks.forEach((w) => console.log(w.sid));16}1718listConversationScopedWebhook();
Response
1{2"meta": {3"page": 0,4"page_size": 5,5"first_page_url": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks?PageSize=5&Page=0",6"previous_page_url": null,7"url": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks?PageSize=5&Page=0",8"next_page_url": null,9"key": "webhooks"10},11"webhooks": [12{13"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",14"conversation_sid": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",15"sid": "WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",16"target": "webhook",17"configuration": {18"url": "https://example.com",19"method": "get",20"filters": [21"onMessageSent",22"onConversationDestroyed"23]24},25"date_created": "2016-03-24T21:05:50Z",26"date_updated": "2016-03-24T21:05:50Z",27"url": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks/WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"28},29{30"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",31"conversation_sid": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",32"sid": "WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",33"target": "trigger",34"configuration": {35"url": "https://example.com",36"method": "post",37"filters": [38"keyword1",39"keyword2"40]41},42"date_created": "2016-03-24T21:05:50Z",43"date_updated": "2016-03-24T21:05:50Z",44"url": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks/WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"45},46{47"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",48"conversation_sid": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",49"sid": "WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",50"target": "studio",51"configuration": {52"flow_sid": "FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"53},54"date_created": "2016-03-24T21:05:50Z",55"date_updated": "2016-03-24T21:05:50Z",56"url": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks/WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"57}58]59}
POST https://conversations.twilio.com/v1/Conversations/{ConversationSid}/Webhooks/{Sid}
A 34 character string that uniquely identifies this resource.
^WH[0-9a-fA-F]{32}$Min length: 34Max length: 34application/x-www-form-urlencodedThe list of events, firing webhook event for this Conversation.
The list of keywords, firing webhook event for this Conversation.
The studio flow SID, where the webhook should be sent to.
^FW[0-9a-fA-F]{32}$Min length: 34Max length: 341// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function updateConversationScopedWebhook() {11const webhook = await client.conversations.v112.conversations("ConversationSid")13.webhooks("WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")14.update({ "configuration.filters": ["keyword1", "keyword2"] });1516console.log(webhook.configuration);17}1819updateConversationScopedWebhook();
Response
1{2"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"conversation_sid": "ConversationSid",4"sid": "WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",5"target": "trigger",6"configuration": {7"url": "https://example.com",8"method": "post",9"filters": [10"keyword1",11"keyword2"12]13},14"date_created": "2016-03-24T21:05:50Z",15"date_updated": "2016-03-24T21:05:51Z",16"url": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks/WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"17}
DELETE https://conversations.twilio.com/v1/Conversations/{ConversationSid}/Webhooks/{Sid}
A 34 character string that uniquely identifies this resource.
^WH[0-9a-fA-F]{32}$Min length: 34Max length: 341// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function deleteConversationScopedWebhook() {11await client.conversations.v112.conversations("ConversationSid")13.webhooks("WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")14.remove();15}1617deleteConversationScopedWebhook();