Skip to content
开发文档
能力中心
应用市场
WebOffice
开发者后台

接收消息

事件描述

用户发送给机器人的消息时,会触发此事件。

订阅说明

事件主体kso.app_chat.message
权限要求查询用户组 kso.chat_message.readwrite
解密方式详见 解密算法

事件体(解密前)

名称参数类型说明
topicstring消息主题 kso.app_chat.message
operationstring消息变更动作
create:发送消息
timeinteger时间(秒为单位的时间戳)
noncestringiv 向量(解密时使用)
signaturestring消息签名
encrypted_datastring消息变更的加密字段

事件体示例(解密前)

json
{
  "topic": "kso.app_chat.message",
  "operation": "create",
  "time": 1704074400,
  "nonce": "71***********7",
  "signature": "w6**********6Q",
  "encrypted_data": "B7**********iA=="
}

事件体数据(解密后)

名称参数类型是否必带说明
chatobject会话信息
∟ idstring会话 id
∟ typestring会话类型:p2p(单聊),group(群聊)
company_idstring企业 id
messageobject消息
∟ idstring消息 id
∟ typestring消息类型,参考 发送消息接口文档type
∟ contentstring消息体,参考 发送消息接口文档content
send_timestring消息发送时间戳
senderobject消息发送者
∟ idstring用户 id
∟ typestring用户类型

事件体数据示例(解密后)

  • 给机器人发送消息
json
{
  "chat": {
    "id": "8225957",
    "type": "p2p"
  },
  "company_id": "eueue",
  "message": {
    "content": {
      "text": {
        "content": "666"
      }
    },
    "id": "w7i5fgFzh6uRtOTN",
    "type": "text"
  },
  "send_time": 1734426254026,
  "sender": {
    "id": "erueru",
    "type": "user"
  }
}
  • 群聊@机器人
json
{
  "chat": {
    "id": "8205341",
    "type": "group"
  },
  "company_id": "uduu",
  "message": {
    "content": {
      "text": {
        "content": "\u003cat id=\"1\"\u003eNews\u003c/at\u003e 12323[**]"
      }
    },
    "id": "B2iofLuEfxCmhOfg",
    "mentions": [
      {
        "id": "1",
        "identity": {
          "id": "AK20241127SUGTFW",
          "name": "News",
          "type": "app"
        },
        "type": "user"
      }
    ],
    "type": "text"
  },
  "send_time": 1734943955071,
  "sender": {
    "id": "dududu",
    "type": "user"
  }
}
  • 发送图片
json
{
  "chat": {
    "id": "8225957",
    "type": "p2p"
  },
  "company_id": "eyeyey",
  "message": {
    "content": {
      "image": {
        "height": 433,
        "name": "xiezuodomain20241223-162623.png",
        "size": 35092,
        "storage_key": "DD1****************************************bWc=",
        "type": "image/png",
        "width": 782
      }
    },
    "id": "B2iofLuEfdF5t5uX",
    "type": "image"
  },
  "send_time": 1734942384583,
  "sender": {
    "id": "eyeyey",
    "type": "user"
  }
}
  • 发送本地文件
json
{
  "chat": {
    "id": "8225957",
    "type": "p2p"
  },
  "company_id": "euyeuyeye",
  "message": {
    "content": {
      "file": {
        "local": {
          "name": "**.p12",
          "size": 3483,
          "storage_key": "DD1AFB29YmV0YS8zMWQ1ZDQ5NDQxNDFkZDJlNTNmOGNkNzQwYzIyZWU5ZDprczM6a29hLWltZw=="
        },
        "type": "local"
      }
    },
    "id": "kYi1fEu6fxuOf2t8",
    "type": "file"
  },
  "send_time": 1734942995610,
  "sender": {
    "id": "fuerureu",
    "type": "user"
  }
}
  • 发送云文档
json
{
  "chat": {
    "id": "8225957",
    "type": "p2p"
  },
  "company_id": "eyeeye",
  "message": {
    "content": {
      "file": {
        "cloud": {
          "id": "hCDZ*******************nT1h",
          "link_id": "cohiPYx868pl",
          "link_url": "https://kdocs.cn/l/cohiPYx868pl"
        },
        "type": "cloud"
      }
    },
    "id": "kYi1fEu6fxuwhETb",
    "type": "file"
  },
  "send_time": 1734943103950,
  "sender": {
    "id": "eeeeer",
    "type": "user"
  }
}
  • 发送图文消息(会转成富文本消息)
json
{
  "chat": {
    "id": "8225957",
    "type": "p2p"
  },
  "company_id": "duddu",
  "message": {
    "content": {
      "rich_text": {
        "elements": [
          {
            "alt_text": "",
            "elements": [
              {
                "alt_text": "",
                "indent": 0,
                "index": 0,
                "text_content": {
                  "content": "1"
                },
                "type": "text"
              }
            ],
            "indent": 0,
            "index": 0,
            "type": "nl"
          },
          {
            "alt_text": "",
            "elements": [
              {
                "alt_text": "",
                "indent": 0,
                "index": 0,
                "text_content": {
                  "content": "2"
                },
                "type": "text"
              }
            ],
            "indent": 0,
            "index": 0,
            "type": "nl"
          },
          {
            "alt_text": "",
            "elements": [
              {
                "alt_text": "",
                "image_content": {
                  "height": 433,
                  "name": "d7a87aa182412f26fbdb0adc1e57d4b7.png",
                  "size": 35092,
                  "storage_key": "DD1AFB***************************************9hLWltZw==",
                  "type": "image/png",
                  "width": 782
                },
                "indent": 0,
                "index": 0,
                "type": "image"
              }
            ],
            "indent": 0,
            "index": 0,
            "type": "nl"
          },
          {
            "alt_text": "",
            "elements": [
              {
                "alt_text": "",
                "indent": 0,
                "index": 0,
                "text_content": {
                  "content": "[**][**]"
                },
                "type": "text"
              }
            ],
            "indent": 0,
            "index": 0,
            "type": "nl"
          }
        ]
      }
    },
    "id": "jji2fZuLfguQiZSp",
    "type": "rich_text"
  },
  "send_time": 1734943195838,
  "sender": {
    "id": "yeyweey",
    "type": "user"
  }
}
  • 发送富文本消息
json
{
  "chat": {
    "id": "erer",
    "type": "p2p"
  },
  "company_id": "dudu",
  "message": {
    "content": {
      "rich_text": {
        "elements": [
          {
            "alt_text": "",
            "elements": [
              {
                "alt_text": "",
                "indent": 0,
                "index": 0,
                "style_text_content": {
                  "style": {
                    "bold": true,
                    "color": "",
                    "italic": false
                  },
                  "text": "2234"
                },
                "type": "text"
              }
            ],
            "indent": 0,
            "index": 0,
            "type": "nl"
          },
          {
            "alt_text": "",
            "elements": [
              {
                "alt_text": "",
                "indent": 0,
                "index": 0,
                "style_text_content": {
                  "style": {
                    "bold": false,
                    "color": "",
                    "italic": false
                  },
                  "text": "1"
                },
                "type": "text"
              }
            ],
            "indent": 0,
            "index": 0,
            "type": "ol"
          },
          {
            "alt_text": "",
            "elements": [
              {
                "alt_text": "",
                "indent": 0,
                "index": 0,
                "style_text_content": {
                  "style": {
                    "bold": false,
                    "color": "",
                    "italic": false
                  },
                  "text": "2"
                },
                "type": "text"
              }
            ],
            "indent": 0,
            "index": 1,
            "type": "ol"
          },
          {
            "alt_text": "",
            "elements": [
              {
                "alt_text": "",
                "indent": 0,
                "index": 0,
                "style_text_content": {
                  "style": {
                    "bold": false,
                    "color": "",
                    "italic": false
                  },
                  "text": "3"
                },
                "type": "text"
              }
            ],
            "indent": 0,
            "index": 2,
            "type": "ol"
          },
          {
            "alt_text": "",
            "elements": [
              {
                "alt_text": "",
                "indent": 0,
                "index": 0,
                "style_text_content": {
                  "style": {
                    "bold": false,
                    "color": "",
                    "italic": false
                  },
                  "text": "lol"
                },
                "type": "text"
              }
            ],
            "indent": 0,
            "index": 0,
            "type": "ul"
          },
          {
            "alt_text": "",
            "elements": [
              {
                "alt_text": "",
                "indent": 0,
                "index": 0,
                "style_text_content": {
                  "style": {
                    "bold": false,
                    "color": "",
                    "italic": false
                  },
                  "text": "wangzhe"
                },
                "type": "text"
              }
            ],
            "indent": 0,
            "index": 0,
            "type": "ul"
          },
          {
            "alt_text": "",
            "elements": [
              {
                "alt_text": "",
                "image_content": {
                  "height": 433,
                  "name": "d7a87aa182412f26fbdb0adc1e57d4b7.png",
                  "size": 35092,
                  "storage_key": "DD1AFB*******************************9hLWltZw==",
                  "type": "image/png",
                  "width": 782
                },
                "indent": 0,
                "index": 0,
                "type": "image"
              }
            ],
            "indent": 0,
            "index": 0,
            "type": "nl"
          },
          {
            "alt_text": "",
            "elements": [
              {
                "alt_text": "",
                "indent": 0,
                "index": 0,
                "text_content": {
                  "content": "[**]"
                },
                "type": "emoji"
              },
              {
                "alt_text": "",
                "indent": 0,
                "index": 0,
                "text_content": {
                  "content": "[**]"
                },
                "type": "emoji"
              }
            ],
            "indent": 0,
            "index": 0,
            "type": "nl"
          }
        ]
      }
    },
    "id": "9ViOfWukfZClFBfb",
    "type": "rich_text"
  },
  "send_time": 1734943548129,
  "sender": {
    "id": "euyreur",
    "type": "user"
  }
}
回到旧版