Skip to contentSkip to navigationSkip to topbar
Rate this page:
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.


UserChannel Properties

userchannel-properties page anchor

Each User Channel resource contains these properties.

Property nameTypePIIDescription
account_sidSID<AC>
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>

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>

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>

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>

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>

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

Possible values:
joinedinvitednot_participating

last_consumed_message_indexinteger

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


unread_messages_countinteger

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>

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


urlstring<uri>

The absolute URL of the User Channel resource.


notification_levelenum<string>

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 resource

fetch-a-userchannel-resource-1 page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_20
// Download the helper library from https://www.twilio.com/docs/node/install
_20
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_20
_20
// Find your Account SID and Auth Token at twilio.com/console
_20
// and set the environment variables. See http://twil.io/secure
_20
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_20
const authToken = process.env.TWILIO_AUTH_TOKEN;
_20
const client = twilio(accountSid, authToken);
_20
_20
async function fetchUserChannel() {
_20
const userChannel = await client.chat.v2
_20
.services("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_20
.users("UserSid")
_20
.userChannels("ChannelSid")
_20
.fetch();
_20
_20
console.log(userChannel.accountSid);
_20
}
_20
_20
fetchUserChannel();

Output

_16
{
_16
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_16
"service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_16
"channel_sid": "ChannelSid",
_16
"user_sid": "UserSid",
_16
"member_sid": "MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_16
"status": "joined",
_16
"last_consumed_message_index": 5,
_16
"unread_messages_count": 5,
_16
"notification_level": "default",
_16
"url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Users/USaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_16
"links": {
_16
"channel": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_16
"member": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Members/MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
_16
}
_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.

Read multiple UserChannel resources

read-multiple-userchannel-resources-1 page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_19
// Download the helper library from https://www.twilio.com/docs/node/install
_19
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_19
_19
// Find your Account SID and Auth Token at twilio.com/console
_19
// and set the environment variables. See http://twil.io/secure
_19
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_19
const authToken = process.env.TWILIO_AUTH_TOKEN;
_19
const client = twilio(accountSid, authToken);
_19
_19
async function listUserChannel() {
_19
const userChannels = await client.chat.v2
_19
.services("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_19
.users("UserSid")
_19
.userChannels.list({ limit: 20 });
_19
_19
userChannels.forEach((u) => console.log(u.accountSid));
_19
}
_19
_19
listUserChannel();

Output

_29
{
_29
"meta": {
_29
"page": 0,
_29
"page_size": 50,
_29
"first_page_url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Users/USaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels?PageSize=50&Page=0",
_29
"previous_page_url": null,
_29
"url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Users/USaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels?PageSize=50&Page=0",
_29
"next_page_url": null,
_29
"key": "channels"
_29
},
_29
"channels": [
_29
{
_29
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_29
"service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_29
"channel_sid": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_29
"user_sid": "USaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_29
"member_sid": "MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_29
"status": "joined",
_29
"last_consumed_message_index": 5,
_29
"unread_messages_count": 5,
_29
"notification_level": "default",
_29
"url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Users/USaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_29
"links": {
_29
"channel": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_29
"member": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Members/MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
_29
}
_29
}
_29
]
_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.

Property nameTypeRequiredPIIDescription
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.

Mute Notifications for a Channel

mute-notifications-for-a-channel page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_20
// Download the helper library from https://www.twilio.com/docs/node/install
_20
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_20
_20
// Find your Account SID and Auth Token at twilio.com/console
_20
// and set the environment variables. See http://twil.io/secure
_20
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_20
const authToken = process.env.TWILIO_AUTH_TOKEN;
_20
const client = twilio(accountSid, authToken);
_20
_20
async function updateUserChannel() {
_20
const userChannel = await client.chat.v2
_20
.services("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_20
.users("UserSid")
_20
.userChannels("ChannelSid")
_20
.update({ notificationLevel: "muted" });
_20
_20
console.log(userChannel.notificationLevel);
_20
}
_20
_20
updateUserChannel();

Output

_16
{
_16
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_16
"service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_16
"channel_sid": "ChannelSid",
_16
"user_sid": "UserSid",
_16
"member_sid": "MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_16
"status": "joined",
_16
"last_consumed_message_index": 5,
_16
"unread_messages_count": 5,
_16
"notification_level": "muted",
_16
"url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Users/USaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_16
"links": {
_16
"channel": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_16
"member": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Members/MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
_16
}
_16
}


Rate this page: