Files
john 031c6e086a feat(wechat): migrate schedule and sync handlers into wechat package
Extract schedule, greeting/status/connectivity replies, chat-general prompt, and display-name helpers from wechat-mp.mjs. Route sync intents via classifyWechatIntent and add channel isolation CI check.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-04 13:48:47 +08:00

51 lines
1.7 KiB
JavaScript

import { resolveWechatAddressName } from '../user/display-name.mjs';
export function buildGreetingText(user) {
const name = resolveWechatAddressName(user);
return name ? `你好,${name}!我在呢,有什么需要?` : '你好!我在呢,有什么需要?';
}
export function buildStatusText(user, fallbackText) {
const name = resolveWechatAddressName(user);
if (!name) return fallbackText;
return `我在这边,${name}。上一条如果还没完成,我会继续把结果发给你;你也可以直接补一句要求。`;
}
export function buildConnectivityTestReply(user) {
const name = resolveWechatAddressName(user);
return name
? `${name},公众号消息通道正常,我收到你的测试了。`
: '公众号消息通道正常,我收到你的测试了。';
}
/**
* Resolve an immediate sync XML reply for lightweight intents.
* @returns {string|null}
*/
export function resolveSyncReply(wechatIntent, user, { statusFallbackText = '' } = {}) {
switch (wechatIntent?.kind) {
case 'status.probe':
return buildStatusText(user, statusFallbackText);
case 'greeting':
return buildGreetingText(user);
case 'connectivity.test':
return buildConnectivityTestReply(user);
default:
return null;
}
}
/**
* Whether this intent should be answered synchronously before agent dispatch.
*/
export function shouldHandleSyncReply(intent, wechatIntent) {
const msgType = String(intent?.msgType ?? '').toLowerCase();
if (wechatIntent?.kind === 'connectivity.test') {
return msgType === 'text' || msgType === 'voice';
}
if (wechatIntent?.kind === 'status.probe' || wechatIntent?.kind === 'greeting') {
return msgType === 'text';
}
return false;
}