Skip to contentSkip to navigationSkip to topbar
On this page

Chat Service Resource


(error)

Danger

Programmable Chat has been deprecated and is no longer supported. Instead, we'll be focusing on the next generation of chat: Twilio Conversations. Find out more about the EOL process here(link takes you to an external page).

If you're starting a new project, please visit the Conversations Docs to begin. If you've already built on Programmable Chat, please visit our Migration Guide to learn about how to switch.

A Service is the top-level scope of all other resources in the Programmable Chat REST API. All other Programmable Chat resources, such as Channels, Users, Messages, and Credentials belong to a specific Service.

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

A Service can also send HTTPS requests(link takes you to an external page) to URLs that you define to let you know of specific events. See what events you can subscribe to in our webhook reference.


Twilio Console

twilio-console page anchor

You can also manage your Programmable Chat Services from your Twilio console when you are logged in.


The Service resource contains these properties.

Property nameTypeRequiredDescriptionChild properties
sidSID<IS>Optional
Not PII

The unique string that we created to identify the Service resource.

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

account_sidSID<AC>Optional

The SID of the Account that created the Service resource.

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

friendly_namestringOptional
PII MTL: 30 days

The string that you assigned to describe the resource.


date_createdstring<date-time>Optional

The date and time in GMT when the resource was created specified in ISO 8601(link takes you to an external page) format.


date_updatedstring<date-time>Optional

The date and time in GMT when the resource was last updated specified in ISO 8601(link takes you to an external page) format.


default_service_role_sidSID<RL>Optional

The service role assigned to users when they are added to the service. See the Role resource for more info about roles.

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

default_channel_role_sidSID<RL>Optional

The channel role assigned to users when they are added to a channel. See the Role resource for more info about roles.

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

default_channel_creator_role_sidSID<RL>Optional

The channel role assigned to a channel creator when they join a new channel. See the Role resource for more info about roles.

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

read_status_enabledbooleanOptional

Whether the Message Consumption Horizon feature is enabled. The default is true.


reachability_enabledbooleanOptional

Whether the Reachability Indicator is enabled for this Service instance. The default is false.


typing_indicator_timeoutintegerOptional

How long in seconds after a started typing event until clients should assume that user is no longer typing, even if no ended typing message was received. The default is 5 seconds.

Default: 0

consumption_report_intervalintegerOptional

DEPRECATED. The interval in seconds between consumption reports submission batches from client endpoints.

Default: 0

limitsobjectOptional

An object that describes the limits of the service instance. The limits object contains channel_members to describe the members/channel limit and user_channels to describe the channels/user limit. channel_members can be 1,000 or less, with a default of 250. user_channels can be 1,000 or less, with a default value of 100.


pre_webhook_urlstringOptional

The URL for pre-event webhooks, which are called by using the webhook_method. See Webhook Events for more details.


post_webhook_urlstringOptional

The URL for post-event webhooks, which are called by using the webhook_method. See Webhook Events for more details.


webhook_methodstringOptional

The HTTP method to use for calls to the pre_webhook_url and post_webhook_url webhooks. Can be: POST or GET and the default is POST. See Webhook Events for more details.


webhook_filtersarray[string]Optional

The list of webhook events that are enabled for this Service instance. See Webhook Events for more details.


pre_webhook_retry_countintegerOptional

The number of times to retry a call to the pre_webhook_url if the request times out (after 5 seconds) or it receives a 429, 503, or 504 HTTP response. Default retry count is 0 times, which means the call won't be retried.

Default: 0

post_webhook_retry_countintegerOptional

The number of times to retry a call to the post_webhook_url if the request times out (after 5 seconds) or it receives a 429, 503, or 504 HTTP response. The default is 0, which means the call won't be retried.

Default: 0

notificationsobjectOptional

The notification configuration for the Service instance. See Push Notification Configuration for more info.


mediaobjectOptional

An object that describes the properties of media that the service supports. The object contains the size_limit_mb property, which describes the size of the largest media file in MB; and the compatibility_message property, which contains the message text to send when a media message does not have any text.


urlstring<uri>Optional

The absolute URL of the Service resource.


linksobject<uri-map>Optional

The absolute URLs of the Service's Channels, Roles, Bindings, and Users.


Create a Service resource

create-a-service-resource page anchor
POST https://chat.twilio.com/v2/Services

Request body parameters

request-body-parameters page anchor
Encoding type:application/x-www-form-urlencoded
SchemaExample
Property nameTypeRequiredDescriptionChild properties
FriendlyNamestringrequired

A descriptive string that you create to describe the new resource.

Create a Service resourceLink to code sample: Create a Service resource
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 createService() {
11
const service = await client.chat.v2.services.create({
12
friendlyName: "FriendlyName",
13
});
14
15
console.log(service.sid);
16
}
17
18
createService();

Output

1
{
2
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"consumption_report_interval": 100,
4
"date_created": "2015-07-30T20:00:00Z",
5
"date_updated": "2015-07-30T20:00:00Z",
6
"default_channel_creator_role_sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
7
"default_channel_role_sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
8
"default_service_role_sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
9
"friendly_name": "FriendlyName",
10
"limits": {
11
"channel_members": 100,
12
"user_channels": 250
13
},
14
"links": {
15
"channels": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels",
16
"users": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Users",
17
"roles": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Roles",
18
"bindings": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Bindings"
19
},
20
"notifications": {},
21
"post_webhook_url": "post_webhook_url",
22
"pre_webhook_url": "pre_webhook_url",
23
"pre_webhook_retry_count": 2,
24
"post_webhook_retry_count": 3,
25
"reachability_enabled": false,
26
"read_status_enabled": false,
27
"sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
28
"typing_indicator_timeout": 100,
29
"url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
30
"webhook_filters": [
31
"webhook_filters"
32
],
33
"webhook_method": "webhook_method",
34
"media": {
35
"size_limit_mb": 150,
36
"compatibility_message": "media compatibility message"
37
}
38
}

Fetch a Service resource

fetch-a-service-resource page anchor
GET https://chat.twilio.com/v2/Services/{Sid}

Property nameTypeRequiredPIIDescription
SidSID<IS>required

The SID of the Service resource to fetch.

Pattern: ^IS[0-9a-fA-F]{32}$Min length: 34Max length: 34
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 fetchService() {
11
const service = await client.chat.v2
12
.services("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.fetch();
14
15
console.log(service.sid);
16
}
17
18
fetchService();

Output

1
{
2
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"consumption_report_interval": 100,
4
"date_created": "2015-07-30T20:00:00Z",
5
"date_updated": "2015-07-30T20:00:00Z",
6
"default_channel_creator_role_sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
7
"default_channel_role_sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
8
"default_service_role_sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
9
"friendly_name": "friendly_name",
10
"limits": {
11
"channel_members": 100,
12
"user_channels": 250
13
},
14
"links": {
15
"channels": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels",
16
"users": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Users",
17
"roles": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Roles",
18
"bindings": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Bindings"
19
},
20
"notifications": {},
21
"post_webhook_url": "post_webhook_url",
22
"pre_webhook_url": "pre_webhook_url",
23
"pre_webhook_retry_count": 2,
24
"post_webhook_retry_count": 3,
25
"reachability_enabled": false,
26
"read_status_enabled": false,
27
"sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
28
"typing_indicator_timeout": 100,
29
"url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
30
"webhook_filters": [
31
"webhook_filters"
32
],
33
"webhook_method": "webhook_method",
34
"media": {
35
"size_limit_mb": 150,
36
"compatibility_message": "media compatibility message"
37
}
38
}

Read multiple Service resources

read-multiple-service-resources page anchor
GET https://chat.twilio.com/v2/Services

Property nameTypeRequiredPIIDescription
PageSizeintegerOptional

How many resources to return in each list page. The default is 50, and the maximum is 1000.

Minimum: 1Maximum: 1000

PageintegerOptional

The page index. This value is simply for client state.

Minimum: 0

PageTokenstringOptional

The page token. This is provided by the API.

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 listService() {
11
const services = await client.chat.v2.services.list({ limit: 20 });
12
13
services.forEach((s) => console.log(s.sid));
14
}
15
16
listService();

Output

1
{
2
"meta": {
3
"first_page_url": "https://chat.twilio.com/v2/Services?PageSize=50&Page=0",
4
"key": "services",
5
"next_page_url": null,
6
"page": 0,
7
"page_size": 50,
8
"previous_page_url": null,
9
"url": "https://chat.twilio.com/v2/Services?PageSize=50&Page=0"
10
},
11
"services": []
12
}

Update a Service resource

update-a-service-resource page anchor
POST https://chat.twilio.com/v2/Services/{Sid}

Property nameTypeRequiredPIIDescription
SidSID<IS>required

The SID of the Service resource to update.

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

A descriptive string that you create to describe the resource.


DefaultServiceRoleSidSID<RL>Optional

The service role assigned to users when they are added to the service. See the Role resource for more info about roles.

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

DefaultChannelRoleSidSID<RL>Optional

The channel role assigned to users when they are added to a channel. See the Role resource for more info about roles.

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

DefaultChannelCreatorRoleSidSID<RL>Optional

The channel role assigned to a channel creator when they join a new channel. See the Role resource for more info about roles.

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

ReadStatusEnabledbooleanOptional

Whether to enable the Message Consumption Horizon feature. The default is true.


ReachabilityEnabledbooleanOptional

Whether to enable the Reachability Indicator for this Service instance. The default is false.


TypingIndicatorTimeoutintegerOptional

How long in seconds after a started typing event until clients should assume that user is no longer typing, even if no ended typing message was received. The default is 5 seconds.


ConsumptionReportIntervalintegerOptional

DEPRECATED. The interval in seconds between consumption reports submission batches from client endpoints.


Notifications.NewMessage.EnabledbooleanOptional

Whether to send a notification when a new message is added to a channel. The default is false.


Notifications.NewMessage.TemplatestringOptional

The template to use to create the notification text displayed when a new message is added to a channel and notifications.new_message.enabled is true.


Notifications.NewMessage.SoundstringOptional

The name of the sound to play when a new message is added to a channel and notifications.new_message.enabled is true.


Notifications.NewMessage.BadgeCountEnabledbooleanOptional

Whether the new message badge is enabled. The default is false.


Notifications.AddedToChannel.EnabledbooleanOptional

Whether to send a notification when a member is added to a channel. The default is false.


Notifications.AddedToChannel.TemplatestringOptional

The template to use to create the notification text displayed when a member is added to a channel and notifications.added_to_channel.enabled is true.


Notifications.AddedToChannel.SoundstringOptional

The name of the sound to play when a member is added to a channel and notifications.added_to_channel.enabled is true.


Notifications.RemovedFromChannel.EnabledbooleanOptional

Whether to send a notification to a user when they are removed from a channel. The default is false.


Notifications.RemovedFromChannel.TemplatestringOptional

The template to use to create the notification text displayed to a user when they are removed from a channel and notifications.removed_from_channel.enabled is true.


Notifications.RemovedFromChannel.SoundstringOptional

The name of the sound to play to a user when they are removed from a channel and notifications.removed_from_channel.enabled is true.


Notifications.InvitedToChannel.EnabledbooleanOptional

Whether to send a notification when a user is invited to a channel. The default is false.


Notifications.InvitedToChannel.TemplatestringOptional

The template to use to create the notification text displayed when a user is invited to a channel and notifications.invited_to_channel.enabled is true.


Notifications.InvitedToChannel.SoundstringOptional

The name of the sound to play when a user is invited to a channel and notifications.invited_to_channel.enabled is true.


PreWebhookUrlstring<uri>Optional

The URL for pre-event webhooks, which are called by using the webhook_method. See Webhook Events for more details.


PostWebhookUrlstring<uri>Optional

The URL for post-event webhooks, which are called by using the webhook_method. See Webhook Events for more details.


WebhookMethodenum<http-method>Optional

The HTTP method to use for calls to the pre_webhook_url and post_webhook_url webhooks. Can be: POST or GET and the default is POST. See Webhook Events for more details.

Possible values:
GETPOST

WebhookFiltersarray[string]Optional

The list of webhook events that are enabled for this Service instance. See Webhook Events for more details.


Limits.ChannelMembersintegerOptional

The maximum number of Members that can be added to Channels within this Service. Can be up to 1,000.


Limits.UserChannelsintegerOptional

The maximum number of Channels Users can be a Member of within this Service. Can be up to 1,000.


Media.CompatibilityMessagestringOptional

The message to send when a media message has no text. Can be used as placeholder message.


PreWebhookRetryCountintegerOptional

The number of times to retry a call to the pre_webhook_url if the request times out (after 5 seconds) or it receives a 429, 503, or 504 HTTP response. Default retry count is 0 times, which means the call won't be retried.


PostWebhookRetryCountintegerOptional

The number of times to retry a call to the post_webhook_url if the request times out (after 5 seconds) or it receives a 429, 503, or 504 HTTP response. The default is 0, which means the call won't be retried.


Notifications.LogEnabledbooleanOptional

Whether to log notifications. The default is false.

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 updateService() {
11
const service = await client.chat.v2
12
.services("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.update({ friendlyName: "FriendlyName" });
14
15
console.log(service.sid);
16
}
17
18
updateService();

Output

1
{
2
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"consumption_report_interval": 100,
4
"date_created": "2015-07-30T20:00:00Z",
5
"date_updated": "2015-07-30T20:00:00Z",
6
"default_channel_creator_role_sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
7
"default_channel_role_sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
8
"default_service_role_sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
9
"friendly_name": "FriendlyName",
10
"limits": {
11
"channel_members": 500,
12
"user_channels": 600
13
},
14
"links": {
15
"channels": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels",
16
"users": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Users",
17
"roles": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Roles",
18
"bindings": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Bindings"
19
},
20
"notifications": {
21
"log_enabled": true,
22
"added_to_channel": {
23
"enabled": false,
24
"template": "notifications.added_to_channel.template"
25
},
26
"invited_to_channel": {
27
"enabled": false,
28
"template": "notifications.invited_to_channel.template"
29
},
30
"new_message": {
31
"enabled": false,
32
"template": "notifications.new_message.template",
33
"badge_count_enabled": true
34
},
35
"removed_from_channel": {
36
"enabled": false,
37
"template": "notifications.removed_from_channel.template"
38
}
39
},
40
"post_webhook_url": "post_webhook_url",
41
"pre_webhook_url": "pre_webhook_url",
42
"pre_webhook_retry_count": 2,
43
"post_webhook_retry_count": 3,
44
"reachability_enabled": false,
45
"read_status_enabled": false,
46
"sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
47
"typing_indicator_timeout": 100,
48
"url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
49
"webhook_filters": [
50
"webhook_filters"
51
],
52
"webhook_method": "webhook_method",
53
"media": {
54
"size_limit_mb": 150,
55
"compatibility_message": "new media compatibility message"
56
}
57
}

Delete a Service resource

delete-a-service-resource page anchor
DELETE https://chat.twilio.com/v2/Services/{Sid}

Property nameTypeRequiredPIIDescription
SidSID<IS>required

The SID of the Service resource to delete.

Pattern: ^IS[0-9a-fA-F]{32}$Min length: 34Max length: 34
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 deleteService() {
11
await client.chat.v2.services("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").remove();
12
}
13
14
deleteService();

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.