# 接收消息

机器人接收到用户发送的消息后触发此事件。

注意事项:

  • 需要开启 机器人能力,并订阅 消息与群组 分类下的 接收消息 事件才可接收推送
  • 同时,将根据应用具备的权限,判断可推送的信息:
    • 当具备 获取用户发给机器人的单聊消息权限或者 读取用户发给机器人的单聊消息(历史权限),可接收与机器人单聊会话中用户发送的所有消息
    • 当具备 获取用户在群组中@机器人的消息 权限或者 获取用户在群聊中@机器人的消息(历史权限),可接收机器人所在群聊中用户 @机器人的消息

# 事件

基本
事件类型 im.message.receive
支持的应用类型 自建应用
权限要求
开启任一权限即可
获取用户在群组中@机器人的消息
接收群聊中@机器人消息事件
读取用户发给机器人的单聊消息
获取用户发给机器人的单聊消息
字段权限要求 该接口返回体中存在下列敏感字段,仅当开启对应的权限后才会返回;如果无需获取这些字段,则不建议申请
获取用户 user ID
推送方式 Webhook

# 事件体

名称 类型 描述
schema string 事件模式
header event_header 事件头
 ∟event_id string 事件 ID
 ∟event_type string 事件类型
 ∟create_time string 事件创建时间戳(单位:毫秒)
 ∟token string 事件 Token
 ∟app_id string 应用 ID
 ∟tenant_key string 租户 Key
event event_sender
 ∟sender event_sender 事件的发送者
  ∟∟sender_id user_id 用户 ID
   ∟∟∟union_id string 用户的 union id
   ∟∟∟user_id string 用户的 user id 字段权限要求:
获取用户 user ID
   ∟∟∟open_id string 用户的 open id
  ∟∟sender_type string 消息发送者类型。目前只支持用户(user)发送的消息。
  ∟∟tenant_key string tenant key,为租户在BOSSHI上的唯一标识,用来换取对应的tenant_access_token,也可以用作租户在应用里面的唯一标识
 ∟message event_message 事件中包含的消息内容
  ∟∟message_id string 消息的open_message_id
  ∟∟root_id string 根消息id,用于回复消息场景
  ∟∟parent_id string 父消息的id,用于回复消息场景
  ∟∟create_time string 消息发送时间(毫秒)
  ∟∟chat_id string 消息所在的群组 ID
  ∟∟chat_type string 消息所在的群组类型,单聊(p2p)或群聊(group)
  ∟∟message_type string 消息类型 具体参见 各类型消息Content
  ∟∟content string 消息内容, json 格式 不同的message_type 消息体格式不同 具体参见 各类型消息Content
  ∟∟mentions mention_event[] 被提及用户的信息
   ∟∟∟key string mention key
   ∟∟∟id user_id 用户 ID
    ∟∟∟∟union_id string 用户的 union id
    ∟∟∟∟user_id string 用户的 user id
字段权限要求:
获取用户 user ID
    ∟∟∟∟open_id string 用户的 open id
   ∟∟∟name string 用户姓名
   ∟∟∟tenant_key string tenant key,为租户在BOSSHI上的唯一标识,用来换取对应的tenant_access_token,也可以用作租户在应用里面的唯一标识

# 事件体示例

字段值仅为示例值

{
    "schema": "1.0",
    "header": {
        "event_id": "5e3702a84e847582be8db7fb73283c02",
        "event_type": "im.message.receive",
        "create_time": "1608725989000",
        "token": "rvaYgkND1GOiu5MM0E1rncYC6PLtF7JV",
        "app_id": "bli_9f5343c580712544",
        "tenant_key": "2ca1d211f64f6438"
    },
    "event": {
        "sender": {
            "sender_id": {
                "union_id": "on_8ed6aa67826108097d9ee143816345",
                "user_id": "1122334455",
                "open_id": "ou_84aad35d084aa403a838cf73ee18467"
            },
            "sender_type": "user",
            "tenant_key": "736588c9260f175e~"
        },
        "message": {
            "message_id": "5ce6d572455d361153b7cb51da133945~",
            "root_id": "5ce6d572455d361153b7cb5xxfsd~",
            "parent_id": "5ce6d572455d361153b7cb5xx~",
            "create_time": "1609073151345",
            "chat_id": "5ce6d572455d361153b7xN~",
            "chat_type": "group",
            "message_type": "text",
            "content": "{\"text\":\"@_user_1 hello\"}",
            "mentions": [
                {
                    "key": "@_user_1",
                    "id": {
                        "union_id": "on_8ed6aa67826108097d9ee143816345",
                        "user_id": "1122334455",
                        "open_id": "ou_84aad35d084aa403a838cf73ee18467"
                    },
                    "name": "Tom",
                    "tenant_key": "736588c9260f175e~"
                }
            ]
        }
    }
}
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
最后更新于 : 4/27/2023, 9:29:53 PM