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.
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.
All URLs in the reference documentation use the following base URL:
https://conversations.twilio.com/v1
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.
1GET /v1/Services/<Service SID, ISXXX...>/Roles/2
Each Role resource contains these properties.
The unique string that we created to identify the Role resource.
^RL[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the Account that created the Role resource.
^AC[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the Conversation Service the Role resource is associated with.
^IS[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The type of role. Can be: conversation
for Conversation roles or service
for Conversation Service roles.
conversation
service
The date and time in GMT when the resource was created specified in ISO 8601 format.
The date and time in GMT when the resource was last updated specified in ISO 8601 format.
An absolute API resource URL for this user role.
POST https://conversations.twilio.com/v1/Roles
application/x-www-form-urlencoded
A descriptive string that you create to describe the new resource. It can be up to 64 characters long.
The type of role. Can be: conversation
for Conversation roles or service
for Conversation Service roles.
conversation
service
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
.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function createRole() {11const role = await client.conversations.v1.roles.create({12friendlyName: "FriendlyName",13permission: ["addParticipant"],14type: "conversation",15});1617console.log(role.sid);18}1920createRole();
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}
The SID of the Role resource to fetch.
^RL[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function fetchRole() {11const role = await client.conversations.v112.roles("RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")13.fetch();1415console.log(role.sid);16}1718fetchRole();
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}
GET https://conversations.twilio.com/v1/Roles
How many resources to return in each list page. The default is 50, and the maximum is 1000.
1
Maximum: 1000
The page token. This is provided by the API.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function listRole() {11const roles = await client.conversations.v1.roles.list({ limit: 20 });1213roles.forEach((r) => console.log(r.sid));14}1516listRole();
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}
The SID of the Role resource to update.
^RL[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
application/x-www-form-urlencoded
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/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function updateRole() {11const role = await client.conversations.v112.roles("New_Chat_Service_SID")13.update({ permission: ["Permission"] });1415console.log(role.sid);16}1718updateRole();
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}
The SID of the Role resource to delete.
^RL[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function deleteRole() {11await client.conversations.v112.roles("RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")13.remove();14}1516deleteRole();
These are the available permissions
entries for roles where type
= service.
Permission | Enables User to: |
---|---|
addParticipant | Add other users as Participants of a Conversation |
createConversation | Create new Conversations |
deleteAnyMessage | Delete any Message in the Service |
deleteConversation | Delete Conversations |
editAnyMessage | Edit any Message in the Service |
editAnyMessageAttributes | Edit any Message attributes in the Service |
editAnyUserInfo | Edit other User's User Info properties |
editConversationAttributes | Update the optional attributes metadata field on a Conversation |
editConversationName | Change the name of a Conversation |
editOwnMessage | Edit their own Messages in the Service |
editOwnMessageAttributes | Edit the own Message attributes in the Service |
editOwnUserInfo | Edit their own User Info properties |
joinConversation | Join Conversations |
removeParticipant | Remove Participants from a Conversation |
These are the available permissions
entries for roles where type
= conversation.
Permission | Enables User to: |
---|---|
addParticipant | Add other users as Participants of a Conversation |
deleteAnyMessage | Delete any Message in the Service |
deleteOwnMessage | Delete their own Messages in the Service |
deleteConversation | Delete Conversations |
editAnyMessage | Edit any Message in the Service |
editAnyMessageAttributes | Edit any Message attributes in the Service |
editAnyUserInfo | Edit other User's User Info properties |
editConversationAttributes | Update the optional attributes metadata field on a Conversation |
editConversationName | Change the name of a Conversation |
editOwnMessage | Edit their own Messages in the Service |
editOwnMessageAttributes | Edit the own Message attributes in the Service |
editOwnUserInfo | Edit their own User Info properties |
leaveConversation | Leave a Conversation |
removeParticipant | Remove Participants from a Conversation |
sendMediaMessage | Send media Messages to Conversations |
sendMessage | Send Messages to Conversations |