最近在使用 rest API 实时通信 的时候碰到一个问题。

我有一个聊天室:

{
  "name": "测试频道",
  "tr": true,
  "lm": {
    "__type": "Date",
    "iso": "2017-01-05T05:55:56.685Z"
  },
  "objectId": "586da108da2f600055d1548a",
  "createdAt": "2017-01-05T01:27:36.452Z",
  "updatedAt": "2017-01-05T05:55:56.739Z",
  "displayType": "暂态对话"
}

当使用 REST API 向这个对话中发送文本消息的时候,可以正常的发送,在线的用户也都可以正常的接收。

但是用户重新登陆后,在拉取历史记录的时候却没有办法获取这些 REST 发送的消息(不是本地缓存的问题)。

于是登录了控制台,后台显示也没有任何的数据:

但是日志中有显示:

想要问下,是不是通过 REST 发出的信息,不会保存在对话中?谢谢

你好,请粘贴下 App ID、conversation id 和用 RSET API 发的 message id。

App ID: 
fyCPl5T1HGePy8lb2XO43pPw-gzGzoHsz

conversation id:
586da108da2f600055d1548a

我写了几个脚本不停的在REST发送消息做测试,下面是几条iOS 客户端收到的消息的日志

message id:

=========== dumpAVIMTypedMessage ===========
mediaType: 1
text: send test: 21*0381*
attributes: {"type":"room"}
fileUrl: null
locationLatitude: null
locationLongitude: null
size: null
duration: null
format: null
width: null
height: null
ioType: 1
status: 4
messageId: gXHGKELRR8u7EwJgFIFFvA
clientId: robot98207
conversationId: 586da108da2f600055d1548a
content: {"_lcattrs": {"type": "room"}, "_lctext": "send test: 21*0381*", "_lctype": -1}
sendTimestamp: 1483607578824
deliveredTimestamp: null
transient: true
=========== ==================== ===========

=========== dumpAVIMTypedMessage ===========
mediaType: 1
text: send test: *9*3*277
attributes: {"type":"room"}
fileUrl: null
locationLatitude: null
locationLongitude: null
size: null
duration: null
format: null
width: null
height: null
ioType: 1
status: 4
messageId: vMaXDatERkywSgsYU8XjQQ
clientId: robot35821
conversationId: 586da108da2f600055d1548a
content: {"_lcattrs": {"type": "room"}, "_lctext": "send test: *9*3*277", "_lctype": -1}
sendTimestamp: 1483607579805
deliveredTimestamp: null
transient: true

=========== dumpAVIMTypedMessage ===========
mediaType: 1
text: send test: *9*3*277
attributes: {"type":"room"}
fileUrl: null
locationLatitude: null
locationLongitude: null
size: null
duration: null
format: null
width: null
height: null
ioType: 1
status: 4
messageId: vMaXDatERkywSgsYU8XjQQ
clientId: robot35821
conversationId: 586da108da2f600055d1548a
content: {"_lcattrs": {"type": "room"}, "_lctext": "send test: *9*3*277", "_lctype": -1}
sendTimestamp: 1483607579805
deliveredTimestamp: null
transient: true
=========== ==================== ===========

您好,原因是您发的这个消息是暂态消息,在最后一个贴的客户端收到消息的日志中,能看到消息的 transient 参数为 true 表示这是个暂态消息。对于暂态消息是不会写入历史记录的,并且调用 REST API 发消息时消息默认就是暂态消息,我们在 API 的文档上有做强调:https://leancloud.cn/docs/realtime_rest_api.html#通过_REST_API_发消息

暂态消息相关请参看文档关于消息的说明:https://leancloud.cn/docs/realtime_v2.html#消息_Message_