频道管理( 已废弃)
更新时间: 2022/12/09 19:47:23
本文已不再维护,请前往频道概述及其他频道相关文档查看。
频道(Channel)是具体信息通讯的发生地。以游乐场来类比,频道就相当于游乐场中的游乐设施。有了圈组服务器这个游乐场地,就必须构建游乐设施才能给用户提供服务。 SDK 中用于表示频道的结构为 channelInfo。
channelInfo参数说明:
字段名 | 类型 | 说明 |
---|---|---|
channelId | string | 频道ID |
serverId | string | 服务器ID |
name | string | 名称 |
topic | string | 主题 |
ext | string | 自定义扩展 |
type | TChannelInfoType |
类型:message=0(消息频道);media=1(实时互动频道);ext=100(自定义频道) |
validFlag | 0|1 | 有效标志:0-无效,1-有效 |
createTime | number | 创建时间的时间戳 |
updateTime | number | 更新时间的时间戳 |
owner | string | 所有者 |
viewMode | 0|1 | 查看模式:0-公开模式(默认),1-私密模式 |
创建频道
创建圈组服务器后,可以在该服务器下创建频道:
接口
type CreateChannelOptions = {
/**
* 服务器ID
*/
serverId: string;
/**
* 名称
*/
name: string;
/**
* 类型:message-消息频道,media-实时互动频道,ext-自定义频道
*/
type: TChannelInfoType;
/**
* 应用id
*/
// appid: string;
/**
* 主题
*/
topic: string;
/**
* 自定义扩展 服务器字段为custom
*/
ext: string;
/**
* 查看模式:0-公开模式(默认),1-私密模式
*/
viewMode?: number
/**
* 反垃圾相关字段
*/
antispamTag?: AntispamTag
}
export type AntispamTag = {
/**
* 用户配置的对某些资料内容另外的反垃圾的业务ID, Json结构, {"textbid":"","picbid":""}
*/
antiSpamBusinessId: {
textbid: string
picbid: string
}
}
/**
* 创建频道
*/
createChannel(options: CreateChannelOptions): Promise<ChannelInfo>
- 创建频道参数中如果带上
antiSpamBusinessId
则会对参数信息进行安全通检查。antiSpamBusinessId
代表安全通自定义业务 ID;如需新增安全通自定义业务,请联系商务经理进行相关配置,然后前往云信控制台的安全通配置界面获取该业务 ID。 - 9.3.0 版本增加了实时互动频道类型,创建频道时可通过
EChannelInfoType
来选择频道类型。
示例代码
const qchat = new QChat(options);
qchat.qchatChannel.createChannel({
"serverId": "12345",
"name": "1"
})
删除频道
拥有Channel管理权限的人可以删除已创建的Channel:
接口
type DeleteChannelOptions = {
/**
* 频道id
*/
ChannelId: string;
}
/**
* 删除建频道
*/
deleteChannel(options: DeleteChannelOptions): Promise<void>
示例代码
const qchat = new QChat(options);
qchat.qchatChannel.deleteChannel({
"serverId": "12345"
})
修改频道
拥有Channel管理权限的人可以修改已创建的Channel:
接口
type UpdateChannelOptions = {
/**
* 频道ID
*/
channelId: string;
/**
* 服务器ID
*/
serverId: string;
/**
* 名称
*/
name: string;
/**
* 类型:message-消息频道,media-实时互动频道,ext-自定义频道
*/
type: EChannelInfoType;
/**
* 主题
*/
topic: string;
/**
* 自定义扩展 服务器字段为custom
*/
ext: string;
/**
* 查看模式:0-公开模式(默认),1-私密模式
*/
viewMode?: number
/**
* 反垃圾相关字段
*/
antispamTag?: AntispamTag
}
export type AntispamTag = {
/**
* 用户配置的对某些资料内容另外的反垃圾的业务ID, Json结构, {"textbid":"","picbid":""}
* http://doc.hz.netease.com/display/MMC/AntispamTag
*/
antiSpamBusinessId: {
textbid: string
picbid: string
}
}
/**
* 更新频道
*/
updateChannel(options: UpdateChannelOptions): Promise<ChannelInfo>
示例代码
const qchat = new QChat(options);
qchat.qchatChannel.updateChannel({
"serverId": "12345",
"name":"123"
})
修改频道信息参数中如果带上 antiSpamBusinessId
则会对参数信息进行安全通检查。antiSpamBusinessId
代表安全通自定义业务 ID;如需新增安全通自定义业务,请联系商务经理进行相关配置,然后前往云信控制台的安全通配置界面获取该业务 ID。
查询频道信息
SDK提供两种方式查询频道信息,分别是按 ChannelId 查询和按时间分页查询。
按 ChannelId 查询
可以通过传入 ChannelId 列表查询指定的 Channel 信息:
接口
type GetChannelsOptions = {
/**
* 频道id
*/
channelIds: string[];
}
/**
* 查询频道列表
*/
getChannels(options: GetChannelsOptions): Promise<ChannelInfo[]>
示例代码
const qchat = new QChat(options);
qchat.qchatChannel.getChannels({
"channelIds": ["12345"]
})
按时间分页查询
可以通过传入 ChannelId 列表查询指定的 Channel 信息:
接口
type GetChannelsByPageOptions = {
/**
* 服务器ID
*/
serverId: string
/**
* 时间戳 传0取当前时间
*/
timetag: number
/**
* 条数
*/
limit: number
}
type GetChannelsByPageResult = {
/**
* 分页便捷选项
*/
listQueryTag: {
/**
* 是否还有下一页
*/
hasMore: boolean;
/**
* 下一次翻页时的起始时间戳
*/
nextTimetag: number;
}
datas: ChannelInfo[]
}
/**
* 查询频道列表(分页)
*/
getChannelsByPage(options: GetChannelsByPageOptions): Promise<GetChannelsByPageResult>
示例代码
const qchat = new QChat(options);
qchat.qchatChannel.getChannelsByPage({
"serverId": "934978",
"timetag": 0,
"limit": 0
})
订阅频道
接口
- 您可以通过以下接口订阅或者取消订阅频道的消息、未读数、未读状态、系统通知。大圈组服务器下只有订阅频道后才能收到该频道的订阅内容(消息、未读数、未读状态)。
- 与您相关的消息不需要订阅频道就可以收到,比如@你的消息(@All的消息不属于与你相关的消息)。
- 小圈组服务器下不需要订阅频道就可以收到所有该服务器下所有频道的消息。
type SubscribeChannelOptions = {
/**
* 订阅类型 :
* 1.订阅某个channel的【消息】/【通知】
* 2.订阅某个channel的【消息未读数】/【通知】
* 3.订阅某个channel的【消息未读状态】/【通知】
*/
type: 1 | 2 | 3;
/**
* 操作类型 1订阅 2取消订阅
*/
opeType: 1 | 2
channels: {
/**
* 服务器id
*/
serverId: string
/**
* 频道id
*/
channelId: string
}[]
}
type UnreadInfo = {
/**
* 服务器id
*/
serverId: string
/**
* 频道id
*/
channelId: string;
/**
* 未读数
*/
unreadCount: number;
/**
* 艾特消息未读数
*/
mentionedCount: number;
/**
* 已读时间戳
*/
ackTimestamp?: number;
/**
* 最大未读数
*/
maxCount?: number;
/**
* 最后一条消息的时间戳
*/
lastMsgTime?: number;
}
/**
* 订阅频道
*/
subscribeChannel(options: SubscribeChannelOptions): Promise<UnreadInfo[]>
示例代码
const qchat = new QChat(options);
qchat.qchatChannel.subscribeChannel({
"type": 1,
"opeType": 1,
"channels": [
{
"serverId": "",
"channelId": ""
}
]
})
查询频道成员列表
可以通过以下接口分页查询某频道下的成员列表。如果是公开频道,则成员为除拉入此频道黑名单外的所有圈组服务器成员;如果是私密频道,则为此频道下白名单中所有圈组服务器成员。
接口
type GetMembersByPageOptions = {
/**
* 服务器ID
*/
serverId: string;
/**
* 频道 ID
*/
channelId: string;
/**
* 分页条件-上一次查询的时间戳。默认0,0等同于表示当前时间。
*/
timetag?: number;
/**
* 分页页码,默认 100 条
*/
limit?: number;
}
type GetMembersByPageResult = {
/**
* 分页便捷选项
*/
listQueryTag: {
/**
* 是否还有下一页
*/
hasMore: boolean;
/**
* 下一次翻页时的起始时间戳
*/
nextTimetag: number;
}
datas: MemberInfo[]
}
/**
* 获取频道下的成员(分页)
*/
getMembersByPage(options: GetMembersByPageOptions): Promise<GetMembersByPageResult>
示例代码
const qchat = new QChat(options);
qchat.qchatChannel.getMembersByPage({
"serverId": "934978",
"channelId": "869553",
"timetag": 0,
"limit": 100
})
更新频道黑名单
如有权限管理黑白名单,可更新频道的黑白名单成员信息。
接口
type UpdateWhiteBlackMembersOptions = {
/**
* 服务器ID
*/
serverId: string;
/**
* 频道 ID
*/
channelId: string;
/**
* 成员的 account ID,一次最多传入 100 个
*/
toAccids: string[];
/**
* 类型
*
* 1. 针对公开的频道 {@link ChannelInfo.viewMode | ChannelInfo.viewMode} 为 0,接口只允许设置黑名单,type 传 "black"
*
* 2. 针对私密的频道 {@link ChannelInfo.viewMode | ChannelInfo.viewMode} 为 1,接口只允许设置白名单,type 传 "white"
*/
type: keyof typeof EWhiteBlackType;
/**
* 操作类型。新增传 "add", 移除传 "remove"
*/
opeType: keyof typeof EWhiteBlackOpeType;
}
/**
* 更新频道的白/黑名单成员
*
* 1. 针对公开的频道 {@link ChannelInfo.viewMode | ChannelInfo.viewMode} 为 0,那么设置的成员在此公开频道的黑名单。此成员将无法查到此频道的信息
*
* 2. 针对私密的频道 {@link ChannelInfo.viewMode | ChannelInfo.viewMode} 为 1,那么设置的成员在此私密频道的白名单。此成员将可以查到此频道的信息
*/
updateWhiteBlackMembers(options: UpdateWhiteBlackMembersOptions): Promise<void>
示例代码
const qchat = new QChat(options);
qchat.qchatChannel.updateWhiteBlackMembers({
"serverId": "1377422",
"channelId": "1295500",
"type": "black",
"opeType": "remove",
"toAccids": ["ctt1"]
})
分页查询频道黑白名单
如有权限管理黑白名单,可更新频道的黑白名单成员信息。
接口
type GetWhiteBlackMembersPageOptions = {
/**
* 服务器ID
*/
serverId: string;
/**
* 频道 ID
*/
channelId: string;
/**
* 类型
*
* 1. 针对公开的频道 {@link ChannelInfo.viewMode | ChannelInfo.viewMode} 为 0,接口只允许设置黑名单,type 传 "black"
*
* 2. 针对私密的频道 {@link ChannelInfo.viewMode | ChannelInfo.viewMode} 为 1,接口只允许设置白名单,type 传 "white"
*/
type: keyof typeof EWhiteBlackType;
/**
* 分页条件-上一次查询的时间戳。默认0,0等同于表示当前时间。
*/
timetag?: number;
/**
* 分页页码,默认 100 条
*/
limit?: number;
}
type GetWhiteBlackMembersPageResult = {
/**
* 分页便捷选项
*/
listQueryTag: {
/**
* 是否还有下一页
*/
hasMore: boolean;
/**
* 下一次翻页时的起始时间戳
*/
nextTimetag: number;
}
datas: MemberInfo[]
}
/**
* 分页查询频道的白/黑名单成员
*/
getWhiteBlackMembersPage(options: GetWhiteBlackMembersPageOptions): Promise<GetWhiteBlackMembersPageResult>
示例代码
const qchat = new QChat(options);
qchat.qchatChannel.getWhiteBlackMembersPage({
"serverId": "934978",
"channelId": "869726",
"type": "white",
"timetag": 0,
"limit": 100
})
更新频道黑名单身份组
如有权限管理黑白名单,可更新频道的黑白名单身份组:
接口
type UpdateWhiteBlackRoleOptions = {
/**
* 服务器ID
*/
serverId: string;
/**
* 频道 ID
*/
channelId: string;
/**
* 身份组 ID
*/
roleId: string;
/**
* 类型
*
* 1. 针对公开的频道 {@link ChannelInfo.viewMode | ChannelInfo.viewMode} 为 0,接口只允许设置黑名单,type 传 "black"
*
* 2. 针对私密的频道 {@link ChannelInfo.viewMode | ChannelInfo.viewMode} 为 1,接口只允许设置白名单,type 传 "white"
*/
type: keyof typeof EWhiteBlackType;
/**
* 操作类型。新增传 "add", 移除传 "remove"
*/
opeType: keyof typeof EWhiteBlackOpeType;
}
/**
* 更新频道的白/黑名单身份组
*
* 1. 针对公开的频道 {@link ChannelInfo.viewMode | ChannelInfo.viewMode} 为 0,那么设置的身份组在此公开频道的黑名单。此身份组用户将无法查到此频道的信息
*
* 2. 针对私密的频道 {@link ChannelInfo.viewMode | ChannelInfo.viewMode} 为 1,那么设置的身份组在此私密频道的白名单。此身份组用户将可以查到此频道的信息
*/
updateWhiteBlackRole(options: UpdateWhiteBlackRoleOptions): Promise<void>
示例代码
const qchat = new QChat(options);
qchat.qchatChannel.updateWhiteBlackRole({
"serverId": "1377422",
"channelId": "1295500",
"roleId": "1164961",
"type": "black",
"opeType": "remove"
})
分页查询黑白名单身份组列表
如有权限管理黑白名单,可更新频道的黑白名单身份组:
接口
type GetWhiteBlackRolesPageOptions = {
/**
* 服务器ID
*/
serverId: string;
/**
channelId: string;
/**
* 类型
* 频道 ID
*/
*
* 1. 针对公开的频道 {@link ChannelInfo.viewMode | ChannelInfo.viewMode} 为 0,接口只允许设置黑名单,type 传 "black"
*
* 2. 针对私密的频道 {@link ChannelInfo.viewMode | ChannelInfo.viewMode} 为 1,接口只允许设置白名单,type 传 "white"
*/
type: keyof typeof EWhiteBlackType;
/**
* 分页条件-上一次查询的时间戳。默认0,0等同于表示当前时间。
*/
timetag?: number;
/**
* 分页页码,默认 100 条
*/
limit?: number
/**
* 分页查询频道的白/黑名单身份组
*/
getWhiteBlackRolesPage(options: GetWhiteBlackRolesPageOptions): Promise<GetWhiteBlackRolesPageResult>
示例代码
const qchat = new QChat(options);
qchat.qchatChannel.getWhiteBlackRolesPage({
"serverId": "934978",
"channelId": "869726",
"type": "white",
"timetag": 0,
"limit": 100
})
批量查询频道黑白名单身份组列表
如有权限管理黑白名单,可更新频道的黑白名单身份组:
接口
type GetExistingWhiteBlackRolesOptions = {
/**
* 服务器ID
*/
serverId: string;
/**
* 频道 ID
*/
channelId: string;
/**
* 类型
*
* 1. 针对公开的频道 {@link ChannelInfo.viewMode | ChannelInfo.viewMode} 为 0,接口只允许设置黑名单,type 传 "black"
*
* 2. 针对私密的频道 {@link ChannelInfo.viewMode | ChannelInfo.viewMode} 为 1,接口只允许设置白名单,type 传 "white"
*/
type: keyof typeof EWhiteBlackType;
/**
* 身份组 id 数组 , 最多100个
*/
roleIds:string[]
}
/**
* 根据身份组ID查询已存在的白/黑名单身份组
*/
getExistingWhiteBlackRoles(options: GetExistingWhiteBlackRolesOptions): Promise<GetExistingWhiteBlackRolesResult>
示例代码
const qchat = new QChat(options);
qchat.qchatChannel.getExistingWhiteBlackRoles({
"serverId": "934978",
"channelId": "869726",
"type": "white",
"roleIds": ["640090"]
})
批量查询频道黑白名单成员列表
如有权限管理黑白名单,可更新频道的黑白名单身份组:
接口
type GetExistingWhiteBlackMembersOptions ={
/**
* 服务器ID
*/
serverId: string;
/**
* 频道 ID
*/
channelId: string;
/**
* 类型
*
* 1. 针对公开的频道 {@link ChannelInfo.viewMode | ChannelInfo.viewMode} 为 0,接口只允许设置黑名单,type 传 "black"
*
* 2. 针对私密的频道 {@link ChannelInfo.viewMode | ChannelInfo.viewMode} 为 1,接口只允许设置白名单,type 传 "white"
*/
type: keyof typeof EWhiteBlackType;
/**
* 账号 数组 , 最多100个
*/
accids:string[]
}
/**
* 根据成员ID查询已存在的白/黑名单的成员
*/
getExistingWhiteBlackMembers(options:GetExistingWhiteBlackMembersOptions):Promise<GetExistingWhiteBlackMembersResult>
示例代码
const qchat = new QChat(options);
qchat.qchatChannel.getExistingWhiteBlackMembers({
"serverId": "934978",
"channelId": "869726",
"type": "white",
"accids": ["ctt1"]
})