- Interactive card approval: when an agent calls a tool that needs approval, it asks for confirmation as a card in DingTalk; click a button to allow or deny;
- Streaming replies: with an AI card template configured, the answer updates within a single card as it is generated; without one, replies are sent as regular Markdown messages;
- Multimodal input: receive images, files, voice, video, and rich-text messages from users and pass them to the agent;
- Outbound sending: the agent can look up the directory and known chats, then send messages, images, and files to users or groups outside the current conversation.
Prerequisites
The DingTalk channel depends ondingtalk-stream, installed with the channel extra:
Install the dependency
Create App
Create and configure the enterprise internal app and its robot on the DingTalk Open Platform.1
Create an enterprise internal app
In the developer console, create an “enterprise internal app” and fill in its name and icon.
2
Record the Client ID and Client Secret
On the app’s credentials and basic info page, copy the Client ID (AppKey) and Client Secret (AppSecret) to fill into the channel config later. The Client Secret is a secret; keep it safe.
3
Add the robot capability
Under “App capabilities”, add “Robot” and fill in its name and icon so the app can send and receive messages.
4
Set the message delivery mode to Stream
On the robot config page, set the message delivery mode to Stream mode, with no HTTP callback URL.
5
Request permissions
Under “Permission management”, request: sending messages as an enterprise robot, creating and updating card instances, and uploading and downloading media files. If you want the
ListUsers tool to search people by name, also request the directory permissions for user search and user profile reads. Refer to the DingTalk docs for the exact scopes.6
Publish the app
Publish an app version so it becomes available in your organization. You can then add the robot to a group or DM it directly.
Prepare Card Templates
DingTalk interactive cards must be built first in the Card Platform; at runtime the channel only fills in the template variables. The channel uses two kinds of templates, both optional: leave one out and the corresponding capability degrades. The approval card template drives tool confirmation. The channel fills in these variables when it delivers a card:
The template needs an approve button and a deny button, both configured as callback buttons that carry
action plus toolCallId, chatId, agentId, sessionId, and approverId in their callback parameters (cardPrivateData.params). For action, approval accepts allow, approve, accept, or agree, and denial accepts deny or reject.
The streaming card template drives streaming replies. Place an AI card streaming component in the template, and set its template variable name as streaming_card_key in the channel config (content by default).
DingTalk caps the content size of a single card update. Once the reply grows past that cap, the channel stops streaming and sends the complete answer as a regular Markdown message instead.
Start Agent Service
A channel runs on top of an agent service. Start the service withcreate_app and declare the accepted channel types via channels. Channels depend on a message bus (message_bus); use InMemoryMessageBus for single-machine development, and switch to RedisMessageBus for multi-process or multi-node deployment.
Start an agent service that hosts the channel
Add Channel
In the management UI (see the sample frontendexamples/web_ui), add a channel through a visual form, with no config to write by hand.
1
Create a channel and pick DingTalk
On the channel management page, create a channel and choose “DingTalk” as the platform type.
2
Fill in the credentials
Enter the Client ID and Client Secret from the previous step into the credential form.
3
Fill in the card template IDs
Enter the approval card and streaming card template IDs into the platform config; both may be left empty.
4
Configure routing rules
Choose which agent handles messages and how sessions are scoped. See Message Routing for what the rules mean.
5
Save and enable
Save and enable the channel; the service opens the DingTalk Stream connection immediately and the robot comes online. Add it to a group or start a DM to begin.
The management UI maps onto the
/channels endpoints; call them directly when you need to create channels programmatically. See the API part of this chapter for the fields.Platform Config
The DingTalk channel’s platform-specific fields:When routing matches on
chat_type, group chats use group and DMs use private.Agent Tools
Once the approval card template is configured, the channel gives the agent an extra set of DingTalk tools for sending to users or groups outside the current conversation. The lookup tools return a target of the formuser:<staffId> or group:<openConversationId>, which the agent passes verbatim to a send tool.
Verify and Troubleshoot
- Check the channel status in the management UI, or call
GET /channels/{id}/statusto confirm the Stream connection is established. - If the robot doesn’t respond in a group, first check
only_at_replyand the @-mention behavior, then check that the send-message permission was requested and published with the version. - If the robot never comes online, check the Client ID / Client Secret and that the message delivery mode is set to Stream.
- If clicking a card button does nothing, check that the button’s callback parameters carry
actionand each identifier field from the table above. - If an attachment fails to send, check whether the file exceeds
max_media_bytesand whether its extension is one DingTalk supports.
Further Reading
Message Routing
Route different groups to different agents.
Feishu
Connect Feishu with the same flow.