Compare commits

...

3 Commits

8 changed files with 139 additions and 65 deletions

View File

@ -257,10 +257,10 @@ export const contacsBulkInsertOnQueue = async (
}; };
function addStartPhoneNumber(phoneNumber: string) { function addStartPhoneNumber(phoneNumber: string) {
const regex = /^55/; const regex = /^57/;
if (!regex.test(phoneNumber)) { if (!regex.test(phoneNumber)) {
phoneNumber = "55" + phoneNumber; phoneNumber = "57" + phoneNumber;
} }
return phoneNumber; return phoneNumber;

View File

@ -51,10 +51,10 @@ const schedule = async () => {
} catch (error) { } catch (error) {
console.log("error on schedule: ", error); console.log("error on schedule: ", error);
} finally { } finally {
timer = setInterval(schedule, 180000); timer = setInterval(schedule, 299999);
} }
}; };
timer = setInterval(schedule, 180000); timer = setInterval(schedule, 299999);
export default schedule; export default schedule;

View File

@ -1,4 +1,5 @@
import fs from "fs"; import fs from "fs";
import path from "path";
import { MessageMedia, Message as WbotMessage } from "whatsapp-web.js"; import { MessageMedia, Message as WbotMessage } from "whatsapp-web.js";
import AppError from "../../errors/AppError"; import AppError from "../../errors/AppError";
import GetTicketWbot from "../../helpers/GetTicketWbot"; import GetTicketWbot from "../../helpers/GetTicketWbot";
@ -14,51 +15,108 @@ import { mediaTypeWhatsappOfficial } from "./wbotMessageListener";
import { bytesToMB } from "../../helpers/BytesToMB"; import { bytesToMB } from "../../helpers/BytesToMB";
interface Request { interface Request {
media: Express.Multer.File; media?: Express.Multer.File;
ticket: Ticket; ticket: Ticket;
mic_audio?: any mic_audio?: any;
filePath?: string;
} }
const SendWhatsAppMedia = async ({ const SendWhatsAppMedia = async ({
media, media,
ticket, ticket,
mic_audio mic_audio,
filePath
}: Request): Promise<WbotMessage | any> => { }: Request): Promise<WbotMessage | any> => {
const { phoneNumberId } = ticket; const { phoneNumberId } = ticket;
if (phoneNumberId) { if (phoneNumberId) {
const { type, mbMaxSize }: any = mediaTypeWhatsappOfficial(media.mimetype); if (media) {
const { type, mbMaxSize }: any = mediaTypeWhatsappOfficial(media.mimetype);
const filesize: any = bytesToMB(media.size); const filesize: any = bytesToMB(media.size);
if (filesize > mbMaxSize) { if (filesize > mbMaxSize) {
throw new AppError("FILE TOO LARGE!"); throw new AppError("FILE TOO LARGE!");
}
if (!type) {
throw new AppError("FILE TYPE NOT SUPPORTED!");
}
sendWhatsMediaOfficialAPI(ticket, media, type, mic_audio);
return;
} }
if (!type) {
throw new AppError("FILE TYPE NOT SUPPORTED!");
}
sendWhatsMediaOfficialAPI(ticket, media, type, mic_audio);
return;
} }
try { try {
const newMedia = MessageMedia.fromFilePath(media.path); let newMedia: MessageMedia;
if (filePath) {
newMedia = MessageMedia.fromFilePath(filePath);
} else if (media) {
newMedia = MessageMedia.fromFilePath(media.path);
} else {
throw new AppError("No media provided!");
}
sendWhatsAppMediaSocket(ticket, newMedia); sendWhatsAppMediaSocket(ticket, newMedia);
await ticket.update({ lastMessage: media.filename }); const lastMessage = filePath ? path.basename(filePath) : media?.filename;
await ticket.update({ lastMessage });
await updateTicketCacheByTicketId(ticket.id, { await updateTicketCacheByTicketId(ticket.id, {
lastMessage: media.filename, lastMessage,
updatedAt: new Date(ticket.updatedAt).toISOString() updatedAt: new Date(ticket.updatedAt).toISOString()
}); });
console.log("media.path: ", media.path); if (media) {
fs.unlinkSync(media.path); fs.unlinkSync(media.path);
}
} catch (err) { } catch (err) {
throw new AppError("ERR_SENDING_WAPP_MSG"); throw new AppError("ERR_SENDING_WAPP_MSG");
} }
// const { phoneNumberId } = ticket;
// if (phoneNumberId) {
// const { type, mbMaxSize }: any = mediaTypeWhatsappOfficial(media.mimetype);
// const filesize: any = bytesToMB(media.size);
// if (filesize > mbMaxSize) {
// throw new AppError("FILE TOO LARGE!");
// }
// if (!type) {
// throw new AppError("FILE TYPE NOT SUPPORTED!");
// }
// sendWhatsMediaOfficialAPI(ticket, media, type, mic_audio);
// return;
// }
// try {
// //const newMedia = MessageMedia.fromFilePath(media.path);
// let newMedia: MessageMedia;
// if (filePath) {
// newMedia = MessageMedia.fromFilePath(filePath);
// } else if (media) {
// newMedia = MessageMedia.fromFilePath(media.path);
// } else {
// throw new AppError("No media provided!");
// }
// sendWhatsAppMediaSocket(ticket, newMedia);
// await ticket.update({ lastMessage: media.filename });
// await updateTicketCacheByTicketId(ticket.id, {
// lastMessage: media.filename,
// updatedAt: new Date(ticket.updatedAt).toISOString()
// });
// console.log("media.path: ", media.path);
// fs.unlinkSync(media.path);
// } catch (err) {
// throw new AppError("ERR_SENDING_WAPP_MSG");
// }
}; };
export default SendWhatsAppMedia; export default SendWhatsAppMedia;

View File

@ -110,7 +110,7 @@ import AssociateContatctQueue from "../ContactServices/AssociateContatctQueue";
import ContactQueue from "../../models/ContactQueues"; import ContactQueue from "../../models/ContactQueues";
import { encodeFileToBase64 } from "../../helpers/EncodeFileToBase64"; import { encodeFileToBase64 } from "../../helpers/EncodeFileToBase64";
import { Json } from "sequelize/types/lib/utils"; import { Json } from "sequelize/types/lib/utils";
import SendWhatsAppMedia from "./SendWhatsAppMedia";
var lst: any[] = getWhatsappIds(); var lst: any[] = getWhatsappIds();
interface Session extends Client { interface Session extends Client {
@ -278,7 +278,7 @@ const question = async (
) { ) {
await botSendMessage( await botSendMessage(
ticket, ticket,
"¡Envía uno o más archivos simultáneamente!" "Por favor adjuntar evidencias.\n¡Envía uno o más archivos simultáneamente!"
); );
return; return;
} }
@ -327,22 +327,9 @@ const question = async (
} }
} }
// currentId = await get({ key: `form:${ticket.id}:current` });
let index = ask.findIndex((obj: any) => obj.id == currentId); let index = ask.findIndex((obj: any) => obj.id == currentId);
if (index != -1) { if (index != -1) {
console.log(
"msg?.body: ",
msg?.body,
" | sendFile?.filePath: ",
sendFile?.filePath,
" | index: ",
index,
" | ask[index]?.item?.file: ",
ask[index]?.item?.file
);
if (!ask[index]?.item?.file && !sendFile) { if (!ask[index]?.item?.file && !sendFile) {
ask[index].value = msg?.body; ask[index].value = msg?.body;
} }
@ -352,18 +339,22 @@ const question = async (
if (index + 1 <= ask.length - 1) { if (index + 1 <= ask.length - 1) {
if (ask[index + 1]?.item?.file && !sendFile) { if (ask[index + 1]?.item?.file && !sendFile) {
await botSendMessage( // await botSendMessage(
ticket, // ticket,
"¿Quieres enviar archivo? Ingrese *Sí* o *No*" // "¿Quieres enviar archivo? Ingrese *Sí* o *No*"
); // );
await set( await set(
`form:${ticket.id}:file`, `form:${ticket.id}:file`,
JSON.stringify({ status: "waiting" }) JSON.stringify({ status: "waiting" })
); );
return; set(
`form:${ticket.id}:file`,
JSON.stringify({ ...sendFile, status: "yes" })
);
// return;
} }
// Next question // Next question
await botSendMessage(ticket, ask[index + 1].question); await botSendMessage(ticket, ask[index + 1].question);
await set(`form:${ticket.id}:current`, `${ask[index + 1].id}`); await set(`form:${ticket.id}:current`, `${ask[index + 1].id}`);
} else { } else {
@ -478,13 +469,13 @@ const verifyMediaMessage = async (
phoneNumberId: msg?.phoneNumberId, phoneNumberId: msg?.phoneNumberId,
fromAgent: false fromAgent: false
}; };
if ( // if (
messageData.mediaType === "video" || // messageData.mediaType === "video" ||
(messageData.mediaType === "audio" && // (messageData.mediaType === "audio" &&
getSettingValue("blockAudioVideoMedia")?.value === "enabled") // getSettingValue("blockAudioVideoMedia")?.value === "enabled")
) { // ) {
mediaAuthorized = false; // mediaAuthorized = false;
} // }
if (msg?.fromMe) { if (msg?.fromMe) {
messageData = { ...messageData, fromAgent: true }; messageData = { ...messageData, fromAgent: true };
} }
@ -1222,7 +1213,7 @@ const handleMessage = async (
return; return;
} }
} }
// //
if ( if (
@ -1257,7 +1248,7 @@ const handleMessage = async (
if (msg.type == "chat" && String(msg.body).length > 120) { if (msg.type == "chat" && String(msg.body).length > 120) {
botSendMessage( botSendMessage(
ticket, ticket,
`Desculpe, nao compreendi!\nTexto acima de 120 caracteres!\n _Digite *0* para voltar ao menu principal._` `¡Disculpa, no comprendí!\n\n¡El mensaje tiene más de 120 caracteres!\n\n_Digite 0 para volver al menú principal._`
); );
return; return;
} }
@ -1390,18 +1381,18 @@ const handleMessage = async (
msg?.body?.trim() != "0" && msg?.body?.trim() != "0" &&
msg?.body?.trim() != "#" msg?.body?.trim() != "#"
) { ) {
await question(fillingOutForm, msg, ticket, contact, wbot); await question(fillingOutForm, msg, ticket, contact, wbot);
return; return;
} }
const menuMsg: any = await menu(msg.body, wbot.id, contact.id); const menuMsg: any = await menu(msg.body, wbot.id, contact.id, ticket);
console.log("menuMsg: ", menuMsg); console.log("menuMsg: ", menuMsg);
await botSendMessage( await botSendMessage(
ticket, ticket,
menuMsg.value + menuMsg.value +
"\n\nSi desea volver al menú principal, escriba *0* o *#* para volver al menú anterior" "\n\nSi deseas volver al menú principal, escriba *0* o *#* para volver al menú anterior"
); );
if ( if (
@ -1484,7 +1475,7 @@ const handleMessage = async (
}, },
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, ticket);
await botSendMessage(ticket, menuMsg.value); await botSendMessage(ticket, menuMsg.value);
} }
@ -1507,7 +1498,7 @@ const handleMessage = async (
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, ticket);
await botSendMessage(ticket, menuMsg.value); await botSendMessage(ticket, menuMsg.value);
@ -1549,7 +1540,7 @@ const handleMessage = async (
}; };
async function previousUra(wbot: any, contact: Contact, ticket: any) { async function previousUra(wbot: any, contact: Contact, ticket: any) {
const menuMsg: any = await menu("#", wbot.id, contact.id); const menuMsg: any = await menu("#", wbot.id, contact.id, ticket);
botSendMessage(ticket, menuMsg.value); botSendMessage(ticket, menuMsg.value);
} }
@ -1602,7 +1593,7 @@ function delForm(ticket: any) {
del(`form:${ticket.id}:confirmation`); del(`form:${ticket.id}:confirmation`);
} }
const menu = async (userTyped: string, whatsappId: any, contactId: any) => { const menu = async (userTyped: string, whatsappId: any, contactId: any, ticket: any) => {
let whatsapp = await whatsappCache(whatsappId); let whatsapp = await whatsappCache(whatsappId);
let lastId = await findObject( let lastId = await findObject(
@ -1614,7 +1605,7 @@ const menu = async (userTyped: string, whatsappId: any, contactId: any) => {
const data: any = await get({ const data: any = await get({
key: whatsapp?.number ? `ura_${whatsapp?.number}` : "ura", key: whatsapp?.number ? `ura_${whatsapp?.number}` : "ura",
parse: true parse: true
}); });
if (!lastId[0]) { if (!lastId[0]) {
await createObject({ await createObject({
@ -1624,6 +1615,21 @@ const menu = async (userTyped: string, whatsappId: any, contactId: any) => {
value: data[1].id, value: data[1].id,
history: `|${data[1].id}` history: `|${data[1].id}`
}); });
if(whatsapp && whatsapp.number === '573168762241'){
const imagePath = path.join(__dirname, '..','..','utils','OET_inicio.jpg');
await SendWhatsAppMedia({
ticket,
filePath: imagePath
});
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Send image init')
}else if(whatsapp && whatsapp.number === '573159260397'){
const imagePath = path.join(__dirname, '..','..','utils','Faro_inicio.jpeg');
await SendWhatsAppMedia({
ticket,
filePath: imagePath
});
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Send image init')
}
} }
lastId = await findObject( lastId = await findObject(
@ -1884,10 +1890,13 @@ async function whatsappCache(whatsappId: any) {
let whatsapp = await get({ key: "whatsapp:*", parse: true }); let whatsapp = await get({ key: "whatsapp:*", parse: true });
let uraByNumber = await get({ key: "ura_*", parse: true }); let uraByNumber = await get({ key: "ura_*", parse: true });
// console.log("------------------------> uraByNumber: ", uraByNumber);
whatsapp = whatsapp.filter((w: any) => +w?.id == +whatsappId); whatsapp = whatsapp.filter((w: any) => +w?.id == +whatsappId);
console.log("------------------------> whatsapp: ", whatsapp);
if (whatsapp && whatsapp.length > 0 && uraByNumber) return whatsapp[0]; if (whatsapp && whatsapp.length > 0 && uraByNumber) return whatsapp[0];
} }
@ -1964,7 +1973,7 @@ async function backUra(whatsappId: any, contactId: any, data: any) {
let uraOptionSelected = await findObject( let uraOptionSelected = await findObject(
whatsappId, whatsappId,
contactId, contactId,
_whatsapp?.number ? `ura_${_whatsapp?.number}` : "ura" _whatsapp?.number ? `ura_${_whatsapp?.number}` : "ura"
); );
@ -2205,6 +2214,13 @@ async function setSoport(ticket: any, wbot: any, contact: any) {
}) })
.join(""); .join("");
let request = await get({
key: `form:${ticket.id}:request`,
parse: true
});
payload += `<nit_transp>${request.nit}</nit_transp>`;
let payloadFile = fillingOutForm.ask.find((a: any) => a?.item?.file); let payloadFile = fillingOutForm.ask.find((a: any) => a?.item?.file);
let files = ""; let files = "";
@ -2251,7 +2267,7 @@ async function setSoport(ticket: any, wbot: any, contact: any) {
</soapenv:Body> </soapenv:Body>
</soapenv:Envelope>`; </soapenv:Envelope>`;
// console.log("DATA: ", data); console.log("DATA REQUEST: ", data);
// return; // return;
var config = { var config = {

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

View File

@ -247,7 +247,7 @@ const MessageInput = ({ ticketStatus, ticketLastMessage, ticketIsRemote }) => {
setInputMessage(ticketLastMessage) setInputMessage(ticketLastMessage)
} }
else { else {
setInputMessage("") //setInputMessage("")
} }
}, [countTicketMsg, ticketIsRemote, ticketLastMessage]) }, [countTicketMsg, ticketIsRemote, ticketLastMessage])

View File

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