identaçao de codigo

pull/21/head
adriano 2023-01-20 16:38:24 -03:00
parent 6673faccbb
commit 69ddcc7c50
9 changed files with 46 additions and 81 deletions

View File

@ -43,6 +43,8 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
const ticket = await ShowTicketService(ticketId);
console.log('TICKET ID: ', ticketId)
SetTicketMessagesAsRead(ticket);
if (medias) {

View File

@ -92,6 +92,7 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
export const store = async (req: Request, res: Response): Promise<Response> => {
const { contactId, status, userId }: TicketData = req.body;
console.log('TICKET CREATE: ', 'contactId: ', contactId, ' | status: ', status, ' | userId: ', userId)
// test del
let ticket = await Ticket.findOne({ where: { contactId, status: 'queueChoice' } });

View File

@ -239,38 +239,6 @@ export const initWbot = async (whatsapp: Whatsapp, backupSessionRestore: boolean
}
// for (let i = 0; i <= 25; i++) {
// // console.log('Send: ', i, ' | miliseconds[Math.floor(Math.random() * miliseconds.length)]): ', miliseconds[Math.floor(Math.random() * miliseconds.length)])
// try {
// let stat = await wbot.getState();
// console.log('GET WHATSAPP STATE: ', stat)
// if (stat !== 'CONNECTED') break
// await wbot.sendMessage(`5517988325936@c.us`, `*@!ping*<>${whatsapp.name}\nIndex: ${i}`);
// await new Promise(r => setTimeout(r, miliseconds[Math.floor(Math.random() * miliseconds.length)]));
// } catch (error) {
// console.log(`Error on try send menssage boot from session: ${whatsapp.name}: ${error}`)
// break
// }
// }
});
} catch (err) {
logger.error(`${err}`);

View File

@ -17,5 +17,5 @@ if (global.gc) {
}
initIO(server);
// StartAllWhatsAppsSessions();
StartAllWhatsAppsSessions();
gracefulShutdown(server);

View File

@ -18,6 +18,9 @@ interface Request {
}
const CreateMessageService = async ({ messageData }: Request): Promise<Message> => {
console.log('UPSERT MESSAGE messageData: ', messageData)
await Message.upsert(messageData);
const message = await Message.findByPk(messageData.id, {
@ -55,6 +58,9 @@ const CreateMessageService = async ({ messageData }: Request): Promise<Message>
//
console.log('Entrou no create message')
const io = getIO();
io.to(message.ticketId.toString())
.to(message.ticket.status)

View File

@ -58,8 +58,6 @@ const SendWhatsAppMessage = async ({
let whatsapps = await wbotByUserQueue(ticket.userId)
// console.log('whatsapps whatsapps whatsapps: ', JSON.parse(JSON.stringify(whatsapps)))
if (whatsapps.length > 0) {
if (whatsapps.length > 1) {
@ -93,6 +91,7 @@ const SendWhatsAppMessage = async ({
console.timeEnd(timetaken)
return sentMessage;
} catch (err) {
const whatsapp = await ShowWhatsAppService(ticket.whatsappId);

View File

@ -159,8 +159,11 @@ const verifyMessage = async (
contact: Contact
) => {
console.log('Entrou no verify message...')
const quotedMsg = await verifyQuotedMessage(msg);
const messageData = {
id: msg.id.id,
ticketId: ticket.id,
@ -175,10 +178,6 @@ const verifyMessage = async (
await ticket.update({ lastMessage: msg.body });
// TEST DEL
// await updateTicketCacheByTicketId(ticket.id, { lastMessage: msg.body, updatedAt: new Date(ticket.updatedAt).toISOString() })
//
await CreateMessageService({ messageData });
};
@ -385,30 +384,6 @@ const handleMessage = async (
wbot: Session
): Promise<void> => {
// TEST DEL MULTI SESSION
// _clear_lst()
// let index = lst.findIndex((x: any) => x.id == msg.id.id)
// console.log('INDEX: ', index)
// if (index == -1) {
// lst.push({ id: msg.id.id })
// }
// else {
// console.log('IGNORED ID: ', msg.id.id)
// return
// }
// // console.log('LIST OF ID MESSAGE lst: ', lst)
// console.log('PASSOU.................................FROM: ', msg.from.split("@")[0], ' | ID: ', msg.id.id)
if (!isValidMsg(msg)) {
return;
}
@ -426,13 +401,19 @@ const handleMessage = async (
// in this case, return and let this message be handled by "media_uploaded" event, when it will have "hasMedia = true"
if (!msg.hasMedia && msg.type !== "chat" && msg.type !== "vcard") return;
msgContact = await wbot.getContactById(msg.to);
console.log('1 --------------> msgContat: ', JSON.parse(JSON.stringify(msgContact)))
console.log(' # msg.type: ', msg.type )
} else {
msgContact = await msg.getContact();
//
console.log('2 --------------> msgContat: ', JSON.parse(JSON.stringify(msgContact)))
//
console.log(`\n <<<<<<<<<< RECEIVING MESSAGE:
Parcial msg and msgContact info:
msgContact.name: ${msgContact.name}
@ -449,6 +430,7 @@ const handleMessage = async (
const chat = await msg.getChat();
console.log('----------> chat: ', JSON.parse(JSON.stringify(chat)))
if (chat.isGroup) {
let msgGroupContact;
@ -467,6 +449,8 @@ const handleMessage = async (
const contact = await verifyContact(msgContact);
console.log('----------> contact: ', JSON.parse(JSON.stringify(contact)))
if (unreadMessages === 0 && whatsapp.farewellMessage && whatsapp.farewellMessage === msg.body) return;
@ -483,9 +467,6 @@ const handleMessage = async (
// Para responder para o cliente pelo mesmo whatsapp que ele enviou a mensagen
if (wbot.id != ticket.whatsappId) {
await ticket.update({ whatsappId: wbot.id });
}
//
@ -876,6 +857,8 @@ const handleMsgAck = async (msg: WbotMessage, ack: MessageAck) => {
}
await messageToUpdate.update({ ack });
console.log('ACK messageToUpdate: ', JSON.parse(JSON.stringify(messageToUpdate)))
io.to(messageToUpdate.ticketId.toString()).emit("appMessage", {
action: "update",
message: messageToUpdate
@ -888,6 +871,7 @@ const handleMsgAck = async (msg: WbotMessage, ack: MessageAck) => {
};
const wbotMessageListener = (wbot: Session): void => {
wbot.on("message_create", async msg => {
handleMessage(msg, wbot);
});

View File

@ -319,6 +319,8 @@ const MessageInput = ({ ticketStatus }) => {
quotedMsg: replyingMessage,
};
try {
// console.log('message: ', message)
await api.post(`/messages/${ticketId}`, message);
} catch (err) {
toastError(err);

View File

@ -364,6 +364,9 @@ const MessagesList = ({ ticketId, isGroup }) => {
socket.on("appMessage", (data) => {
if (data.action === "create") {
console.log('ADD_MESSAGE: ', data.message)
dispatch({ type: "ADD_MESSAGE", payload: data.message });
scrollToBottom();