如何更改 twilio 频道的名称
How to change name of twilio channel
Twilio 文档页面提到使用角色更改频道名称 (https://www.twilio.com/docs/api/chat/rest/roles),但未提供任何示例代码。在下面的示例中我将如何执行此操作:
var channel = this.state.channel;
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = 'your_auth_token';
var Twilio = require('twilio').Twilio;
var client = new Twilio(accountSid, authToken);
var service = client.chat.services('ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
service.roles.list().then(function(response) {
// what do I insert here to change the name of the channel variable
});
这里是 Twilio 开发人员布道者。
在 Twilio Programmable Chat 中,每个用户在创建时都会获得一个默认角色。还有一个默认的频道角色,分配给每个加入频道的成员。角色说明了每个 user/member 拥有的权限。有一个 guide on roles and permissions available in the Chat documentation 我建议你通读一下。
默认用户角色具有以下权限:
- 创建频道
- 获取频道列表(public、加入并受邀)
- 加入频道(public 或受邀)
- 编辑自己的用户信息
并且默认频道成员角色具有这些权限:
- 离开频道
- 获取会员列表
- 获取频道消息
- 添加消息
- 编辑自己的消息
- 编辑自己的消息属性
- 删除自己的消息
您可以从 SDK update these roles or create new roles using the REST API. If you want users to be able to update the channel name you need to give them the editChannelName
permission. You can either do this on the user level or the channel level. Once you have granted this permission to the role, or created a new role with this permission and assigned it to the user, the user will be able to call channel.updateFriendlyName
。
或者,您可以使用 Channels resource in the REST API to change the friendly name of the channel too。
channel.update({
friendlyName: 'channel_name',
})
.then(response => {
console.log(response);
});
Twilio 文档页面提到使用角色更改频道名称 (https://www.twilio.com/docs/api/chat/rest/roles),但未提供任何示例代码。在下面的示例中我将如何执行此操作:
var channel = this.state.channel;
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = 'your_auth_token';
var Twilio = require('twilio').Twilio;
var client = new Twilio(accountSid, authToken);
var service = client.chat.services('ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
service.roles.list().then(function(response) {
// what do I insert here to change the name of the channel variable
});
这里是 Twilio 开发人员布道者。
在 Twilio Programmable Chat 中,每个用户在创建时都会获得一个默认角色。还有一个默认的频道角色,分配给每个加入频道的成员。角色说明了每个 user/member 拥有的权限。有一个 guide on roles and permissions available in the Chat documentation 我建议你通读一下。
默认用户角色具有以下权限:
- 创建频道
- 获取频道列表(public、加入并受邀)
- 加入频道(public 或受邀)
- 编辑自己的用户信息
并且默认频道成员角色具有这些权限:
- 离开频道
- 获取会员列表
- 获取频道消息
- 添加消息
- 编辑自己的消息
- 编辑自己的消息属性
- 删除自己的消息
您可以从 SDK update these roles or create new roles using the REST API. If you want users to be able to update the channel name you need to give them the editChannelName
permission. You can either do this on the user level or the channel level. Once you have granted this permission to the role, or created a new role with this permission and assigned it to the user, the user will be able to call channel.updateFriendlyName
。
或者,您可以使用 Channels resource in the REST API to change the friendly name of the channel too。
channel.update({
friendlyName: 'channel_name',
})
.then(response => {
console.log(response);
});