164 lines
6.0 KiB
JavaScript
164 lines
6.0 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 links = picks
|
|
.filter((example) => String(example?.url ?? '').trim() && String(example?.label ?? '').trim())
|
|
.map((example) => buildWechatTextLink(example.url, example.label));
|
|
if (links.length) {
|
|
lines.push('', '✨ 案例查看:');
|
|
for (let i = 0; i < links.length; i += 2) {
|
|
lines.push(links.slice(i, i + 2).join(' · '));
|
|
}
|
|
}
|
|
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;
|
|
}
|