send_markdown_message
Send formatted markdown messages with titles, mentions, and notifications to DingTalk group chats using a custom robot.
Instructions
Send a markdown message
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes | The title of the message | |
| text | Yes | The text content to send | |
| atMobiles | No | The mobile numbers of users to @mention (ping) individually in the group chat | |
| atAll | No | Whether to @all the users in the group |
Implementation Reference
- src/index.ts:52-62 (handler)Handler function for the 'send_markdown_message' tool. It invokes dingtalkBot.sendMarkdown and formats success or error response.async ({ title, text, atMobiles, atAll }) => { const response = await dingtalkBot.sendMarkdown(title, text, atMobiles, atAll); if (response.errcode !== 0) { return { content: [{ type: "text", text: `Failed to send message, code: ${response.errcode}, message: ${response.errmsg}` }], }; } return { content: [{ type: "text", text: "Message sent successfully" }], }; }
- src/index.ts:46-51 (schema)Zod input schema defining parameters for send_markdown_message tool: title, text, optional atMobiles and atAll.{ title: z.string().describe("The title of the message"), text: z.string().describe("The text content to send"), atMobiles: z.array(z.string()).optional().describe("The mobile numbers of users to @mention (ping) individually in the group chat"), atAll: z.boolean().optional().describe("Whether to @all the users in the group"), },
- src/index.ts:43-63 (registration)Registration of the 'send_markdown_message' tool on the MCP server, including name, description, input schema, and handler function.server.tool( 'send_markdown_message', 'Send a markdown message', { title: z.string().describe("The title of the message"), text: z.string().describe("The text content to send"), atMobiles: z.array(z.string()).optional().describe("The mobile numbers of users to @mention (ping) individually in the group chat"), atAll: z.boolean().optional().describe("Whether to @all the users in the group"), }, async ({ title, text, atMobiles, atAll }) => { const response = await dingtalkBot.sendMarkdown(title, text, atMobiles, atAll); if (response.errcode !== 0) { return { content: [{ type: "text", text: `Failed to send message, code: ${response.errcode}, message: ${response.errmsg}` }], }; } return { content: [{ type: "text", text: "Message sent successfully" }], }; } );
- src/dingtalk_custom_robot.ts:82-108 (helper)Core implementation of sending markdown message: constructs MarkdownMessage payload and performs authenticated POST request to DingTalk robot API.async sendMarkdown( title: string, text: string, atMobiles?: string[], atAll: boolean = false ): Promise<MessageResponse> { const data: MarkdownMessage = { msgtype: 'markdown', markdown: { title, text, }, at: { atMobiles: atMobiles || [], isAtAll: atAll, }, }; const response = await fetch(this.getSignedUrl(), { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(data), }); return response.json() as Promise<MessageResponse>; }
- src/dingtalk_custom_robot.ts:41-54 (helper)Utility method to generate signed URL for DingTalk API requests using HMAC-SHA256 signature if secret is provided.private getSignedUrl(): string { const timestamp = Date.now(); if (this.secret) { const stringToSign = `${timestamp}\n${this.secret}`; const hmac = crypto.createHmac('sha256', this.secret); const sign = encodeURIComponent( hmac.update(stringToSign).digest('base64') ); return `${this.baseUrl}?access_token=${this.accessToken}×tamp=${timestamp}&sign=${sign}`; } return `${this.baseUrl}?access_token=${this.accessToken}`; }