# 获取指定消息的内容

通过 message_id 查询消息内容。

注意事项:

  • 需要开启机器人能力
  • 机器人必须在群组中
  • 查询消息卡片(compressive_card)时,将不会返回消息内容

# 请求

基本
HTTP URL https://hi-gw.weizhipin.com/open-apis/im/messages/:message_id
HTTP Method GET
支持的应用类型 自建应用
商店应用
权限要求开启任一权限即可 获取用户给机器人发送的信息

# 请求头

名称 类型 必填 描述
Authorization string tenant_access_token
值格式:"Bearer access_token"
示例值:"Bearer t-7f1bcd13fc57d46bac21793a18e560"
Content-Type string 固定值:"application/json; charset=utf-8"

# 路径参数(url中冒号标识的参数,如":xxxx"请连同:整体替换成对应值)

名称 类型 描述
message_id string 待获取消息内容的消息的ID
示例值:"150402"

# 查询参数

名称 类型 必填 描述
user_id_type string 控制回显文本用户 ID 类型,如sender对象的id 示例值:"open_id"
可选值有:
open_id:用户的 open id
union_id:用户的 union id
user_id:用户的 user id
默认值:open_id
当值为 user_id,字段权限要求:
获取用户 user ID

# 响应

# 响应体

名称 类型 描述
code int 错误码,非 0 表示失败
msg string 错误描述
data - -
 ∟message_id string 消息id
 ∟root_id string 根消息id
 ∟parent_id string 父消息的id
 ∟msg_type string 消息类型 包括:image、 compressive_card、 rich_text、tex等
 ∟create_time string 消息生成的时间戳(毫秒)
 ∟update_time string 消息更新的时间戳(毫秒)
 ∟deleted boolean 消息是否被撤回
 ∟updated boolean 消息是否被更新
 ∟chat_id string 所属的群
 ∟sender sender 发送者,可以是用户或应用
 ∟ ∟id string 该字段标识发送者的id
 ∟ ∟id_type string 该字段标识发送者的id类型
 ∟ ∟sender_type string 该字段标识发送者的类型
 ∟body message_body 消息内容
 ∟ ∟content string 消息内容,json结构序列化后的字符串。不同msg_type对应不同内容。消息类型 包括:image、 system_card、 rich_text、text等) ;
注意: 当消息类型为消息卡片(compressive_card)时,返回的消息内容为""
 ∟mentions mention[] 被@的用户或机器人的id列表
 ∟ ∟id string 被@的用户或者机器人的open_id
 ∟ ∟id_type string 被@的用户或机器人 id 类型,目前仅支持 open_id
 ∟upper_message_id string 合并转发消息中,上一层级的消息id message_id

# 响应体示例

{
  "code": 0,
  "traceId": "_Ao59UOIBLPCeAAu",
  "success": true,
  "data": {
    "message_id": "c909a40e9ed292b31kEWDPHnxajTLa0~",
    "root_id": "07b5df7e131fbe2e1w~~",
    "parent_id": "07b5df7e131fbe2e1w~~",
    "msg_type": "text",
    "create_time": "1680593068000",
    "update_time": "1680593068000",
    "deleted": false,
    "updated": false,
    "chat_id": null,
    "sender": {
      "id": null,
      "idType": null,
      "senderType": "IM机器人",
      "tenantKey": "327ab1e8160c0b783kUZ"
    },
    "body": {
       "content": "{\"atIdList\":[\"-1\",\"ou_d30ebbab92f41742a20ac0969476857f\",\"ou_464a93783034963bfb77ad3bce3354d9\"],\"text\":\" ​@所有人⁠    ​@娄修俊⁠   ​@陈世伟⁠ test\"}"
    },
    "mentions": [
      {
        "id": "-1",
        "id_type": "open_id",
        "tenant_key": "327ab1e8160c0b783kUZ"
      },
      {
        "id": "ou_d30ebbab92f41742a20ac0969476857f",
        "id_type": "open_id",
        "tenant_key": "327ab1e8160c0b783kUZ"
      },
      {
        "id": "ou_464a93783034963bfb77ad3bce3354d9",
        "id_type": "open_id",
        "tenant_key": "327ab1e8160c0b783kUZ"
      }
    ],
    "upper_message_id": null
  },
  "msg": "操作成功"
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
最后更新于 : 3/4/2024, 3:29:16 PM