✨ 新功能: - 添加Telegram Bot通知支持 - 账目记录自动推送到Telegram - 支持多个Bot配置管理 - 支持群组和个人通知 📊 数据库: - 新增telegram_notification_configs表 - 存储Bot配置和通知类型 🔧 后端API: - GET /api/telegram/notifications - 获取所有配置 - POST /api/telegram/notifications - 创建配置 - PUT /api/telegram/notifications/:id - 更新配置 - DELETE /api/telegram/notifications/:id - 删除配置 - POST /api/telegram/test - 测试Bot配置 💬 通知功能: - 自动发送账目记录通知 - 包含交易类型、金额、分类、账户等信息 - 支持格式化显示(类型图标、状态标识) - 配置创建时自动测试有效性 📝 文档: - 添加完整的使用说明文档 - API接口说明和示例 - 常见问题解答
20 lines
617 B
TypeScript
20 lines
617 B
TypeScript
import { readBody } from 'h3';
|
|
import { useResponseError, useResponseSuccess } from '~/utils/response';
|
|
import { testTelegramConfig } from '~/utils/telegram-bot';
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const body = await readBody(event);
|
|
|
|
if (!body?.botToken || !body?.chatId) {
|
|
return useResponseError('缺少Bot Token或Chat ID', -1);
|
|
}
|
|
|
|
const result = await testTelegramConfig(body.botToken, body.chatId);
|
|
|
|
if (result.success) {
|
|
return useResponseSuccess({ message: '测试消息发送成功' });
|
|
} else {
|
|
return useResponseError(result.error || '测试失败', -1);
|
|
}
|
|
});
|