124 lines
3.8 KiB
JavaScript
124 lines
3.8 KiB
JavaScript
const TECH_INTENTS = new Set([
|
||
'wifi_credentials',
|
||
'app_issue_streaming',
|
||
'app_issue_account',
|
||
'app_feature_guidance',
|
||
]);
|
||
|
||
const INTENT_TO_FAQ_CATEGORY = {
|
||
wifi_credentials: 'wifi',
|
||
app_issue_account: 'app_account',
|
||
};
|
||
|
||
const { faqAnswerText } = require('../utils/faqAnswer');
|
||
|
||
const MAX_FAQS = 10;
|
||
const ANSWER_MAX = 600;
|
||
const HELPDESK = 'Please ask at the venue help desk or contact event support.';
|
||
|
||
const STREAMING_STATIC_TIPS = [
|
||
'Refresh the page and rejoin using the latest link from your confirmation email.',
|
||
'Use the latest Chrome or Edge and check your internet connection.',
|
||
'Allow the browser to use your microphone/camera if it asks.',
|
||
'Turn off any VPN or ad-blocker and close other video apps.',
|
||
'Try an incognito window or a different device.',
|
||
];
|
||
|
||
const ACCOUNT_STATIC_TIPS = [
|
||
'Confirm you are using the same email you registered with.',
|
||
'Check spam/junk for a login or OTP email.',
|
||
'Wait a minute and request a new code if the OTP expired.',
|
||
'If you still cannot sign in, contact the organizers or help desk to reset access.',
|
||
];
|
||
|
||
function isTechIntent(intent) {
|
||
return TECH_INTENTS.has(String(intent || ''));
|
||
}
|
||
|
||
function trimText(value, max = ANSWER_MAX) {
|
||
const s = String(value || '').trim();
|
||
if (!s) return '';
|
||
return s.length > max ? `${s.slice(0, max)}…` : s;
|
||
}
|
||
|
||
function answeredFaqsForIntent(bot, intent) {
|
||
const category = INTENT_TO_FAQ_CATEGORY[intent];
|
||
if (!category) return [];
|
||
const rows = Array.isArray(bot?.faqs) ? bot.faqs : [];
|
||
return rows
|
||
.filter((f) => String(f?.category || '') === category && faqAnswerText(f))
|
||
.slice(0, MAX_FAQS)
|
||
.map((f) => ({
|
||
q: trimText(f.question, 200),
|
||
a: trimText(faqAnswerText(f), ANSWER_MAX),
|
||
key: String(f?.key || f?.category || category || '').trim() || null,
|
||
category: String(f?.category || category || '').trim() || null,
|
||
}))
|
||
.filter((f) => f.q && f.a);
|
||
}
|
||
|
||
/**
|
||
* @param {{ intent: string, bot?: object }} opts
|
||
*/
|
||
async function fetchTechData({ intent, bot = null } = {}) {
|
||
const intentKey = String(intent || '');
|
||
const faqs = answeredFaqsForIntent(bot, intentKey);
|
||
const hasFaqs = faqs.length > 0;
|
||
const category = INTENT_TO_FAQ_CATEGORY[intentKey] || null;
|
||
|
||
const base = {
|
||
intent: intentKey,
|
||
category,
|
||
faqs,
|
||
staticTips: null,
|
||
note: null,
|
||
};
|
||
|
||
if (intentKey === 'wifi_credentials') {
|
||
base.note = hasFaqs
|
||
? 'Share Wi‑Fi network name and/or password only from DATA.faqs. Never invent credentials.'
|
||
: `No Wi‑Fi FAQ is configured. Do not invent SSID or password. Suggest venue signage or the help desk. ${HELPDESK}`;
|
||
return base;
|
||
}
|
||
|
||
if (intentKey === 'app_issue_streaming') {
|
||
if (hasFaqs) {
|
||
base.note = 'Answer streaming/AV help from DATA.faqs only. Do not invent platform-specific settings.';
|
||
} else {
|
||
base.staticTips = STREAMING_STATIC_TIPS;
|
||
base.note =
|
||
`No streaming FAQ is configured. Share DATA.staticTips as numbered steps, then suggest event support. ${HELPDESK}`;
|
||
}
|
||
return base;
|
||
}
|
||
|
||
if (intentKey === 'app_issue_account') {
|
||
if (hasFaqs) {
|
||
base.note = 'Answer login/account help from DATA.faqs only. Never invent emails or reset links.';
|
||
} else {
|
||
base.staticTips = ACCOUNT_STATIC_TIPS;
|
||
base.note =
|
||
`No account FAQ is configured. Share DATA.staticTips, then suggest organizers / help desk. ${HELPDESK}`;
|
||
}
|
||
return base;
|
||
}
|
||
|
||
if (intentKey === 'app_feature_guidance') {
|
||
base.note = hasFaqs
|
||
? 'Explain the feature using DATA.faqs only. Do not invent UI steps not in DATA.'
|
||
: 'No app-feature FAQ is configured. Ask which feature they need help with, or suggest in-app help / organizers. Do not invent a walkthrough.';
|
||
return base;
|
||
}
|
||
|
||
return base;
|
||
}
|
||
|
||
module.exports = {
|
||
TECH_INTENTS,
|
||
INTENT_TO_FAQ_CATEGORY,
|
||
isTechIntent,
|
||
fetchTechData,
|
||
STREAMING_STATIC_TIPS,
|
||
ACCOUNT_STATIC_TIPS,
|
||
};
|