Send messages with a bot
Message types
You can send bot messages in two ways: by calling an API or by using a Webhook. The supported message types and data formats vary by method.We recommend that you send messages by calling an API.
Method 1: Call an API
Important
- Bot messages in one-on-one chats between a user and the bot: support sending and receiving images, voice messages, and files.
- Bot messages in group chats: the bot can send images, voice messages, videos, and files. However, users cannot @ the bot to send voice messages, videos, or files to it in a group chat.
Available APIs
Data format
- Message template key: a unique identifier used when developers send messages. It allows the code to quickly reference a predefined message template.
-
Message template parameters: the actual data used to replace predefined placeholders in the message template. For example, when the message template key is
sampleText, you need to set the value of thecontentfield. -
Example: the following HTTP example shows how an internal app bot sends a text message to a group:
- Message template key:
"msgKey" : "sampleText" - Message template parameters:
"msgParam" : "{\"content\":\"DingTalk, where progress happens\"}"
- Message template key:
Supported Markdown syntax
Additional notes on the Markdown syntax for the sampleMarkdown message type.
Method 2: Use a Webhook
Webhooks are supported only in group chats.
Text message
Link message
This type does not support @ People.
Markdown message
Only a subset of Markdown syntax is currently supported. The supported elements are listed below:
ActionCard message
-
Whole-card jump ActionCard
-
Independent-jump ActionCard
FeedCard message
This type does not support @ People.
To skip replying to the group, use the following format:
Receive messages with a bot
When a user @ the group bot or sends a direct message to the bot, DingTalk forwards the received message to the bot callback service configured by the developer.Message body
The following example uses the text message type. If you use HTTP callbacks, DingTalk delivers the message with a POST request.Message types
Bots can currently receive messages of the following types: text, voice, image, file, video, and Rich Text. The fields for each message type are explained below. Other than the message type and message body fields, the parameters are the same as in the table above.Text message
Rich Text message
Image message
Voice message
In Group Chat conversations, the bot does not support receiving voice messages when a Group member @ the bot.
Video message
In Group Chat conversations, the bot does not support receiving video messages when a Group member @ the bot.
File message
In Group Chat conversations, the bot does not support receiving file messages when a Group member @ the bot.
Related content
If you select HTTP mode as the message receiving mode when creating an internal app bot, the HTTP header parameters shown below are included along with the message body when the bot receives a message:
You must verify the timestamp and sign in the header to confirm that the request is a legitimate request from DingTalk and to prevent third parties from impersonating DingTalk to call your HTTPS service. The verification rules are as follows:
- If the difference between the timestamp and the current system timestamp is greater than 1 hour, the request is considered illegitimate.
- If the sign does not match the signature value you calculate, the request is considered illegitimate.
Error codes
When the bot Webhook or Stream usage exceeds the quota, the following behavior occurs:Error behavior
Group Chat conversations
Direct Message conversations
Error description
Related documents
- Send group chat messages with an Enterprise bot
- Send one-on-one messages with an Enterprise bot
- Send group chat messages with a Custom bot
- Send group chat messages with a group template bot