Files
john 7f06361bd3 Ship the page-focused follow reply with the news and shop updates.
Replace the subscribe welcome with page-generation examples, add the trial news003 WeChat share card, and let OneShop checkout return to an order or recharge page.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-25 14:30:20 +08:00

169 lines
6.2 KiB
JavaScript

import { resolveWechatAddressName } from '../user/display-name.mjs';
export const DEFAULT_SUBSCRIBE_INTRO_URL =
'https://m.tkmind.cn/MindSpace/a70ff537-8908-486e-9b6c-042e07cc25db/public/tkmind-deep-intro.html';
/** 103 生产默认绑定入口:{H5_PUBLIC_BASE_URL}/auth/wechat/authorize?intent=login */
export const DEFAULT_PRODUCTION_BIND_URL =
'https://m.tkmind.cn/auth/wechat/authorize?intent=login';
export const DEFAULT_PLAZA_HOME_URL = 'https://plaza.tkmind.cn/plaza';
const SUBSCRIBE_EXAMPLE_ORIGIN =
'https://m.tkmind.cn/MindSpace/a70ff537-8908-486e-9b6c-042e07cc25db/public';
/** 关注欢迎语里的可点开案例。提示句都必须包含「生成页面」。 */
export const DEFAULT_SUBSCRIBE_WELCOME_EXAMPLES = Object.freeze([
{
prompt: '生成页面:某产品调研分析报告,含用户痛点、竞品对比和结论',
label: '产品调研 · 竞品地图',
url: `${SUBSCRIBE_EXAMPLE_ORIGIN}/chenkeming-map.html`,
},
{
prompt: '生成页面:季度数据分析报告,用图表讲清变化',
label: '分析报告 · 数据仪表盘',
url: `${SUBSCRIBE_EXAMPLE_ORIGIN}/zhixing-data-dashboard.html`,
},
{
prompt: '生成页面:苏州一日游攻略,含路线和美食',
label: '旅行攻略 · 新疆亲子游',
url: `${SUBSCRIBE_EXAMPLE_ORIGIN}/xinjiang-travel.html`,
},
{
prompt: '生成页面:周末市集活动页,含时间、地点和报名',
label: '活动页面 · 餐厅招牌',
url: `${SUBSCRIBE_EXAMPLE_ORIGIN}/changsha-restaurant-promo.html`,
},
]);
/** 关注欢迎语里推荐的 M发现精选入口(示例页/广场作品,便于长期维护)。 */
export const DEFAULT_SUBSCRIBE_PLAZA_PICKS = Object.freeze([
{
label: '✈️ 旅行攻略 · 路线/交通/美食预算一站看',
url: 'https://m.tkmind.cn/MindSpace/a70ff537-8908-486e-9b6c-042e07cc25db/public/xinjiang-travel.html',
},
{
label: '🍜 深夜食堂 · 城市探店、散步地图',
url: 'https://plaza.tkmind.cn/plaza/p/a2767a6d-e314-49fe-885e-c5baa978e6fc',
},
{
label: '🎨 创意海报页 · 活动页、品牌视觉',
url: 'https://m.tkmind.cn/MindSpace/a70ff537-8908-486e-9b6c-042e07cc25db/public/tkmind-zhiqu-landing.html',
},
]);
export function buildWechatTextLink(href, label) {
const normalizedHref = String(href ?? '').trim();
const normalizedLabel = String(label ?? '').trim();
if (!normalizedHref) return normalizedLabel;
if (!normalizedLabel) return normalizedHref;
return `<a href="${normalizedHref}">${normalizedLabel}</a>`;
}
export function buildPlazaDiscoveryLines({
plazaHomeUrl = DEFAULT_PLAZA_HOME_URL,
plazaPicks = DEFAULT_SUBSCRIBE_PLAZA_PICKS,
} = {}) {
const homeUrl = String(plazaHomeUrl ?? '').trim();
if (!homeUrl) return [];
const picks = Array.isArray(plazaPicks) ? plazaPicks : DEFAULT_SUBSCRIBE_PLAZA_PICKS;
const lines = [
'',
'🎯 M发现 · 精选作品广场',
'别人已经做好的精美页面,点开就能看;改改文字和图片,就是你的攻略/活动页:',
];
for (const pick of picks) {
const url = String(pick?.url ?? '').trim();
const label = String(pick?.label ?? '').trim();
if (!url || !label) continue;
lines.push(`· ${buildWechatTextLink(url, label)}`);
}
lines.push('', `👉 ${buildWechatTextLink(homeUrl, '进入 M发现,逛热门作品')}`);
return lines;
}
export function buildSubscribeWelcomeText({
bindUrl,
examples = DEFAULT_SUBSCRIBE_WELCOME_EXAMPLES,
} = {}) {
const normalizedBindUrl = String(bindUrl ?? '').trim();
const lines = [
'欢迎关注 TKMind 智趣 👋',
'',
'你想做的页面,直接说给我。',
'带上「生成页面」,我做好后回你链接,马上就能分享。',
'',
'例如:',
];
const picks = Array.isArray(examples) ? examples : DEFAULT_SUBSCRIBE_WELCOME_EXAMPLES;
const visible = [];
for (const example of picks) {
const prompt = String(example?.prompt ?? '').trim();
const url = String(example?.url ?? '').trim();
const label = String(example?.label ?? '').trim();
if (!prompt.includes('生成页面')) continue;
lines.push(`· 「${prompt}」`);
if (url && label) visible.push({ url, label });
}
if (visible.length) {
lines.push('', '点开看看做好的页面:');
for (const pick of visible) {
lines.push(`· ${buildWechatTextLink(pick.url, pick.label)}`);
}
}
lines.push('', '链接转给朋友,对方点开就能看。');
if (normalizedBindUrl) {
lines.push('', `👉 先${buildWechatTextLink(normalizedBindUrl, '点我绑定')},再发一句「生成页面:…」`);
}
return lines.join('\n');
}
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;
}