会话能力
会话能力
打开聊天会话
matrix.openChat(params)
跳转到指定的聊天会话页面。此接口需要先调用 config 授权后才能使用。
请求参数
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| id | String | 必填 | 会话 ID |
| type | Number | 必填 | 会话类型(1=单聊,2=群聊) |
| onSuccess | Function | 必填 | 成功回调 |
| onFail | Function | 必填 | 失败回调 |
调用示例
matrix.openChat({
id: '12345',
type: 1,
onSuccess: function() {
console.log('已打开会话');
},
onFail: function(error) {
console.error('打开失败:', error.message);
}
});
选择会话
matrix.chooseChat(params)
打开会话选择页面,让用户选择一个或多个会话。此接口需要先调用 config 授权后才能使用。
请求参数
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| onSuccess | Function | 必填 | 成功回调 |
| onFail | Function | 必填 | 失败回调 |
返回参数
| 参数名 | 类型 | 说明 |
|---|---|---|
| sessions | Array | 选中的会话列表 |
sessions 数组元素结构
| 字段名 | 类型 | 说明 |
|---|---|---|
| id | String | 会话 ID |
| type | Number | 会话类型(1=单聊,2=群聊) |
调用示例
// 默认多选,显示最近聊天列表
matrix.chooseChat({
onSuccess: function(data) {
console.log('选中的会话:', data.sessions);
data.sessions.forEach(function(session) {
console.log('会话ID:', session.id);
console.log('类型:', session.type === 1 ? '单聊' : '群聊');
});
},
onFail: function(error) {
if (error.code === -2) {
console.log('用户取消选择');
} else {
console.error('选择失败:', error.message);
}
}
});