I have a code, where I have a callback, with the value of the callback I send a message on whatsApp. But before the callback loop I add the function of sending a welcome message, however, the welcome message goes after the CallBack message, and it should go before. Does anyone know why it happens and how to solve it?
Code
function start(client) {
client.onMessage((message) => {
mensagem = message.body.split(' ')
estado = mensagem.slice(1, 2)
palavraChave = mensagem.slice(0, 1).join(' ').toLowerCase()
NomePessoa = message.sender.name || message.sender.pushname
if (palavraChave === '/coronavírus' || palavraChave === '/coronavirus') {
client.sendText(message.from, `Hello`) //This message goes last
api.pesquisa(`${estado}`).then((infoCorona) => {
client.sendText(message.from, `${infoCorona}`) //This message goes first
contador++
console.log(`Você ajudou ${contador} pessoas.`)
});
}
});
}