Skip to contentSkip to navigationSkip to topbar
On this page

User Channel 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.

The User Channel resource of Programmable Chat is a read-only resource that describes a Channel that the User is a Member of.


Channel Properties

channel-properties page anchor

Each User Channel resource contains these properties.

Property nameTypeRequiredDescriptionChild properties
account_sidSID<AC>Optional
Not PII

The SID of the Account that created the User Channel resource.

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

service_sidSID<IS>Optional

The SID of the Service the User Channel resource is associated with.

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

channel_sidSID<CH>Optional

The SID of the Channel the User Channel resource belongs to.

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

user_sidSID<US>Optional

The SID of the User the User Channel belongs to.

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

member_sidSID<MB>Optional

The SID of a Member that represents the User on the Channel.

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

statusenum<string>Optional

The status of the User on the Channel. Can be: joined, invited, or not_participating.

Possible values:
joinedinvitednot_participating

last_consumed_message_indexintegerOptional

The index of the last Message in the Channel that the Member has read.


unread_messages_countintegerOptional

The number of unread Messages in the Channel for the User. Note that retrieving messages on a client endpoint does not mean that messages are consumed or read. See Consumption Horizon feature to learn how to mark messages as consumed.


linksobject<uri-map>Optional

The absolute URLs of the Members, Messages , Invites and, if it exists, the last Message for the Channel.


urlstring<uri>Optional

The absolute URL of the User Channel resource.


notification_levelenum<string>Optional

The push notification level of the User for the Channel. Can be: default or muted.

Possible values:
defaultmuted

Fetch a UserChannel resource

fetch-a-userchannel-resource page anchor
GET https://chat.twilio.com/v2/Services/{ServiceSid}/Users/{UserSid}/Channels/{ChannelSid}

The {UserSid} value can be either the sid or the identity of the User resource and the {ChannelSid} value can be either the sid or the unique_name of the Channel to fetch.

Path parameters

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

The SID of the Service to fetch the User Channel resource from.

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

UserSidstringrequired

The SID of the User to fetch the User Channel resource from. This value can be either the sid or the identity of the User resource.


ChannelSidstringrequired

The SID of the Channel that has the User Channel to fetch. This value can be either the sid or the unique_name of the Channel to fetch.

Fetch a UserChannel resourceLink to code sample: Fetch a UserChannel 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 fetchUserChannel() {
11
const userChannel = await client.chat.v2
12
.services("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.users("UserSid")
14
.userChannels("ChannelSid")
15
.fetch();
16
17
console.log(userChannel.accountSid);
18
}
19
20
fetchUserChannel();

Output

1
{
2
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"channel_sid": "ChannelSid",
5
"user_sid": "UserSid",
6
"member_sid": "MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
7
"status": "joined",
8
"last_consumed_message_index": 5,
9
"unread_messages_count": 5,
10
"notification_level": "default",
11
"url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Users/USaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
12
"links": {
13
"channel": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
14
"member": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Members/MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
15
}
16
}

Read multiple UserChannel resources

read-multiple-userchannel-resources page anchor
GET https://chat.twilio.com/v2/Services/{ServiceSid}/Users/{UserSid}/Channels

The {UserSid} value can be either the sid or the identity of the User resource to read User Channel resources from.

Property nameTypeRequiredPIIDescription
ServiceSidSID<IS>required

The SID of the Service to read the User Channel resources from.

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

UserSidstringrequired

The SID of the User to read the User Channel resources from. This value can be either the sid or the identity of the User resource.

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 listUserChannel() {
11
const userChannels = await client.chat.v2
12
.services("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.users("UserSid")
14
.userChannels.list({ limit: 20 });
15
16
userChannels.forEach((u) => console.log(u.accountSid));
17
}
18
19
listUserChannel();

Output

1
{
2
"meta": {
3
"page": 0,
4
"page_size": 50,
5
"first_page_url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Users/USaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels?PageSize=50&Page=0",
6
"previous_page_url": null,
7
"url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Users/USaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels?PageSize=50&Page=0",
8
"next_page_url": null,
9
"key": "channels"
10
},
11
"channels": [
12
{
13
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
14
"service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
15
"channel_sid": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
16
"user_sid": "USaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
17
"member_sid": "MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
18
"status": "joined",
19
"last_consumed_message_index": 5,
20
"unread_messages_count": 5,
21
"notification_level": "default",
22
"url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Users/USaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
23
"links": {
24
"channel": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
25
"member": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Members/MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
26
}
27
}
28
]
29
}

Set the NotificationLevel

set-the-notificationlevel page anchor
POST https://chat.twilio.com/v2/Services/{ServiceSid}/Users/{UserSid}/Channels/{ChannelSid}

The NotificationLevel property expresses whether a user receives pushes for this channel or not. This can be set separately for each user/channel pair.

Property nameTypeRequiredPIIDescription
ServiceSidSID<IS>required

The SID of the Service to update the User Channel resource in.

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

UserSidstringrequired

The SID of the User to update the User Channel resource from. This value can be either the sid or the identity of the User resource.


ChannelSidstringrequired

The SID of the Channel with the User Channel resource to update. This value can be the Channel resource's sid or unique_name.

Encoding type:application/x-www-form-urlencoded
SchemaExample
Property nameTypeRequiredDescriptionChild properties
NotificationLevelenum<string>Optional

The push notification level to assign to the User Channel. Can be: default or muted.

Possible values:
defaultmuted

LastConsumedMessageIndexintegerOptional

The index of the last Message in the Channel that the Member has read.


LastConsumptionTimestampstring<date-time>Optional

The ISO 8601(link takes you to an external page) timestamp of the last Message read event for the Member within the Channel.

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 updateUserChannel() {
11
const userChannel = await client.chat.v2
12
.services("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.users("UserSid")
14
.userChannels("ChannelSid")
15
.update({ notificationLevel: "muted" });
16
17
console.log(userChannel.notificationLevel);
18
}
19
20
updateUserChannel();

Output

1
{
2
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"channel_sid": "ChannelSid",
5
"user_sid": "UserSid",
6
"member_sid": "MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
7
"status": "joined",
8
"last_consumed_message_index": 5,
9
"unread_messages_count": 5,
10
"notification_level": "muted",
11
"url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Users/USaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
12
"links": {
13
"channel": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
14
"member": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Members/MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
15
}
16
}

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.