Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> git-subtree-dir: gti-maquina-comercial git-subtree-mainline:93ca82979egit-subtree-split:b77484946f
66 lines
2.5 KiB
JavaScript
66 lines
2.5 KiB
JavaScript
export const COMMERCIAL_VARIABLES = [
|
|
{ key: 'name', label: 'Nome do WhatsApp/contato' },
|
|
{ key: 'empresa', label: 'Nome da empresa' },
|
|
{ key: 'businessName', label: 'Nome da empresa (GChat)' },
|
|
{ key: 'firstName', label: 'Primeiro nome' },
|
|
{ key: 'produto', label: 'Produto recomendado' },
|
|
{ key: 'protocol', label: 'Assunto/protocolo' },
|
|
{ key: 'cidade', label: 'Cidade' },
|
|
{ key: 'uf', label: 'UF' },
|
|
{ key: 'segmento', label: 'Nicho/segmento' },
|
|
{ key: 'cnpj', label: 'CNPJ' },
|
|
{ key: 'email', label: 'E-mail' },
|
|
{ key: 'phoneNumber', label: 'WhatsApp/telefone' },
|
|
{ key: 'whatsapp', label: 'WhatsApp/telefone' },
|
|
{ key: 'kanban', label: 'Produto/interesse' },
|
|
{ key: 'user', label: 'Usuário/remetente' },
|
|
{ key: 'userEmail', label: 'E-mail do remetente' },
|
|
{ key: 'greeting', label: 'Saudação' }
|
|
];
|
|
|
|
export function commercialVariableValues(lead = {}) {
|
|
const empresa = lead.empresa || lead.businessName || lead.name || 'sua empresa';
|
|
const produto = lead.produto || lead.produto_principal || lead.interesse || 'Atendimento comercial';
|
|
const cidade = lead.cidade || 'sua regiao';
|
|
const segmento = lead.segmento_label || lead.segmento || '';
|
|
const phoneNumber = lead.whatsapp || lead.phoneNumber || '';
|
|
const firstName = String(lead.name || empresa).split(/\s+/).filter(Boolean)[0] || empresa;
|
|
return {
|
|
name: lead.name || empresa,
|
|
empresa,
|
|
businessName: empresa,
|
|
firstName,
|
|
lastName: lead.lastName || '',
|
|
produto,
|
|
protocol: lead.protocol || produto,
|
|
cidade,
|
|
uf: lead.uf || '',
|
|
segmento,
|
|
cnpj: lead.cnpj || '',
|
|
email: lead.email || '',
|
|
phoneNumber,
|
|
whatsapp: phoneNumber,
|
|
kanban: lead.kanban || produto,
|
|
user: lead.user || 'Grupo GTI',
|
|
userEmail: lead.userEmail || 'comercial@gtigrupo.com.br',
|
|
greeting: 'Ola'
|
|
};
|
|
}
|
|
|
|
// Substituicao simples de variaveis no texto do template. Cada mensagem ja e
|
|
// resolvida por completo antes de chamar o Z-PRO (bulkIndividual manda texto
|
|
// pronto), entao nao dependemos da substituicao posicional por CSV que o
|
|
// bulkSendMessageWithVariable do Z-PRO usa.
|
|
export function renderTemplate(mensagem, lead) {
|
|
const values = commercialVariableValues(lead);
|
|
let output = String(mensagem || '')
|
|
.replaceAll('{empresa}', values.empresa)
|
|
.replaceAll('{cidade}', values.cidade)
|
|
.replaceAll('{produto}', values.produto)
|
|
.replaceAll('{segmento}', values.segmento);
|
|
for (const [key, value] of Object.entries(values)) {
|
|
output = output.replaceAll(`{{${key}}}`, value);
|
|
}
|
|
return output;
|
|
}
|