接收历史消息
接口描述
History
接口获取指定频道中存储的历史消息。
接口方法
Shell
GET https://api.sd-rtn.com/rtm/v2/history/{:appId}/userId/{:userId}/channelType/{:channelType}/channel/{:channelName}?start=1234567 & end = 65432111 & messageCount = 100
参数 | 类型 | 必填 | 描述 |
---|---|---|---|
appId | string | 是 | 你的声网项目的 。 |
userId | string | 是 | 此次操作的 User ID。 以下为支持的字符集范围(共 89 个字符):
注意 字符长度限制为:0 < 字符长度 ≤ 64。 |
channelType | string | 是 | 频道类型:
|
channelName | string | 是 | 频道名。 以下为支持的字符集范围(共 89 个字符):
注意 字符长度限制为:0 < 字符长度 ≤ 64。 |
start | long | 否 | 历史消息开始的时间戳,可以为 0,不填默认为 0。 |
end | long | 否 | 历史消息结束的时间戳,可以为 0,不填默认为 0。 |
messageCount | int | 否 | 单次查询的最大消息数。如果单次查询的时间范围内消息数大于该值,则需多次调用该方法进行查询。取值范围为 (0,100],不填默认为 100。 |
基本用法
- cURL
- Node.js
Shell
curl -L 'https://api.sd-rtn.com/rtm/v2/history/{appId}/userId/Tony/channelType/message/channel/chatroom?start=17809876 & end = 1781000 & messageCount = 100' \
-H 'Accept: application/json'
JavaScript
const axios = require('axios');
let config = {
method: 'get',
maxBodyLength: Infinity,
url: 'https://api.sd-rtn.com/rtm/v2/history/{:appId}/userId/Tony/channelType/message/channel/chatroom?start=17809876 & end = 1781000 & messageCount = 100',
headers: {
'Accept': 'application/json'
'Authorization': 'agora token=007xxxxx'
}
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
返回值
执行后将返回以下数据:
JSON
{
errorCode: 200,
error: false,
requestId: 1121_1234231,
operation: "getMessage",
reason: "xxxxxxxxxxxx",
timestamp:1234567,
data:{
messageList: HistoryMessage[];
count: number,
newStart: number
}
}
其中,HistoryMessage
结构如下:
JSON
{
messageType: "STRING",
message: "xxxxxxxxxx",
customType: "xxx",
publisher: "xxxxx",
timestamp:1234567
}
参数 | 类型 | 描述 |
---|---|---|
errorCode | number | 错误码。200 表示请求成功。如果不为 200,你可以参考错误码了解出错的原因并进行排障。 |
error | boolean | 当前请求是否出错。
|
requestId | string | 当前请求的请求 ID。 |
operation | string | 当前请求的具体操作。 |
reason | string | 出错原因。 |
timestamp | number | 发送请求的时间戳。 |
data | object | 响应的具体 Payload 信息,包含如下字段:
|