30 lines
945 B
JavaScript
30 lines
945 B
JavaScript
/** Default values when greeting template variables are missing (web embed, WhatsApp, etc.). */
|
|
const CONCIERGE_GREETING_DEFAULTS = {
|
|
profileName: 'Visitor',
|
|
eventName: 'Event',
|
|
};
|
|
|
|
/**
|
|
* Replace {profileName}, {eventName}, and other known placeholders in a concierge greeting.
|
|
* Empty or missing values fall back to CONCIERGE_GREETING_DEFAULTS.
|
|
*
|
|
* @param {string} template
|
|
* @param {{ profileName?: string, eventName?: string }} [values]
|
|
* @returns {string}
|
|
*/
|
|
function interpolateConciergeGreeting(template, values = {}) {
|
|
let out = String(template || '');
|
|
for (const [key, fallback] of Object.entries(CONCIERGE_GREETING_DEFAULTS)) {
|
|
const raw = values[key];
|
|
const val =
|
|
raw != null && String(raw).trim() !== '' ? String(raw).trim() : fallback;
|
|
out = out.replace(new RegExp(`\\{${key}\\}`, 'gi'), val);
|
|
}
|
|
return out;
|
|
}
|
|
|
|
module.exports = {
|
|
CONCIERGE_GREETING_DEFAULTS,
|
|
interpolateConciergeGreeting,
|
|
};
|