import { isScheduleIntent, parseScheduleIntent } from '../../schedule-intent.mjs'; export async function handleWechatScheduleIntent({ intent, user, scheduleService }) { if (!scheduleService) return null; const scheduleIntent = parseScheduleIntent(intent.agentText); if (!isScheduleIntent(scheduleIntent)) return null; const timezone = process.env.H5_DEFAULT_TIMEZONE || 'Asia/Shanghai'; if (scheduleIntent.action === 'create_todo') { if (scheduleIntent.needsClarification?.includes('todo_title')) { return '可以。你想让我记哪一条待办?例如“帮我记一下 跟段吃饭”。'; } const item = await scheduleService.createItem({ userId: user.userId, kind: 'task', title: scheduleIntent.title, timezone, sourceChannel: 'wechat', sourceMessageId: intent.msgId || null, sourceText: intent.agentText, metadata: { source: 'wechat_mp', }, }); return `已记录到待办列表:${item.title},未设置提醒。`; } if (scheduleIntent.action === 'create_daily_todo_digest') { if (scheduleIntent.needsClarification?.includes('digest_time')) { return '可以。你想每天几点收到当天待办记录?比如“每天早上 7 点发给我”。'; } const subscription = await scheduleService.createDailyTodoDigest({ userId: user.userId, hour: scheduleIntent.hour, minute: scheduleIntent.minute, timezone, channel: 'wechat', sourceChannel: 'wechat', sourceMessageId: intent.msgId || null, sourceText: intent.agentText, }); const minuteText = subscription.minute === 0 ? '' : `${String(subscription.minute).padStart(2, '0')}分`; return `已设置:我会每天早上 ${subscription.hour}点${minuteText} 通过服务号把当天待办记录发给你。`; } if (scheduleIntent.action === 'create_balance_alert') { if (scheduleIntent.needsClarification?.includes('threshold')) { return '可以。你想在余额低于多少时提醒我?例如“余额低于 20 元提醒我”。'; } const subscription = await scheduleService.createBalanceLowAlert({ userId: user.userId, thresholdCents: scheduleIntent.thresholdCents, channel: 'wechat', sourceChannel: 'wechat', sourceMessageId: intent.msgId || null, sourceText: intent.agentText, }); return `已设置:当余额低于 ${(subscription.thresholdCents / 100).toFixed(2)} 元时,我会通过服务号提醒你。`; } if (scheduleIntent.action === 'query_schedule') { return scheduleService.buildTodoDigestText({ userId: user.userId, timezone, }); } return null; }