Skip to content

Commit

Permalink
changed presence events from contact to ticket
Browse files Browse the repository at this point in the history
  • Loading branch information
allgood committed Jun 30, 2024
1 parent db66e72 commit 682b090
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 168 deletions.
31 changes: 17 additions & 14 deletions backend/src/libs/wbot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { Store } from "./store";
import { StartWhatsAppSession } from "../services/WbotServices/StartWhatsAppSession";
import DeleteBaileysService from "../services/BaileysServices/DeleteBaileysService";
import Contact from "../models/Contact";
import Ticket from "../models/Ticket";

const loggerBaileys = MAIN_LOGGER.child({});
loggerBaileys.level = "error";
Expand Down Expand Up @@ -268,21 +269,23 @@ export const initWASocket = async (whatsapp: Whatsapp): Promise<Session> => {
companyId: whatsapp.companyId
}
});
if (!contact) {
return;
}
const ticket = await Ticket.findOne({
where: {
contactId: contact.id
}
});

if (contact) {
await contact.update({
presence: presences[remoteJid].lastKnownPresence
});

await contact.reload();

io.to(`company-${whatsapp.companyId}-mainchannel`).emit(
`company-${whatsapp.companyId}-contact`,
{
action: "update",
contact
}
);
if (ticket) {
io.to(ticket.id.toString())
.to(`company-${whatsapp.companyId}-${ticket.status}`)
.to(`queue-${ticket.queueId}-${ticket.status}`)
.emit(`company-${whatsapp.companyId}-presence`, {
ticketId: ticket.id,
presence: presences[remoteJid].lastKnownPresence
});
}
} catch (error) {
logger.error(
Expand Down
Loading

0 comments on commit 682b090

Please sign in to comment.