Skip to contentSkip to navigationSkip to topbar
On this page

Per-Service Webhook Resource


The Per-Service Webhook resource allows you to control the effects of webhooks in a particular Conversation Service. The webhooks will only fire for activity at the service-level.

Services allow you to:

  • Create multiple, distinct environments (such as dev, stage, and prod) under a single Twilio account
  • Scope access to resources through both the REST and client APIs
  • Configure different service instances with specific behaviors

Every service can have unique webhook targets. This means you can include different metadata in the URLs or even trigger different behavior for different services.

Webhook targets for the Service Instance (the URL that Twilio will invoke) are configured in the Twilio Console.

If configured, service-scoped webhooks will override your global webhook settings such that only the service-scoped hooks will fire. This applies only to the services where service-level hooks are configured. See Conversations Webhooksfor more information.


Webhook Properties

webhook-properties page anchor
Property nameTypeRequiredDescriptionChild properties
account_sidSID<AC>Optional
Not PII

The unique ID of the Account responsible for this service.

Pattern: ^AC[0-9a-fA-F]{32}$Min length: 34Max length: 34

chat_service_sidSID<IS>Optional

The unique ID of the Conversation Service this conversation belongs to.

Pattern: ^IS[0-9a-fA-F]{32}$Min length: 34Max length: 34

pre_webhook_urlstring<uri>Optional

The absolute url the pre-event webhook request should be sent to.


post_webhook_urlstring<uri>Optional

The absolute url the post-event webhook request should be sent to.


filtersarray[string]Optional

The list of events that your configured webhook targets will receive. Events not configured here will not fire. Possible values are onParticipantAdd, onParticipantAdded, onDeliveryUpdated, onConversationUpdated, onConversationRemove, onParticipantRemove, onConversationUpdate, onMessageAdd, onMessageRemoved, onParticipantUpdated, onConversationAdded, onMessageAdded, onConversationAdd, onConversationRemoved, onParticipantUpdate, onMessageRemove, onMessageUpdated, onParticipantRemoved, onMessageUpdate or onConversationStateUpdated.


methodenum<string>Optional

The HTTP method to be used when sending a webhook request. One of GET or POST.

Possible values:
GETPOST

urlstring<uri>Optional

An absolute API resource URL for this webhook.


Fetch a ServiceWebhookConfiguration resource

fetch-a-servicewebhookconfiguration-resource page anchor
GET https://conversations.twilio.com/v1/Services/{ChatServiceSid}/Configuration/Webhooks

Path parameters

path-parameters page anchor
Property nameTypeRequiredPIIDescription
ChatServiceSidSID<IS>required

The unique ID of the Conversation Service this conversation belongs to.

Pattern: ^IS[0-9a-fA-F]{32}$Min length: 34Max length: 34
Fetch a Service WebhookLink to code sample: Fetch a Service Webhook
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function fetchServiceWebhookConfiguration() {
11
const webhook = await client.conversations.v1
12
.services("ISXXXXXXXXXXXXXXXXXXXXXX")
13
.configuration.webhooks()
14
.fetch();
15
16
console.log(webhook.accountSid);
17
}
18
19
fetchServiceWebhookConfiguration();

Output

1
{
2
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"chat_service_sid": "ISXXXXXXXXXXXXXXXXXXXXXX",
4
"pre_webhook_url": "https://www.example.com/pre",
5
"post_webhook_url": "https://www.example.com/post",
6
"filters": [
7
"onMessageRemove",
8
"onParticipantAdd"
9
],
10
"method": "POST",
11
"url": "https://conversations.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Configuration/Webhooks"
12
}

Update a ServiceWebhookConfiguration resource

update-a-servicewebhookconfiguration-resource page anchor
POST https://conversations.twilio.com/v1/Services/{ChatServiceSid}/Configuration/Webhooks

Property nameTypeRequiredPIIDescription
ChatServiceSidSID<IS>required

The unique ID of the Conversation Service this conversation belongs to.

Pattern: ^IS[0-9a-fA-F]{32}$Min length: 34Max length: 34
Encoding type:application/x-www-form-urlencoded
SchemaExample
Property nameTypeRequiredDescriptionChild properties
PreWebhookUrlstring<uri>Optional

The absolute url the pre-event webhook request should be sent to.


PostWebhookUrlstring<uri>Optional

The absolute url the post-event webhook request should be sent to.


Filtersarray[string]Optional

The list of events that your configured webhook targets will receive. Events not configured here will not fire. Possible values are onParticipantAdd, onParticipantAdded, onDeliveryUpdated, onConversationUpdated, onConversationRemove, onParticipantRemove, onConversationUpdate, onMessageAdd, onMessageRemoved, onParticipantUpdated, onConversationAdded, onMessageAdded, onConversationAdd, onConversationRemoved, onParticipantUpdate, onMessageRemove, onMessageUpdated, onParticipantRemoved, onMessageUpdate or onConversationStateUpdated.


MethodstringOptional

The HTTP method to be used when sending a webhook request. One of GET or POST.

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function updateServiceWebhookConfiguration() {
11
const webhook = await client.conversations.v1
12
.services("ISXXXXXXXXXXXXXXXXXXXXXX")
13
.configuration.webhooks()
14
.update({
15
filters: ["onConversationUpdated", "onMessageRemoved"],
16
method: "POST",
17
postWebhookUrl: "https://company.com/archive-every-action",
18
preWebhookUrl: "https://company.com/filtering-and-permissions",
19
});
20
21
console.log(webhook.accountSid);
22
}
23
24
updateServiceWebhookConfiguration();

Output

1
{
2
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"chat_service_sid": "ISXXXXXXXXXXXXXXXXXXXXXX",
4
"pre_webhook_url": "https://company.com/filtering-and-permissions",
5
"post_webhook_url": "https://company.com/archive-every-action",
6
"filters": [
7
"onMessageRemoved",
8
"onParticipantAdded"
9
],
10
"method": "POST",
11
"url": "https://conversations.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Configuration/Webhooks"
12
}

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.