send_text_message
Send plain text messages to DingTalk group chats with optional @mentions for specific users or all members.
Instructions
Send a plain text message
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| 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:30-41 (handler)Handler function for 'send_text_message' tool that invokes DingtalkBot.sendText and formats MCP responseasync ({ text, atMobiles, atAll }) => { const response = await dingtalkBot.sendText(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:25-29 (schema)Input schema (zod) for send_text_message tool{ 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:22-41 (registration)Registration of send_text_message tool using server.tool() including schema and handlerserver.tool( 'send_text_message', 'Send a plain text 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 ({ text, atMobiles, atAll }) => { const response = await dingtalkBot.sendText(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:56-80 (helper)DingtalkBot.sendText method implementing the core logic for sending text messages to DingTalk robot API, called by the tool handlerasync sendText( content: string, atMobiles?: string[], atAll: boolean = false ): Promise<MessageResponse> { const data: TextMessage = { msgtype: 'text', text: { content, }, 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>; }