Background
Bots can receive messages in two modes: Stream mode and HTTP mode. This document describes how to receive messages in both modes.Prerequisites
- Complete the Create an app process.
- Complete the process of adding app capabilities.
Procedure
Stream mode (recommended)
For more languages, refer to the Server-side Stream mode documentation.
- Prepare the Java development environment:
- Runtime: JDK 1.8 or later
-
Install the Java SDK:
Add the dependency to your project’s
pom.xmlfile or download the corresponding JAR package. You can view and download the latest SDK version here.
-
Server-side integration example:
Name Description ClientId The ClientId of the Internal app credential. ClientSecret The ClientSecret of the Internal app credential. topic The Bot callback name. Fixed value: /v1.0/im/bot/messages/get. -
After the development is complete, add the Bot to a group. When you send “Hello” by @ the Bot, the server receives a message in the following format:
Name Description conversationId The conversation ID. atUsers Information about the @ mentioned users: - dingtalkId: The encrypted sender ID. chatbotCorpId The organization ID where the Bot resides. chatbotUserId The encrypted Bot ID. No use case for now; can be ignored. msgId The encrypted message ID. No use case for now; can be ignored. senderNick The sender’s name. isAdmin Whether the sender is an Admin. senderStaffId The user ID of the person who @ the Bot in the internal group. sessionWebhookExpiredTime The expiration time of the Webhook URL for the current chat. createAt The message timestamp, in milliseconds. senderCorpId The organization ID of the sender’s current group, available only in internal groups. conversationType The conversation type: - 1: Direct Message - 2: Group Chat senderId The encrypted sender ID. Note Use senderStaffId, which is the sender’s userId value. conversationTitle The chat title, available only in group chats. isInAtList Whether the user is in the @ list. sessionWebhook The Webhook URL for the current chat. text The text message: - content: The text content. robotCode The Bot code. msgtype The message type.
HTTP mode
-
Prepare the Java development environment:
- Runtime: JDK 1.7 or later
-
Server-side integration example:
-
After the development is complete, add the Bot to a group. When you send “Hello” by @ the Bot, the server receives a message in the following format:
Name Description conversationId The conversation ID. atUsers Information about the @ mentioned users: - dingtalkId: The encrypted sender ID. - staffId: The userId value of the Employee in the current internal group. chatbotCorpId The organization ID where the Bot resides. chatbotUserId The encrypted Bot ID. No use case for now; can be ignored. msgId The encrypted message ID. No use case for now; can be ignored. senderNick The sender’s name. isAdmin Whether the sender is an Admin. senderStaffId The user ID of the person who @ the Bot in the internal group. sessionWebhookExpiredTime The expiration time of the Webhook URL for the current chat. createAt The message timestamp, in milliseconds. senderCorpId The organization ID of the sender’s current group, available only in internal groups. conversationType The conversation type: - 1: Direct Message - 2: Group Chat senderId The encrypted sender ID. Note Use senderStaffId, which is the sender’s userId value. conversationTitle The chat title, available only in group chats. isInAtList Whether the user is in the @ list. sessionWebhook The Webhook URL for the current chat. content The message text. msgtype The message type.