Skip to contentSkip to navigationSkip to topbar
On this page

Role Resource


In Twilio Conversations, the Role Resource represents what a User can do within the Service and individual Conversations. Roles are scoped to either a Service or a Conversation.

Users are assigned a Role at the Service level. This determines what they can do within the chat Service instance, such as create and destroy Conversations within the Service.

Participants are assigned a Role at the Conversation level. This determines what they are able to do within a particular Conversation, such as invite Participants to be members of the Conversation, post Messages, and remove other Participants from the Conversation.

See Permission Values for information about the permissions that can be assigned in each scope.

(error)

Do not use Personally Identifiable Information (PII) for the friendlyName field

Avoid using a person's name, home address, email, phone number, or other PII in the friendlyName field. Use some form of pseudonymized identifier, instead.

You can learn more about how we process your data in our privacy policy.(link takes you to an external page)


API Base URL

api-base-url page anchor

All URLs in the reference documentation use the following base URL:

https://conversations.twilio.com/v1

Using the shortened base URL

using-the-shortened-base-url page anchor

Using the REST API, you can interact with Role 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.

GET /v1/Roles/

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.

1
GET /v1/Services/<Service SID, ISXXX...>/Roles/
2

Each Role resource contains these properties.

Property nameTypeRequiredDescriptionChild properties
sidSID<RL>Optional
Not PII

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

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

account_sidSID<AC>Optional

The SID of the Account that created the Role resource.

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

chat_service_sidSID<IS>Optional

The SID of the Conversation Service the Role resource is associated with.

Pattern: ^IS[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.


typeenum<string>Optional

The type of role. Can be: conversation for Conversation roles or service for Conversation Service roles.

Possible values:
conversationservice

permissionsarray[string]Optional

An array of the permissions the role has been granted.


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.


urlstring<uri>Optional

An absolute API resource URL for this user role.


POST https://conversations.twilio.com/v1/Roles

Encoding type:application/x-www-form-urlencoded
SchemaExample
Property nameTypeRequiredDescriptionChild properties
FriendlyNamestringrequired

A descriptive string that you create to describe the new resource. It can be up to 64 characters long.


Typeenum<string>required

The type of role. Can be: conversation for Conversation roles or service for Conversation Service roles.

Possible values:
conversationservice

Permissionarray[string]required

A permission that you grant to the new role. Only one permission can be granted per parameter. To assign more than one permission, repeat this parameter for each permission value. The values for this parameter depend on the role's type.

Create a RoleLink to code sample: Create a Role
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 createRole() {
11
const role = await client.conversations.v1.roles.create({
12
friendlyName: "FriendlyName",
13
permission: ["addParticipant"],
14
type: "conversation",
15
});
16
17
console.log(role.sid);
18
}
19
20
createRole();

Output

1
{
2
"sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"chat_service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
5
"friendly_name": "FriendlyName",
6
"type": "conversation",
7
"permissions": [
8
"sendMessage",
9
"leaveConversation",
10
"editOwnMessage",
11
"deleteOwnMessage"
12
],
13
"date_created": "2016-03-03T19:47:15Z",
14
"date_updated": "2016-03-03T19:47:15Z",
15
"url": "https://conversations.twilio.com/v1/Roles/RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
16
}

GET https://conversations.twilio.com/v1/Roles/{Sid}

Property nameTypeRequiredPIIDescription
SidSID<RL>required

The SID of the Role resource to fetch.

Pattern: ^RL[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 fetchRole() {
11
const role = await client.conversations.v1
12
.roles("RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.fetch();
14
15
console.log(role.sid);
16
}
17
18
fetchRole();

Output

1
{
2
"sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"chat_service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
5
"friendly_name": "Conversation Role",
6
"type": "conversation",
7
"permissions": [
8
"sendMessage",
9
"leaveConversation",
10
"editOwnMessage",
11
"deleteOwnMessage"
12
],
13
"date_created": "2016-03-03T19:47:15Z",
14
"date_updated": "2016-03-03T19:47:15Z",
15
"url": "https://conversations.twilio.com/v1/Roles/RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
16
}

Read multiple Role resources

read-multiple-role-resources page anchor
GET https://conversations.twilio.com/v1/Roles

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 listRole() {
11
const roles = await client.conversations.v1.roles.list({ limit: 20 });
12
13
roles.forEach((r) => console.log(r.sid));
14
}
15
16
listRole();

Output

1
{
2
"meta": {
3
"page": 0,
4
"page_size": 50,
5
"first_page_url": "https://conversations.twilio.com/v1/Roles?PageSize=50&Page=0",
6
"previous_page_url": null,
7
"url": "https://conversations.twilio.com/v1/Roles?PageSize=50&Page=0",
8
"next_page_url": null,
9
"key": "roles"
10
},
11
"roles": [
12
{
13
"sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
14
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
15
"chat_service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
16
"friendly_name": "Conversation Role",
17
"type": "conversation",
18
"permissions": [
19
"sendMessage",
20
"leaveConversation",
21
"editOwnMessage",
22
"deleteOwnMessage"
23
],
24
"date_created": "2016-03-03T19:47:15Z",
25
"date_updated": "2016-03-03T19:47:15Z",
26
"url": "https://conversations.twilio.com/v1/Roles/RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
27
}
28
]
29
}

POST https://conversations.twilio.com/v1/Roles/{Sid}

Property nameTypeRequiredPIIDescription
SidSID<RL>required

The SID of the Role resource to update.

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

A permission that you grant to the role. Only one permission can be granted per parameter. To assign more than one permission, repeat this parameter for each permission value. Note that the update action replaces all previously assigned permissions with those defined in the update action. To remove a permission, do not include it in the subsequent update action. The values for this parameter depend on the role's type.

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 updateRole() {
11
const role = await client.conversations.v1
12
.roles("New_Chat_Service_SID")
13
.update({ permission: ["Permission"] });
14
15
console.log(role.sid);
16
}
17
18
updateRole();

Output

1
{
2
"sid": "New_Chat_Service_SID",
3
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"chat_service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
5
"friendly_name": "Conversation Role",
6
"type": "conversation",
7
"permissions": [
8
"sendMessage",
9
"leaveConversation",
10
"editOwnMessage",
11
"deleteOwnMessage"
12
],
13
"date_created": "2016-03-03T19:47:15Z",
14
"date_updated": "2016-03-03T19:47:15Z",
15
"url": "https://conversations.twilio.com/v1/Roles/RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
16
}

DELETE https://conversations.twilio.com/v1/Roles/{Sid}

Property nameTypeRequiredPIIDescription
SidSID<RL>required

The SID of the Role resource to delete.

Pattern: ^RL[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 deleteRole() {
11
await client.conversations.v1
12
.roles("RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.remove();
14
}
15
16
deleteRole();

Service-scope permissions

service-scope-permissions page anchor

These are the available permissions entries for roles where type = service.

PermissionEnables User to:
addParticipantAdd other users as Participants of a Conversation
createConversationCreate new Conversations
deleteAnyMessageDelete any Message in the Service
deleteConversationDelete Conversations
editAnyMessageEdit any Message in the Service
editAnyMessageAttributesEdit any Message attributes in the Service
editAnyUserInfoEdit other User's User Info properties
editConversationAttributesUpdate the optional attributes metadata field on a Conversation
editConversationNameChange the name of a Conversation
editOwnMessageEdit their own Messages in the Service
editOwnMessageAttributesEdit the own Message attributes in the Service
editOwnUserInfoEdit their own User Info properties
joinConversationJoin Conversations
removeParticipantRemove Participants from a Conversation

Conversation-scope permissions

conversation-scope-permissions page anchor

These are the available permissions entries for roles where type = conversation.

PermissionEnables User to:
addParticipantAdd other users as Participants of a Conversation
deleteAnyMessageDelete any Message in the Service
deleteOwnMessageDelete their own Messages in the Service
deleteConversationDelete Conversations
editAnyMessageEdit any Message in the Service
editAnyMessageAttributesEdit any Message attributes in the Service
editAnyUserInfoEdit other User's User Info properties
editConversationAttributesUpdate the optional attributes metadata field on a Conversation
editConversationNameChange the name of a Conversation
editOwnMessageEdit their own Messages in the Service
editOwnMessageAttributesEdit the own Message attributes in the Service
editOwnUserInfoEdit their own User Info properties
leaveConversationLeave a Conversation
removeParticipantRemove Participants from a Conversation
sendMediaMessageSend media Messages to Conversations
sendMessageSend Messages to Conversations

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.