Skip to content

Commit

Permalink
feat(messaging): Add an endpoint to handle events (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreroggeri authored Aug 18, 2024
1 parent ed847d3 commit 305e0d4
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions chatbot/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,29 @@ void (async () => {

app.use('/v1/', buildApiRouter(messenger));

app.use('/events', async (req, res) => {
logger.info('Received events', { body: req.body });

const messageType = req.body.message?.type;

switch (messageType) {
case 'end-of-call-report':
const number = req.body.message?.call?.customer?.number;
logger.info('Received end-of-call-report', { number });
if (number) {
const numberWithoutPlusSign = number.replace('+', '');
const jid = `${numberWithoutPlusSign}@s.whatsapp.net`;
if (await messenger.phoneHasAccount(jid)) {
messenger.sendMessage(jid, 'Olá, aqui é do consultório odontológico. Vi que você acabou de ligar. Qualquer dúvida estamos a disposição.');
}
}
return res.status(200).json({ status: 'ok' });
break;
default:
return res.status(200).json({ status: 'ok' });
}
});

app.listen(settings.port, () => {
logger.info(`Chatbot is running on :${settings.port}`);
});
Expand Down

0 comments on commit 305e0d4

Please sign in to comment.