fix: bug id and body undefined from webhook

feat-scaling-ticket-remote-creation
adriano 2024-03-07 15:25:22 -03:00
parent ec6e84f567
commit c5c5ddb5a4
2 changed files with 41 additions and 32 deletions

View File

@ -265,6 +265,10 @@ export const weebhook = async (
}); });
if (type == "text") { if (type == "text") {
if (!message?.text?.body) {
return res.status(400).json({ error: "body not found" });
}
type = "chat"; type = "chat";
msg = { msg = {
...msg, ...msg,
@ -272,6 +276,10 @@ export const weebhook = async (
type type
}; };
} else { } else {
if (!message[message?.type]?.id) {
return res.status(400).json({ error: "id not found" });
}
const mediaId = message[message.type].id; const mediaId = message[message.type].id;
const mimetype = message[message.type].mime_type; const mimetype = message[message.type].mime_type;

View File

@ -98,7 +98,7 @@ import FindOrCreateTicketServiceBot from "../TicketServices/FindOrCreateTicketSe
import ShowTicketService from "../TicketServices/ShowTicketService"; import ShowTicketService from "../TicketServices/ShowTicketService";
import ShowQueuesByUser from "../UserServices/ShowQueuesByUser"; import ShowQueuesByUser from "../UserServices/ShowQueuesByUser";
import ListWhatsappQueuesByUserQueue from "../UserServices/ListWhatsappQueuesByUserQueue"; import ListWhatsappQueuesByUserQueue from "../UserServices/ListWhatsappQueuesByUserQueue";
import CreateContactService from "../ContactServices/CreateContactService" import CreateContactService from "../ContactServices/CreateContactService";
var lst: any[] = getWhatsappIds(); var lst: any[] = getWhatsappIds();
@ -318,14 +318,15 @@ const verifyQueue = async (
selectedOption = 1; selectedOption = 1;
choosenQueue = queues[+selectedOption - 1]; choosenQueue = queues[+selectedOption - 1];
} else { } else {
selectedOption = msg.body; selectedOption = msg?.body;
if (selectedOption && selectedOption.trim().length > 0) {
//////////////// EXTRAIR APENAS O NÚMERO /////////////////// //////////////// EXTRAIR APENAS O NÚMERO ///////////////////
selectedOption = selectedOption.replace(/[^1-9]/g, ""); selectedOption = selectedOption.replace(/[^1-9]/g, "");
/////////////////////////////////// ///////////////////////////////////
choosenQueue = queues[+selectedOption - 1]; choosenQueue = queues[+selectedOption - 1];
} }
}
if (choosenQueue) { if (choosenQueue) {
// Atualizando o status do ticket para mostrar notificação para o atendente da fila escolhida pelo usuário. De queueChoice para pending // Atualizando o status do ticket para mostrar notificação para o atendente da fila escolhida pelo usuário. De queueChoice para pending