dingtalk_notify_session_end
Send session completion notifications via DingTalk, including session type, duration, tasks completed, summary, file modifications, tools used, and optional @all mentions.
Instructions
Send a session completion notification with automatic stats
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| atAll | No | Whether to @all members | |
| duration | No | Session duration (e.g., "30分钟", "1小时20分") | |
| filesCount | No | Number of files modified/created | |
| mainTasks | No | List of main tasks completed in this session | |
| sessionType | No | Type of session (e.g., "开发协助", "代码审查", "问题解决") | 开发协助 |
| summary | No | Brief summary of the session | 会话已完成 |
| toolsUsed | No | Number of tools/commands used |
Implementation Reference
- src/index.ts:326-387 (handler)The main handler function that constructs a detailed markdown message for session completion notification, including stats like duration, tasks, files, tools, and sends it via the DingTalk client.private async handleNotifySessionEnd(args: { sessionType?: string; duration?: string; mainTasks?: string[]; summary?: string; filesCount?: number; toolsUsed?: number; atAll?: boolean; }) { if (!this.dingTalkClient) { throw new Error('DingTalk client not configured. Use dingtalk_configure first or set environment variables (DINGTALK_WEBHOOK, DINGTALK_SECRET).'); } const sessionType = args.sessionType || '开发协助'; const duration = args.duration || '刚刚完成'; const mainTasks = args.mainTasks || []; const summary = args.summary || '会话已完成'; const filesCount = args.filesCount || 0; const toolsUsed = args.toolsUsed || 0; const now = new Date(); const gitUsername = this.getGitUsername(); const title = `🤖 Claude Code ${sessionType}完成`; let content = `## 🤖 Claude Code ${sessionType}完成 **完成时间:** ${now.toLocaleString('zh-CN')} **会话时长:** ${duration} **操作者:** ${gitUsername} ### 📋 本次会话 ${summary}`; if (mainTasks.length > 0) { content += ` ### ✅ 主要任务 ${mainTasks.map(task => `- ${task.trim()}`).join('\n')}`; } content += ` ### 📊 操作统计 - **文件操作:** ${filesCount} 个 - **工具使用:** ${toolsUsed} 次 --- *Claude Code 自动通知 | ${now.toLocaleDateString('zh-CN')}*`; const success = await this.dingTalkClient.sendMarkdown(title, content, args.atAll); return { content: [ { type: 'text', text: success ? '✅ Session completion notification sent successfully' : '❌ Failed to send session completion notification', }, ], }; }
- src/index.ts:153-196 (registration)Tool registration in the ListToolsRequest handler, defining the tool name, description, and input schema.{ name: 'dingtalk_notify_session_end', description: 'Send a session completion notification with automatic stats', inputSchema: { type: 'object', properties: { sessionType: { type: 'string', description: 'Type of session (e.g., "开发协助", "代码审查", "问题解决")', default: '开发协助' }, duration: { type: 'string', description: 'Session duration (e.g., "30分钟", "1小时20分")', }, mainTasks: { type: 'array', items: { type: 'string' }, description: 'List of main tasks completed in this session', }, summary: { type: 'string', description: 'Brief summary of the session', default: '会话已完成' }, filesCount: { type: 'number', description: 'Number of files modified/created', default: 0 }, toolsUsed: { type: 'number', description: 'Number of tools/commands used', default: 0 }, atAll: { type: 'boolean', description: 'Whether to @all members', default: false } }, required: [] }, },
- src/index.ts:218-228 (registration)Dispatch registration in the CallToolRequest handler's switch statement, casting arguments and calling the handler.case 'dingtalk_notify_session_end': return await this.handleNotifySessionEnd(args as unknown as { sessionType?: string; duration?: string; mainTasks?: string[]; summary?: string; filesCount?: number; toolsUsed?: number; atAll?: boolean; });
- src/index.ts:156-194 (schema)Input schema definition for the tool's parameters.inputSchema: { type: 'object', properties: { sessionType: { type: 'string', description: 'Type of session (e.g., "开发协助", "代码审查", "问题解决")', default: '开发协助' }, duration: { type: 'string', description: 'Session duration (e.g., "30分钟", "1小时20分")', }, mainTasks: { type: 'array', items: { type: 'string' }, description: 'List of main tasks completed in this session', }, summary: { type: 'string', description: 'Brief summary of the session', default: '会话已完成' }, filesCount: { type: 'number', description: 'Number of files modified/created', default: 0 }, toolsUsed: { type: 'number', description: 'Number of tools/commands used', default: 0 }, atAll: { type: 'boolean', description: 'Whether to @all members', default: false } }, required: []
- src/index.ts:33-39 (helper)Helper function to retrieve the git username, used in the notification message.private getGitUsername(): string { try { const username = execSync('git config --get user.name', { encoding: 'utf8' }).trim(); return username || 'Unknown User'; } catch (error) { return 'Unknown User'; }