Compare commits

...

2 Commits

Author SHA1 Message Date
adriano b9f8bfc8d5 feat: add group suport in api session 2024-06-13 17:53:07 -03:00
adriano 1c93c16f84 feat: Add support for WhatsApp groups 2024-06-13 17:50:30 -03:00
6 changed files with 42 additions and 23 deletions

View File

@ -885,11 +885,15 @@ async function handleMessage(msg) {
if (msg.fromMe) {
console.log('MSG FROM ME')
msgContact = await client.getContactById(msg.to)
}
else {
console.log('MSG FROM CLIENT')
console.log('################# RECEIVING MESSAGE FROM: ', msg.from, ' to ', msg.to)
msgContact = await msg.getContact()
@ -912,10 +916,10 @@ async function handleMessage(msg) {
msgContact: msgContact,
chat: chat,
quotedMsg: quotedMsg ? quotedMsg.id.id : null,
media: media
media: media,
getContactById: msg.fromMe ? await client.getContactById(msg.to) : await client.getContactById(msg.from)
}
socketIo.emit("message_create", data)
}

View File

@ -114,7 +114,7 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
withUnreadMessages,
unlimited,
searchParamContent
});
});
return res
.status(200)

View File

@ -60,10 +60,11 @@ const FindOrCreateTicketService = async (
order: [["updatedAt", "DESC"]]
});
if (ticket) {
if (ticket) {
await ticket.update({
status: "pending",
userId: null,
queueId: null,
unreadMessages
});
}
@ -96,7 +97,12 @@ const FindOrCreateTicketService = async (
if (!ticket) {
let status = "pending";
if (queues.length > 1 && !botInfo.isOnQueue && !queueId) {
if (
queues.length > 1 &&
!botInfo.isOnQueue &&
!queueId &&
!groupContact
) {
status = "queueChoice";
}

View File

@ -372,6 +372,12 @@ const verifyQueue = async (
ticket: Ticket,
contact: Contact
) => {
if(ticket?.isGroup){
return
}
const { queues, greetingMessage } = await ShowWhatsAppService(wbot.id!);
let selectedOption = null;
@ -703,7 +709,7 @@ const handleMessage = async (
try {
let msgContact: any = wbot.msgContact;
// let groupContact: Contact | undefined;
let groupContact: Contact | undefined;
if (msg.fromMe) {
// messages sent automatically by wbot have a special character in front of it
@ -743,18 +749,21 @@ const handleMessage = async (
// console.log('----------> chat: ', JSON.parse(JSON.stringify(chat)))
// if (chat.isGroup) {
// let msgGroupContact;
// if (msg.fromMe) {
// msgGroupContact = await wbot.getContactById(msg.to);
// } else {
// msgGroupContact = await wbot.getContactById(msg.from);
// }
console
// groupContact = await verifyContact(msgGroupContact);
// }
if (chat.isGroup) {
// let msgGroupContact;
// if (msg.fromMe) {
// msgGroupContact = await wbot.getContactById(msg.to);
// } else {
// msgGroupContact = await wbot.getContactById(msg.from);
// }
groupContact = await verifyContact(wbot.getContactById);
}
const whatsapp = await ShowWhatsAppService(wbot.id!);
const unreadMessages = msg.fromMe ? 0 : chat.unreadCount;
@ -777,12 +786,12 @@ const handleMessage = async (
const _botInfo = await BotIsOnQueue("botqueue");
if (_botInfo.isOnQueue) {
if (_botInfo.isOnQueue && !chat.isGroup) {
let ticket_obj: any = await FindOrCreateTicketServiceBot(
contact,
wbot.id!,
unreadMessages
// groupContact
unreadMessages,
groupContact
);
ticket = ticket_obj.ticket;
@ -801,8 +810,8 @@ const handleMessage = async (
ticket = await FindOrCreateTicketService(
contact,
wbot.id!,
unreadMessages
// groupContact
unreadMessages,
groupContact
);
}

View File

@ -387,10 +387,10 @@ const NotificationsPopOver = () => {
vertical: "top",
horizontal: "right",
}}
classes={{ paper: classes.popoverPaper }}
classes={{ paper: classes?.popoverPaper }}
onClose={handleClickAway}
>
<List dense className={classes.tabContainer}>
<List dense className={classes?.tabContainer}>
{notifications.length === 0 ? (
<ListItem>
<ListItemText>{i18n.t("notifications.noTickets")}</ListItemText>

View File

@ -229,7 +229,7 @@ const TicketListItem = ({ ticket, remoteTicketsControll, settings }) => {
variant="body2"
color="textPrimary"
>
{ticket.contact.name}
{ticket?.contact?.name}
</Typography>
{ticket.status === "closed" && (
<Badge