Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions plugins/dingtalk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# DingTalk Channel Plugin

Connect Cola to DingTalk through an enterprise internal application robot using
the Stream mode (outbound WebSocket). No public callback URL, domain, or TLS
certificate is required.

## Features

- Receives robot messages (direct chats and @-mentions in group chats) over a
managed Stream WebSocket connection with automatic reconnect.
- Receives inbound media: images, audio, video and files are downloaded to a
local temp path and handed to the agent as attachments (up to 50 MB each).
When a download fails, the message falls back to a short text summary.
- Sends Cola replies back to the originating DingTalk conversation:
`oToMessages` for direct chats, `groupMessages` for group chats.
- Sends Markdown replies when the model output is markdown-capable.
- Sends image and file replies natively (uploaded to DingTalk via its media
upload API and sent as `sampleImageMsg` / `sampleFile` robot messages).
- Group chat is opt-in via `groupEnabled`; DingTalk itself only pushes group
messages that @-mention the robot.

## Requirements

- An enterprise internal application on the
[DingTalk Open Platform](https://open-dev.dingtalk.com) with:
- The **robot** application capability added, with the message receive mode
set to **Stream mode**.
- A **published version** (unpublished robots do not receive
`senderStaffId`, which is required for direct-chat replies).
- The **enterprise robot message sending** permission granted.
- The application's **Client ID (AppKey)** and **Client Secret (AppSecret)**.

## Setup

1. In the DingTalk Open Platform console, create (or reuse) an enterprise
internal application and copy the Client ID and Client Secret.
2. Under **Application capabilities**, add the **robot** capability and select
**Stream mode** as the message receive mode, then publish the application
version.
3. Under **Permissions**, grant the enterprise robot message sending
permission.
4. Install the DingTalk plugin in Cola and enter the Client ID and Client
Secret in the plugin settings.
5. For group chats, add the robot to the target group (group settings →
robots) and enable `groupEnabled` in the plugin settings. Users must
@-mention the robot in groups.
6. Check `/dingtalk status` in Cola.

## Notes and limits

- The Stream channel is receive-only; replies are sent through the DingTalk
REST API with an access token cached for its 2-hour validity window.
- Group message payloads are limited to 15000 bytes by DingTalk; Cola splits
longer replies.
- Incoming media downloads: DingTalk's robot file-download endpoint returns a
short-lived temporary URL; the plugin downloads to a local temp dir (capped
at 50 MB per file). Media messages without a usable `downloadCode` (e.g.
rich-text messages with embedded pictures) remain text summaries.
- Outbound media: images and files are supported. DingTalk's video message
(`sampleVideo`) additionally requires a cover-image mediaId that cannot be
derived from the single file Cola provides, so video replies are not enabled.
Voice uploads are capped at 2 MB by DingTalk; image/video/file at 20 MB.
- Media upload uses DingTalk's legacy OAPI gateway
(`https://oapi.dingtalk.com/media/upload`), which authenticates with an
`access_token` form/query field rather than the `x-acs-dingtalk-access-token`
header used by the newer `api.dingtalk.com` robot endpoints. The token is the
same one issued by `/v1.0/oauth2/accessToken`.
- Treat the Client Secret as a credential: it is stored in Cola's secret
configuration fields and is never written to logs or files.

## Security

Do not commit Client ID/Secret values, session webhooks, or message content.
The plugin never persists credentials outside Cola's encrypted configuration.
Binary file added plugins/dingtalk/assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions plugins/dingtalk/locales/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"label": "DingTalk",
"description": "Chat with Cola in DingTalk",
"config.clientId": "Client ID (AppKey)",
"config.clientSecret": "Client Secret (AppSecret)",
"config.groupEnabled": "Enable group chat",
"config.ownerStaffId": "Owner Staff ID",
"status.connected": "Connected",
"status.disconnected": "Disconnected",
"status.noAccounts": "No account configured",
"status.accounts": "Connected accounts: {{count}}",
"status.connecting": "Connecting…",
"status.reconnecting": "Disconnected, reconnecting…",
"status.failed": "Connection failed",
"channel.groupDisabled": "Group chat is not enabled. Send a direct message to the bot instead.",
"auth.user": "I am the owner's work assistant and am unable to process your request for now. You are not authorized yet (Your ID: {{userId}}). The owner can run `cola channel allow dingtalk {{userId}}` on the desktop, or send this ID to the assistant via an authorized channel.",
"auth.group": "I am the owner's work assistant and am unable to process your request for now. This group is not authorized yet (Group ID: {{groupId}}). The owner can run `cola channel allow-group dingtalk {{groupId}}` on the desktop, or send this ID to the assistant via direct message.",
"error.noAccount": "No active DingTalk account",
"command.description": "{{name}} status and configuration",
"command.args": "Subcommands: {{commands}}",
"command.statusTitle": "**{{name}} Status**",
"command.configTitle": "**{{name}} Configuration**",
"command.unknown": "Unknown subcommand: {{subcommand}}. Use {{commands}}.",
"state.missing": "Missing",
"command.accountLine": "- **{{id}}**: Client ID={{clientId}}, {{status}}"
}
26 changes: 26 additions & 0 deletions plugins/dingtalk/locales/es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"label": "DingTalk",
"description": "Chatea con Cola en DingTalk",
"config.clientId": "Client ID (AppKey)",
"config.clientSecret": "Client Secret (AppSecret)",
"config.groupEnabled": "Habilitar chats de grupo",
"config.ownerStaffId": "Owner Staff ID(ID de empleado del propietario)",
"status.connected": "Conectado",
"status.disconnected": "Desconectado",
"status.noAccounts": "No hay cuentas configuradas",
"status.accounts": "Cuentas conectadas: {{count}}",
"status.connecting": "Conectando…",
"status.reconnecting": "Conexión perdida, reconectando…",
"status.failed": "Error de conexión",
"channel.groupDisabled": "Los chats de grupo no están habilitados. Envía un mensaje directo al bot.",
"auth.user": "Soy el asistente de trabajo del propietario y no puedo procesar su solicitud por ahora. Usted aún no está autorizado (Su ID: {{userId}}). El propietario puede ejecutar `cola channel allow dingtalk {{userId}}` en el escritorio, o enviar este ID al asistente a través de un canal autorizado.",
"auth.group": "Soy el asistente de trabajo del propietario y no puedo procesar su solicitud por ahora. Este grupo aún no está autorizado (ID del grupo: {{groupId}}). El propietario puede ejecutar `cola channel allow-group dingtalk {{groupId}}` en el escritorio, o enviar este ID al asistente por mensaje directo.",
"error.noAccount": "No hay una cuenta de DingTalk activa",
"command.description": "Estado y configuración de {{name}}",
"command.args": "Subcomandos: {{commands}}",
"command.statusTitle": "**Estado de {{name}}**",
"command.configTitle": "**Configuración de {{name}}**",
"command.unknown": "Subcomando desconocido: {{subcommand}}. Usa {{commands}}.",
"state.missing": "Falta",
"command.accountLine": "- **{{id}}**: Client ID={{clientId}}, {{status}}"
}
26 changes: 26 additions & 0 deletions plugins/dingtalk/locales/ja.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"label": "DingTalk",
"description": "DingTalk で Cola と会話する",
"config.clientId": "Client ID(AppKey)",
"config.clientSecret": "Client Secret(AppSecret)",
"config.groupEnabled": "グループチャットを有効にする",
"config.ownerStaffId": "Owner Staff ID(所有者従業員 ID)",
"status.connected": "接続済み",
"status.disconnected": "未接続",
"status.noAccounts": "アカウントが未設定です",
"status.accounts": "接続済みアカウント数:{{count}}",
"status.connecting": "接続中…",
"status.reconnecting": "接続が切断されました。再接続中…",
"status.failed": "接続に失敗しました",
"channel.groupDisabled": "グループチャットは無効です。ボットにダイレクトメッセージを送ってください。",
"auth.user": "私は主人の仕事アシスタントです。現在はリクエストを処理できません。まだ権限が付与されていません(あなたの ID:{{userId}})。主人はデスクトップで `cola channel allow dingtalk {{userId}}` を実行するか、この ID を既存の許可済みチャネル経由でアシスタントに送信してください。",
"auth.group": "私は主人の仕事アシスタントです。現在はリクエストを処理できません。このグループはまだ許可されていません(グループ ID:{{groupId}})。主人はデスクトップで `cola channel allow-group dingtalk {{groupId}}` を実行するか、この ID を DM でアシスタントに送信してください。",
"error.noAccount": "利用可能な DingTalk アカウントがありません",
"command.description": "{{name}} のステータスと設定",
"command.args": "サブコマンド:{{commands}}",
"command.statusTitle": "**{{name}} ステータス**",
"command.configTitle": "**{{name}} 設定**",
"command.unknown": "不明なサブコマンド:{{subcommand}}。{{commands}} を使用してください。",
"state.missing": "未設定",
"command.accountLine": "- **{{id}}**: Client ID={{clientId}}、{{status}}"
}
26 changes: 26 additions & 0 deletions plugins/dingtalk/locales/ko.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"label": "DingTalk",
"description": "DingTalk에서 Cola와 대화하기",
"config.clientId": "Client ID (AppKey)",
"config.clientSecret": "Client Secret (AppSecret)",
"config.groupEnabled": "그룹 채팅 사용",
"config.ownerStaffId": "Owner Staff ID(소유자 직원 ID)",
"status.connected": "연결됨",
"status.disconnected": "연결 안 됨",
"status.noAccounts": "구성된 계정이 없습니다",
"status.accounts": "연결된 계정 수: {{count}}",
"status.connecting": "연결 중…",
"status.reconnecting": "연결이 끊겼습니다. 다시 연결 중…",
"status.failed": "연결 실패",
"channel.groupDisabled": "그룹 채팅이 비활성화되어 있습니다. 봇에게 개인 메시지를 보내 주세요.",
"auth.user": "저는 주인님의 업무 비서입니다. 현재 요청을 처리할 수 없습니다. 아직 권한이 부여되지 않았습니다(내 ID: {{userId}}). 주인님은 데스크톱에서 `cola channel allow dingtalk {{userId}}`를 실행하거나, 이 ID를 이미 허용된 채널을 통해 비서에게 보내 주세요.",
"auth.group": "저는 주인님의 업무 비서입니다. 현재 요청을 처리할 수 없습니다. 이 그룹은 아직 허용되지 않았습니다(그룹 ID: {{groupId}}). 주인님은 데스크톱에서 `cola channel allow-group dingtalk {{groupId}}`를 실행하거나, 이 ID를 DM으로 비서에게 보내 주세요.",
"error.noAccount": "사용 가능한 DingTalk 계정이 없습니다",
"command.description": "{{name}} 상태 및 설정",
"command.args": "하위 명령: {{commands}}",
"command.statusTitle": "**{{name}} 상태**",
"command.configTitle": "**{{name}} 설정**",
"command.unknown": "알 수 없는 하위 명령: {{subcommand}}. {{commands}}를 사용하세요.",
"state.missing": "미설정",
"command.accountLine": "- **{{id}}**: Client ID={{clientId}}, {{status}}"
}
26 changes: 26 additions & 0 deletions plugins/dingtalk/locales/zh-CN.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"label": "钉钉",
"description": "在钉钉中与 Cola 对话",
"config.clientId": "Client ID(AppKey)",
"config.clientSecret": "Client Secret(AppSecret)",
"config.groupEnabled": "启用群聊",
"config.ownerStaffId": "Owner Staff ID(所有者员工 ID)",
"status.connected": "已连接",
"status.disconnected": "未连接",
"status.noAccounts": "未配置账号",
"status.accounts": "已连接账号数:{{count}}",
"status.connecting": "正在连接…",
"status.reconnecting": "连接已断开,正在重连…",
"status.failed": "连接失败",
"channel.groupDisabled": "尚未启用群聊,请私信机器人。",
"auth.user": "我是主人的工作助理,暂时不能为您处理请求。您尚未获得授权(您的 ID:{{userId}})。主人可在电脑上执行 `cola channel allow dingtalk {{userId}}` 完成授权,或将此 ID 通过其他已授权渠道发给助手。",
"auth.group": "我是主人的工作助理,暂时不能为您处理请求。本群尚未授权(群 ID:{{groupId}})。主人可在电脑上执行 `cola channel allow-group dingtalk {{groupId}}` 授权本群,或将此 ID 通过私信发给助手开通。",
"error.noAccount": "没有可用的钉钉账号",
"command.description": "{{name}} 状态和配置",
"command.args": "子命令:{{commands}}",
"command.statusTitle": "**{{name}} 状态**",
"command.configTitle": "**{{name}} 配置**",
"command.unknown": "未知子命令:{{subcommand}}。请使用 {{commands}}。",
"state.missing": "未填写",
"command.accountLine": "- **{{id}}**: Client ID={{clientId}},{{status}}"
}
26 changes: 26 additions & 0 deletions plugins/dingtalk/locales/zh-TW.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"label": "釘釘",
"description": "在釘釘中與 Cola 對話",
"config.clientId": "Client ID(AppKey)",
"config.clientSecret": "Client Secret(AppSecret)",
"config.groupEnabled": "啟用群聊",
"config.ownerStaffId": "Owner Staff ID(擁有者員工 ID)",
"status.connected": "已連線",
"status.disconnected": "未連線",
"status.noAccounts": "未設定帳號",
"status.accounts": "已連線帳號數:{{count}}",
"status.connecting": "正在連線…",
"status.reconnecting": "連線已中斷,正在重新連線…",
"status.failed": "連線失敗",
"channel.groupDisabled": "尚未啟用群聊,請私訊機器人。",
"auth.user": "我是主人的工作助理,暫時無法為您處理請求。您尚未獲得授權(您的 ID:{{userId}})。主人可在電腦上執行 `cola channel allow dingtalk {{userId}}` 完成授權,或將此 ID 透過其他已授權渠道發給助手。",
"auth.group": "我是主人的工作助理,暫時無法為您處理請求。本群尚未授權(群 ID:{{groupId}})。主人可在電腦上執行 `cola channel allow-group dingtalk {{groupId}}` 授權本群,或將此 ID 透過私訊發給助手開通。",
"error.noAccount": "沒有可用的釘釘帳號",
"command.description": "{{name}} 狀態和設定",
"command.args": "子命令:{{commands}}",
"command.statusTitle": "**{{name}} 狀態**",
"command.configTitle": "**{{name}} 設定**",
"command.unknown": "未知子命令:{{subcommand}}。請使用 {{commands}}。",
"state.missing": "未填寫",
"command.accountLine": "- **{{id}}**: Client ID={{clientId}},{{status}}"
}
51 changes: 51 additions & 0 deletions plugins/dingtalk/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "cola-plugin-dingtalk",
"version": "0.2.0",
"description": "DingTalk channel plugin for Cola",
"license": "Apache-2.0",
"type": "module",
"exports": {
".": "./dist/index.js"
},
"scripts": {
"build": "tsup",
"typecheck": "tsc --noEmit",
"test": "vitest run"
},
"dependencies": {
"@marswave/cola-plugin-sdk": "0.0.5",
"dingtalk-stream": "2.1.5"
},
"devDependencies": {
"@types/node": "^22.0.0",
"tsup": "^8.5.1",
"typescript": "^5.8.3"
},
"engines": {
"node": ">=22"
},
"cola": {
"plugin": {
"id": "dingtalk",
"entry": "./dist/index.js",
"minColaVersion": "1.4.5"
},
"channel": {
"label": "DingTalk",
"description": "DingTalk messaging via official enterprise bot (Stream mode)",
"iconUrl": "https://raw.githubusercontent.com/marswaveai/cola-plugins/main/plugins/dingtalk/assets/icon.png",
"aliases": [
"dingtalk"
],
"docsPath": "https://github.com/marswaveai/cola-plugins/blob/main/plugins/dingtalk/README.md",
"i18n": {
"en": "./locales/en.json",
"es": "./locales/es.json",
"ja": "./locales/ja.json",
"ko": "./locales/ko.json",
"zh-CN": "./locales/zh-CN.json",
"zh-TW": "./locales/zh-TW.json"
}
}
}
}
Loading