Skip to content

消息内容(content)结构说明

本文介绍发送消息、批量发送消息、更新消息、获取消息内容等接口中各消息类型(msg_type)对应的消息内容(content)应如何构造 本文不适用于webhook机器人,webhook机器人使用方式需参考webhook机器人使用指南

文本(text)

消息类型为文本 type=text 时,传递的内容 content 对象

名称参数类型是否必填说明
textobject文本消息
支持通过在消息体插入标签的方式 at 人
例子:你好 <at id="0"> 张三 </at>
∟ contentstring文本内容
∟ typestring文本类型
plain:纯文本;markdown
json
{
  // 文本
  "type": "text",
  "receivers": [],
  "mentions": [],
  "content": {
    "text": {
      "content": "string",
      "type": "string"
    }
  }
}

富文本(rich_text)

消息类型为富文本 type=rich_text 时,传递的内容 content 对象

名称参数类型是否必填说明
rich_textobject富文本消息
∟ elementsarray富文本消息内容
∟ ∟ typestring富文本元素类型
ol:有序列表;ul:无序列表;nl:换行;text:普通文本;
emoji:表情;custom_emoji:自定义表情;mention:at 人;image:图片
∟ ∟ alt_textstring代替文本摘要,当客户端无法解析则取该字段
∟ ∟ indentinteger缩进
∟ ∟ indexinteger第几行
∟ ∟ elementsarray子元素列表,与父元素 element 结构相同(递归)
∟ ∟ text_contentobject【1】纯文本内容, 当富文本元素类型为表情 emoji 时使用
∟ ∟ ∟ contentstring文本内容
∟ ∟ ∟ typestring文本类型
plain:纯文本;markdown
∟ ∟ style_text_contentobject【2】有样式的文本内容,当富文本元素类型为普通文本 text 时使用
∟ ∟ ∟ styleobject元素样式
∟ ∟ ∟ ∟ boldboolean加粗
∟ ∟ ∟ ∟ colorstringRGBA 16 进制描述,例如:#FF0000FF,最后两位为透明度
∟ ∟ ∟ ∟ italicboolean斜体
∟ ∟ mention_contentobject【3】at 人的内容,当富文本元素类型为 at 人 mention 时使用
∟ ∟ ∟ identityobject被 at 用户的 id,当 at 所有人时该值为空
∟ ∟ ∟ ∟ avatarstring用户头像
∟ ∟ ∟ ∟ company_idstring企业 id
∟ ∟ ∟ ∟ idstring用户信息
∟ ∟ ∟ ∟ namestring用户名称
∟ ∟ ∟ ∟ typestring身份类型
user:用户;sp:服务主体
∟ ∟ ∟ textstring被 at 的文本内容
∟ ∟ image_contentobject【4】图片内容,当富文本元素类型为自定义表情 custom_emoji 或 图片 image 时使用
∟ ∟ ∟ sizeinteger图片大小(B)
∟ ∟ ∟ heightinteger高度(px)
∟ ∟ ∟ widthinteger宽度(px)
∟ ∟ ∟ namestring图片名称
∟ ∟ ∟ typestring图片格式,可传值:
image/pngimage/jpgimage/gifimage/webp
∟ ∟ ∟ storage_keystring图片存储 key
∟ ∟ ∟ thumbnail_typestring缩略图片格式,可传值:
image/pngimage/jpgimage/gifimage/webp
∟ ∟ ∟ thumbnail_storage_keystring缩略图片存储 key
∟ ∟ link_contentobject【5】链接的内容,当富文本元素类型为 link 时使用
∟ ∟ ∟ textstring文本内容
∟ ∟ ∟ urlstringurl 链接
json
{
  // 富文本
  "type": "rich_text",
  "receivers": [],
  "mentions": [],
  "content": {
    "rich_text": {
      "elements": [
        {
          "type": "string",
          "alt_text": "string",
          "indent": 0,
          "index": 0,
          "elements": [
            {
              // 与父元素 elements 结构相同(递归)
            }
          ],
          "text_content": {
            "content": "string",
            "type": "string"
          },
          "style_text_content": {
            "style": {
              "bold": false,
              "color": "string",
              "italic": false
            },
            "text": "string"
          },
          "mention_content": {
            "identity": {
              "avatar": "string",
              "company_id": "string",
              "id": "string",
              "name": "string",
              "type": "string"
            },
            "text": "string",
            "type": "string"
          },
          "image_content": {
            "height": 0,
            "name": "string",
            "size": 0,
            "storage_key": "string",
            "thumbnail_storage_key": "string",
            "thumbnail_type": "string",
            "type": "string",
            "width": 0
          },
          "link_content": {
            "text": "string",
            "url": "string"
          }
        }
      ]
    }
  }
}

图片(image)

消息类型为图片 type=image 时,传递的内容 content 对象

名称参数类型是否必填说明
imageobject图片消息
∟ typestring图片格式,可传值:
image/pngimage/jpgimage/gifimage/webp
∟ thumbnail_typestring缩略图片格式,可传值:
image/pngimage/jpgimage/gifimage/webp
∟ namestring图片名称
∟ sizeinteger图片大小(B),不传默认按原图比例和大小展示
∟ widthinteger宽度(px),不传默认按原图比例和大小展示
∟ heightinteger高度(px),不传默认按原图比例和大小展示
∟ storage_keystring图片存储 key
∟ thumbnail_storage_keystring缩略图片存储 key
json
{
  // 图片
  "type": "image/png",
  "receivers": [],
  "mentions": [],
  "content": {
    "image": {
      "type": "string",
      "thumbnail_type": "string",
      "name": "string",
      "size": 0,
      "width": 0,
      "height": 0,
      "storage_key": "string",
      "thumbnail_storage_key": "string"
    }
  }
}

文件(file)

消息类型为文件 type=file 时,传递的内容 content 对象

  • 发送本地文件,即文件类型为 local
名称参数类型是否必填说明
fileobject文件消息
∟ typestring文件类型:固定为local:本地文件
∟ localobject本地文件
∟ ∟ namestring文件名称
∟ ∟ sizeinteger文件大小(B)
∟ ∟ storage_keystring文件存储 key
json
{
  // 文件
  "type": "file",
  "receivers": [],
  "mentions": [],
  "content": {
    "file": {
      // 本地文件
      "type": "local",
      "local": {
        "name": "string",
        "size": 0,
        "storage_key": "string"
      }
    }
  }
}

音频(audio)

消息类型为音频 type=audio 时,传递的内容 content 对象

名称参数类型是否必填说明
audioobject音频消息
∟ mediaobject音频媒体信息
∟ ∟ channelsinteger通道数
∟ ∟ codecstring编码格式
amr
∟ ∟ durationinteger播放时长(s)
∟ ∟ formatstring文件格式
wav
∟ ∟ sample_bitsinteger比特率
∟ ∟ sample_rateinteger采用率
∟ ∟ sizeinteger文件大小(B)
∟ storage_keystring音频文件存储 key
json
{
  // 音频
  "type": "audio",
  "receivers": [],
  "mentions": [],
  "content": {
    "audio": {
      "media": {
        "channels": 0,
        "codec": "string",
        "duration": 0,
        "format": "string",
        "sample_bits": 0,
        "sample_rate": 0,
        "size": 0
      },
      "storage_key": "string"
    }
  }
}

视频(video)

消息类型为音频 type=video 时,传递的内容 content 对象

名称参数类型是否必填说明
videoobject视频消息
∟ mediaobject视频媒体信息
∟ ∟ codecstring编码格式
h.264
∟ ∟ cover_storage_keystring视频文件封面图片存储 key
∟ ∟ durationinteger播放时长(s)
∟ ∟ formatstring文件格式
mp4
∟ ∟ heightinteger高度(px)
∟ ∟ sizeinteger文件大小(B)
∟ ∟ widthinteger宽度(px)
∟ storage_keystring视频文件存储 key
json
{
  // 视频
  "type": "audio",
  "receivers": [],
  "mentions": [],
  "content": {
    "video": {
      "media": {
        "codec": "string",
        "cover_storage_key": "string",
        "duration": 0,
        "format": "string",
        "height": 0,
        "size": 0,
        "width": 0
      },
      "storage_key": "string"
    }
  }
}

卡片(card)

消息卡片是应用接入WPS协作机器人发送消息时的一种消息类型。消息卡片提供了丰富的组件,支持开发者按需组合配置消息卡片。详细说明可看WPS协作卡片介绍WPS协作卡片结构说明

为了提升卡片的搭建效率,WPS开放平台也为开发者提供了可视化的消息卡片搭建工具,开发者可进入开发者后台-应用能力-WPS协作机器人-发送消息-API发送-消息卡片编辑器处进行配置。

消息类型为卡片 type=card 时,传递的内容 content 对象

名称参数类型是否必填说明
cardobject卡片消息
∟ configobject
∟ linkobject卡片整体的跳转链接
∟ i18n_itemsarray卡片的内容,支持多语言
json
{
  "type": "card",
  "receivers": [],
  "mentions": [],
  "content": {
    "card": {
      "config": {
      },
      "i18n_items": [
        {
        }
      ],
      "link": {
      }
    }
  }
}

如何在消息内@人

消息接口支持在markdown格式的文本内,通过在消息体 content 中插入<at>标签的方式@人。目前支持markdown文本的消息类型有:文本(text)、富文本(rich_text)、卡片(card)

使用步骤如下:

1.在对应消息类型的content内,使用<at>标签的方式写入@内容,有2种使用格式:

  • @单个用户:<at id=\"2\">展示名称</at>
  • @所有人:<at id=\"1\">所有人</at>,id固定为1

请注意,上述的id仅用来代表索引,在下述第2步中会使用到,并不是用户user_id

2.在该接口的请求体mentions部分,传参上述的索引和具体的用户user_id。具体写法和对应关系请看示例图:

艾特人