Add smart ACK provider for WeChat MP replies

Replace fixed ackText with a rule-based AckProvider that picks
response templates by message type and intent (translate, summary,
rewrite, poster, ppt, mindmap, code, search, schedule). Pure sync,
zero I/O, auto-falls back to config.ackText on any error.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
john
2026-06-26 15:19:03 +08:00
parent 9ed4fd48d7
commit 9b4a25799f
162 changed files with 17276 additions and 2054 deletions
+62
View File
@@ -0,0 +1,62 @@
import { TEMPLATES } from './ack-templates.mjs';
function pickRandom(arr, randomEnabled) {
if (!randomEnabled || arr.length === 1) return arr[0];
return arr[Math.floor(Math.random() * arr.length)];
}
function withNickname(text, nickname, nicknameEnabled) {
if (!nicknameEnabled || !nickname) return text;
return `${nickname}${text}`;
}
function buildText(pool, ctx) {
const text = pickRandom(pool, ctx.randomEnabled);
return withNickname(text, ctx.nickname, ctx.nicknameEnabled);
}
const ImageBuilder = {
priority: 80,
support: (ctx) => ctx.msgType === 'image',
build: (ctx) => buildText(TEMPLATES.image, ctx),
};
const VoiceBuilder = {
priority: 80,
support: (ctx) => ctx.msgType === 'voice',
build: (ctx) => buildText(TEMPLATES.voice, ctx),
};
const LocationBuilder = {
priority: 80,
support: (ctx) => ctx.msgType === 'location',
build: (ctx) => buildText(TEMPLATES.location, ctx),
};
const LinkBuilder = {
priority: 80,
support: (ctx) => ctx.msgType === 'link',
build: (ctx) => buildText(TEMPLATES.link, ctx),
};
const IntentBuilder = {
priority: 50,
support: (ctx) => {
const task = ctx.intent?.task;
return task && task !== 'unknown' && TEMPLATES.intent[task];
},
build: (ctx) => buildText(TEMPLATES.intent[ctx.intent.task], ctx),
};
const DefaultBuilder = {
priority: 0,
support: () => true,
build: (ctx) => buildText(TEMPLATES.default, ctx),
};
const BUILDERS = [ImageBuilder, VoiceBuilder, LocationBuilder, LinkBuilder, IntentBuilder, DefaultBuilder]
.sort((a, b) => b.priority - a.priority);
export function selectBuilder(ctx) {
return BUILDERS.find((b) => b.support(ctx)) ?? DefaultBuilder;
}