Compare commits

..

No commits in common. "d298f75efce12365e679006e511d0da90ad85ee3" and "9b6e48f54e65a827152ccd724b5703be30fbedd7" have entirely different histories.

3 changed files with 39 additions and 25 deletions

View File

@ -80,7 +80,7 @@ const UpdateTicketService = async ({
if (msg?.trim().length > 0) { if (msg?.trim().length > 0) {
setTimeout(async () => { setTimeout(async () => {
sendWhatsAppMessageSocket(ticket, `\u200e${msg}`); sendWhatsAppMessageSocket(ticket, msg);
}, 2000); }, 2000);
} }

View File

@ -392,7 +392,7 @@ const verifyQueue = async (
if (outService.length > 0) { if (outService.length > 0) {
const { type, msg: msgOutService } = outService[0]; const { type, msg: msgOutService } = outService[0];
console.log(`${type} message ignored on queue`); console.log(`${type} message ignored on queue`);
botSendMessage(ticket, `\u200e${msgOutService}`); botSendMessage(ticket, msgOutService);
return; return;
} }
@ -585,7 +585,7 @@ const botTransferTicketToUser = async (
}; };
const botSendMessage = (ticket: Ticket, msg: string) => { const botSendMessage = (ticket: Ticket, msg: string) => {
const { phoneNumberId } = ticket; const { phoneNumberId } = ticket;
const debouncedSentMessage = debounce( const debouncedSentMessage = debounce(
async () => { async () => {
@ -643,10 +643,27 @@ const handleMessage = async (
let msgContact: any = wbot.msgContact; let msgContact: any = wbot.msgContact;
// let groupContact: Contact | undefined; // let groupContact: Contact | undefined;
if (msg.fromMe) { if (msg.fromMe) {
const whatsapp = await whatsappInfo(wbot.id);
if (whatsapp?.number) {
const ticketExpiration = await SettingTicket.findOne({
where: { key: "ticketExpiration", number: whatsapp.number }
});
if (
ticketExpiration &&
ticketExpiration.value == "enabled" &&
ticketExpiration?.message.trim() == msg.body.trim()
) {
console.log("*********** TICKET EXPIRATION");
return;
}
}
// messages sent automatically by wbot have a special character in front of it // messages sent automatically by wbot have a special character in front of it
// if so, this message was already been stored in database; // if so, this message was already been stored in database;
if (/\u200e/.test(msg.body[0])) return; // if (/\u200e/.test(msg.body[0])) return;
// media messages sent from me from cell phone, first comes with "hasMedia = false" and type = "image/ptt/etc" // media messages sent from me from cell phone, first comes with "hasMedia = false" and type = "image/ptt/etc"
// in this case, return and let this message be handled by "media_uploaded" event, when it will have "hasMedia = true" // in this case, return and let this message be handled by "media_uploaded" event, when it will have "hasMedia = true"
@ -918,28 +935,25 @@ const handleMessage = async (
ticket.status == "pending" && ticket.status == "pending" &&
ticket.queueId ticket.queueId
) { ) {
if (botInfo.isOnQueue) { let choosenQueue = await ShowQueueService(botInfo.botQueueId);
let choosenQueue = await ShowQueueService(botInfo.botQueueId);
await UpdateTicketService({ await UpdateTicketService({
ticketData: { ticketData: {
status: "open", status: "open",
userId: botInfo.userIdBot, userId: botInfo.userIdBot,
queueId: choosenQueue.id queueId: choosenQueue.id
}, },
ticketId: ticket.id ticketId: ticket.id
}); });
const menuMsg: any = await menu(msg.body, wbot.id, contact.id); const menuMsg: any = await menu(msg.body, wbot.id, contact.id);
await botSendMessage(ticket, menuMsg.value); await botSendMessage(ticket, menuMsg.value);
}
return; return;
} else if ( } else if (
!msg.fromMe && !msg.fromMe &&
msg.body == "#" && msg.body == "#" &&
ticket.status == "pending" && ticket.status == "pending" &&
ticket.queueId && ticket.queueId
botInfo.isOnQueue
) { ) {
let choosenQueue = await ShowQueueService(botInfo.botQueueId); let choosenQueue = await ShowQueueService(botInfo.botQueueId);
@ -976,7 +990,7 @@ const handleMessage = async (
if (ticket?.queueId) { if (ticket?.queueId) {
ticketHasQueue = true; ticketHasQueue = true;
} }
if (ticketHasQueue && ticket.status != "open") { if (ticketHasQueue && ticket.status != "open") {
let whatsapp: any = await whatsappInfo(ticket?.whatsappId); let whatsapp: any = await whatsappInfo(ticket?.whatsappId);
@ -990,7 +1004,7 @@ const handleMessage = async (
return; return;
} }
botSendMessage(ticket, `\u200e${msgOutService}`); botSendMessage(ticket, msgOutService);
return; return;
} }
} }

View File

@ -9,12 +9,12 @@ const ListWhatsAppsNumber = async (
let whatsapps: any = []; let whatsapps: any = [];
if (whatsapp) { if (whatsapp) {
if (status) { if (status) {
whatsapps = await Whatsapp.findAll({ whatsapps = await Whatsapp.findAll({
raw: true, raw: true,
where: { number: whatsapp.number, status: status, }, where: { number: whatsapp.number, status: status, },
attributes: ["id", "number", "status", "isDefault", "url", 'isOfficial'] attributes: ["id", "number", "status", "isDefault", "url", 'isOfficial']
}); });
} else { } else {
whatsapps = await Whatsapp.findAll({ whatsapps = await Whatsapp.findAll({
raw: true, raw: true,