Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejs
function firstName(nomeCompleto){
    const parts = nomeCompleto.split(' ');
    const first_name = parts[0];
    return first_name
}

function lastName(nomeCompleto){
    const parts = nomeCompleto.split(' ');
    let last_name = parts.slice(1).join(' ') || '';
    return last_name
}

function formatarTelefone(telefone){
    let whatsapp = telefone.replace(/\D/g, '');
    const ddi = "55";
    let ddd;//Adicione aqui exceções de DDi que não devem receber o tratamento do Script
    if (telefone.startsWith('+55') || telefone.startsWith('55') (whatsapp|| (telefone.startsWith('+') && !telefone.startsWith("'+55"'))) {
        return whatsapp;
= whatsapp.slice(2)    }
    const ddi = "+55";
    }let ddd;
    if (whatsapp.length >=== 10 || whatsapp.length === 11) {
        ddd = whatsapp.slice(0, 2);
        whatsapp = whatsapp.slice(2);
 
  } else {         ddd = '00';
    }
    if (ddd !== '00' && parseInt(ddd, 10) <= 28) {
            whatsapp = '9' + whatsapp.slice(-8);
        } else {
            whatsapp = whatsapp.slice(-8);
        }
      const whatsapp_formatado =return ddi + ddd + whatsapp;
    }
    return whatsapp_formatado;
}

if (payload.client) {

return {"name":payload.client.name,"email":payload.client.email,"phone":formatarTelefone(payload.client.cellphone),"body":payload};

} else {

throw new Error('Email não encontrado no payload.');

}

...