> ## Documentation Index
> Fetch the complete documentation index at: https://help.dingtalk.io/llms.txt
> Use this file to discover all available pages before exploring further.

# 消息类型和数据格式

> 本文介绍了通过接口发送机器人消息和Webhook的方式发送机器人消息的消息类型和数据格式。

## 消息类型和数据格式

发送机器人消息的方式有2种，通过 **接口发送** 机器人消息和通过 **Webhook发送** 机器人消息。不同的方式，支持的消息类型和数据格式不同。

**说明**

推荐使用接口方式发送消息。

| 消息类型         | 接口方式发送机器人消息 | Webbook方式发送机器人消息 |
| ------------ | ----------- | ---------------- |
| Text文本类型     | ✅           | ✅                |
| Markdown类型   | ✅           | ✅                |
| 图片Image类型    | ✅           | ❌                |
| ActionCard类型 | ✅           | ✅                |
| FeedCard类型   | ❌           | ✅                |
| Link链接消息     | ✅           | ✅                |

## 接口方式支持的消息类型和数据格式

### 适用接口

* [批量发送单聊消息](/zh/open/development/chatbots-send-one-on-one-chat-messages-in-batches)
* [企业机器人向内部群发消息](/zh/open/development/the-robot-sends-a-group-message)

### 数据格式

| 消息类型              | 消息模板Key                                                                                                                                                                                                                                                                                                                                | 消息模板参数                                                                                                                                                        | 说明             |
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- |
| 文本类型              | sampleText                                                                                                                                                                                                                                                                                                                             | `&#123;       "content": "xxxx"   &#125;`                                                                                                                     |                |
| Markdown类型        | sampleMarkdown                                                                                                                                                                                                                                                                                                                         | `&#123;     "title": "xxxx"，     "text": "xxxx"   &#125;`                                                                                                     |                |
| 图片类型              | sampleImageMsg                                                                                                                                                                                                                                                                                                                         | `&#123;     "photoURL": "xxxx"   &#125;`                                                                                                                      |                |
| 链接类型              | sampleLink                                                                                                                                                                                                                                                                                                                             | `&#123;           "text": "消息内容测试",      "title": "sampleLink消息测试",      "picUrl": "@lADOADmaWMzazQKA",      "messageUrl": "http://dingtalk.com"      &#125;` | 链接消息。          |
| ActionCard类型      | sampleActionCard                                                                                                                                                                                                                                                                                                                       | `&#123;      "title": "测试标题",      "text": "内容测试",      "singleTitle": "查看详情",      "singleURL": "https://open.dingtalk.com" &#125;`                          | 卡片消息：一个按钮。一个按钮 |
| sampleActionCard2 | `&#123;      "title": "消息标题测试",      "text": "消息正文测试",      "actionTitle1": "一个按钮",      "actionURL1": "https://www.taobao.com",      "actionTitle2": "两个按钮",      "actionURL2": "https://www.tmall.com" &#125;`                                                                                                                       | 卡片消息：竖向二个按钮。两个按钮竖直按钮                                                                                                                                          |                |
| sampleActionCard3 | `&#123;      "title": "消息标题测试",      "text": "消息内容测试",      "actionTitle1": "第一个按钮的文本",      "actionURL1": "第一个按钮触发的url",      "actionTitle2": "第二个按钮的文本",      "actionURL2": "第二个按钮触发的url",      "actionTitle3": "第三个按钮的文本",      "actionURL3": "第三个按钮触发的url" &#125;`                                                                 | 卡片消息：竖向三个按钮。                                                                                                                                                  |                |
| sampleActionCard4 | `&#123;   "title":"消息标题测试", "text":"消息内容测试", "actionTitle1":"第一个按钮的文本", "actionURL1":"第一个按钮触发的url", "actionTitle2":"第二个按钮的文本", "actionURL2":"第二个按钮触发的url", "actionTitle3":"第三个按钮的文本", "actionURL3":"第三个按钮触发的url", "actionTitle4":"第四个按钮的文本", "actionURL4":"第四个按钮触发的url" &#125;`                                                        | 卡片消息：竖向四个按钮。                                                                                                                                                  |                |
| sampleActionCard5 | `&#123;   "title":"消息标题测试", "text":"消息内容测试", "actionTitle1":"第一个按钮的文本", "actionURL1":"第一个按钮触发的url", "actionTitle2":"第二个按钮的文本", "actionURL2":"第二个按钮触发的url", "actionTitle3":"第三个按钮的文本", "actionURL3":"第三个按钮触发的url", "actionTitle4":"第四个按钮的文本", "actionURL4":"第四个按钮触发的url", "actionTitle5":"第五个按钮的文本", "actionURL5":"第五个按钮触发的url" &#125;` | 卡片消息：竖向五个按钮。                                                                                                                                                  |                |
| sampleActionCard6 | `&#123;     "title": "xxxx",     "text": "xxxx",     "buttonTitle1":"xxxxx",     "buttonUrl1":"xxxxx",     "buttonTitle2":"xxxxx",     "buttonUrl2":"xxxxx"   &#125;`                                                                                                                                                                  | 卡片消息：横向二个按钮。横向按钮                                                                                                                                              |                |

## Webhook方式支持的消息类型和数据格式

### 适用范围

**说明**

webhook方式只支持在群聊会话。

Webhook发送消息的实现方式，请参考企业内部机器人使用Webhook发送群聊消息和自定义机器人接入。

### 数据格式

* **文本text类型**

  ```
  {
      "at": {
          "atMobiles": [
              "180xxxxxx"
          ],
          "atUserIds": [
              "user123"
          ],
          "isAtAll": false
      },
      "text": {
          "content": "我就是我, @180xxxxxx 是不一样的烟火"
      },
      "msgtype": "text"
  }
  ```

  | **参数**    | **是否必填** | **类型**  | **说明**                                                               |
  | --------- | -------- | ------- | -------------------------------------------------------------------- |
  | msgtype   | 是        | String  | text。                                                                |
  | content   | 是        | String  | 消息文本。                                                                |
  | atMobiles | 否        | Array   | 被@人的手机号。  **说明**  消息内容content中要带上"@手机号"，跟atMobiles参数结合使用，才有@效果，如上示例。 |
  | atUserIds | 否        | Array   | 被@人的用户userid。                                                        |
  | isAtAll   | 否        | Boolean | @所有人是true，否则为false。                                                  |

  ![777.png ](https://help-static-aliyun-doc.aliyuncs.com/assets/img/zh-CN/4099076061/p131215.png)
* **链接Link类型**

  ```
  {
      "msgtype": "link", 
      "link": {
          "text": "这是Link消息", 
          "title": "这是一个Link消息", 
          "picUrl": "https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png", 
          "messageUrl": "https://open.dingtalk.com/document/"
      }
  }
  ```

  | **参数**     | **参数类型** | 是否必填 | **说明**           |
  | ---------- | -------- | ---- | ---------------- |
  | msgtype    | String   | 是    | 消息类型，此时固定为：link。 |
  | title      | String   | 是    | 消息标题。            |
  | text       | String   | 是    | 消息内容。如果太长只会部分展示。 |
  | messageUrl | String   | 是    | 点击消息跳转的URL。      |
  | picUrl     | String   | 否    | 图片URL。           |

  ![link消息 ](https://help-static-aliyun-doc.aliyuncs.com/assets/img/zh-CN/5566042461/p385786.png)
* **Markdown类型**

  ```
  {
       "msgtype": "markdown",
       "markdown": {
           "title":"杭州天气",
           "text": "#### 杭州天气 @150XXXXXXXX \n> 9度，西北风1级，空气良89，相对温度73%\n> ![screenshot](https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png)\n> ###### 10点20分发布 [天气](https://www.dingalk.com) \n"
       },
        "at": {
            "atMobiles": [
                "150XXXXXXXX"
            ],
            "atUserIds": [
                "user123"
            ],
            "isAtAll": false
        }
   }
  ```

  | **参数**    | **是否必填** | **类型**  | **说明**                                                            |
  | --------- | -------- | ------- | ----------------------------------------------------------------- |
  | msgtype   | 是        | String  | markdown。                                                         |
  | title     | 是        | String  | 首屏会话透出的展示内容。                                                      |
  | text      | 是        | String  | Markdown格式的消息内容。                                                  |
  | atMobiles | 否        | Array   | 被@人的手机号。  **说明**  消息内容text内要带上"@手机号"，跟atMobiles参数结合使用，才有@效果，如上示例。 |
  | atUserIds | 否        | Array   | 被@人的用户userid。                                                     |
  | isAtAll   | 否        | Boolean | @所有人是true，否则为false。                                               |

  ![image.png ](https://help-static-aliyun-doc.aliyuncs.com/assets/img/zh-CN/4099076061/p131216.png)目前只支持Markdown语法的子集，支持的元素如下：

  ```
  标题
  # 一级标题
  ## 二级标题
  ### 三级标题
  #### 四级标题
  ##### 五级标题
  ###### 六级标题
   
  引用
  > A man who stands for nothing will fall for anything.
   
  文字加粗、斜体
  **bold**
  *italic*
   
  链接
  [this is a link](https://www.dingtalk.com/)
   
  图片
  ![](http://name.com/pic.jpg)
   
  无序列表
  - item1
  - item2
   
  有序列表
  1. item1
  2. item2
  ```
* **整体跳转ActionCard类型**

  ```
  {
      "msgtype": "actionCard",
      "actionCard": {
          "title": "打造一间咖啡厅", 
          "text": "![screenshot](https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png) \n #### 乔布斯 20 年前想打造的苹果咖啡厅 \n\n Apple Store 的设计正从原来满满的科技感走向生活化，而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划",
          "singleTitle" : "阅读全文",
          "singleURL" : "https://www.dingtalk.com/"
      }
  }
  ```

  | **参数**      | **是否必填** | **类型** | **说明**           |
  | ----------- | -------- | ------ | ---------------- |
  | msgtype     | 是        | String | actionCard。      |
  | title       | 是        | String | 首屏会话透出的展示内容。     |
  | text        | 是        | String | markdown格式的消息内容。 |
  | singleTitle | 是        | String | 单个按钮的标题。         |
  | singleURL   | 是        | String | 单个按钮的跳转链接。       |

  ![image.png ](https://help-static-aliyun-doc.aliyuncs.com/assets/img/zh-CN/5099076061/p131217.png)
* **独立跳转ActionCard类型**

  ```
  {
      "msgtype": "actionCard",
      "actionCard": {
          "title": "乔布斯 20 年前想打造一间苹果咖啡厅，而它正是 Apple Store 的前身", 
          "text": "![screenshot](https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png) \n\n #### 乔布斯 20 年前想打造的苹果咖啡厅 \n\n Apple Store 的设计正从原来满满的科技感走向生活化，而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划", 
          "btnOrientation": "0", 
          "btns": [
              {
                  "title": "内容不错", 
                  "actionURL": "https://www.dingtalk.com/"
              }, 
              {
                  "title": "不感兴趣", 
                  "actionURL": "https://www.dingtalk.com/"
              }
          ]
      }
  }
  ```

  | **参数**         | **是否必填** | **类型** | **说明**                              |
  | -------------- | -------- | ------ | ----------------------------------- |
  | msgtype        | 是        | String | actionCard。                         |
  | title          | 是        | String | 首屏会话透出的展示内容。                        |
  | text           | 是        | String | markdown格式的消息内容。                    |
  | btns           | 是        | Array  | 按钮。                                 |
  | title          | 是        | String | 按钮标题。                               |
  | actionURL      | 是        | String | 点击按钮触发的URL。                         |
  | btnOrientation | 否        | String | 按钮排列顺序。  **0**：按钮竖直排列  **1**：按钮横向排列 |

  ![屏幕快照 2019-12-25 下午8.27.52.png ](https://help-static-aliyun-doc.aliyuncs.com/assets/img/zh-CN/5099076061/p131218.png)
* **FeedCard类型**

  ```
  {
      "msgtype": "feedCard",
      "feedCard": {
          "links": [
              {
                  "title": "时代的火车向前开1", 
                  "messageURL": "https://www.dingtalk.com/", 
                  "picURL": "https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png"
              },
              {
                  "title": "时代的火车向前开2", 
                  "messageURL": "https://www.dingtalk.com/", 
                  "picURL": "https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png"
              }
          ]
      }
  }
  ```

  | **参数**     | **是否必填** | **类型** | **说明**        |
  | ---------- | -------- | ------ | ------------- |
  | msgtype    | 是        | String | feedCard。     |
  | title      | 是        | String | 单条信息文本。       |
  | messageURL | 是        | String | 单条信息跳转链接。     |
  | picURL     | 是        | String | 单条信息后面图片的URL。 |

  ![屏幕快照 2019-12-25 下午8.29.45.png ](https://help-static-aliyun-doc.aliyuncs.com/assets/img/zh-CN/5099076061/p131219.png)当不想回复消息到群里时，回复格式如下：

  ```
  {
      "msgtype": "empty"
  }
  ```
