Files
memind/wechat/intent/channel-prefix.mjs
T
john cbcec96306
Memind CI / Test, build, and release guards (push) Has been cancelled
fix(wechat): route colloquial page talk to the task the user meant
Bare “页面”, daily page titles, link requests, and short edits after a side question were leaving the original page task.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-26 16:00:43 +08:00

50 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/** Explicit WeChat channel prefixes so users can separate chat, page, and scheduled tasks. */
export const WECHAT_CHANNEL_PREFIX = Object.freeze({
CHAT: 'chat',
PAGE: 'page',
SCHEDULED_TASK: 'scheduled_task',
});
const PREFIX_ENTRIES = Object.freeze([
{
channel: WECHAT_CHANNEL_PREFIX.CHAT,
pattern: /^【?\s*聊天\s*】?[::\s]*/iu,
},
{
channel: WECHAT_CHANNEL_PREFIX.PAGE,
pattern: /^(?:【\s*(?:改页|做页|页面)\s*】\s*|(?:改页|做页|页面)\s*[::])\s*/iu,
},
{
channel: WECHAT_CHANNEL_PREFIX.SCHEDULED_TASK,
pattern: /^【?\s*定时任务\s*】?[::\s]*/iu,
},
]);
/**
* @returns {{ channel: string|null, body: string, hadPrefix: boolean }}
*/
export function parseWechatChannelPrefix(text) {
const normalized = String(text ?? '').trim();
if (!normalized) {
return { channel: null, body: '', hadPrefix: false };
}
for (const entry of PREFIX_ENTRIES) {
if (!entry.pattern.test(normalized)) continue;
return {
channel: entry.channel,
body: normalized.replace(entry.pattern, '').trim(),
hadPrefix: true,
};
}
return { channel: null, body: normalized, hadPrefix: false };
}
export function stripWechatChannelPrefix(text) {
return parseWechatChannelPrefix(text).body;
}
export function hasWechatPageChannelPrefix(text) {
return parseWechatChannelPrefix(text).channel === WECHAT_CHANNEL_PREFIX.PAGE;
}