Compare commits
No commits in common. "6450fb6ea74ff2a591367586f7561e46331194d6" and "6762c8041d662d32eaf2889ede9054b6adbf0dad" have entirely different histories.
6450fb6ea7
...
6762c8041d
|
@ -257,10 +257,10 @@ export const contacsBulkInsertOnQueue = async (
|
|||
};
|
||||
|
||||
function addStartPhoneNumber(phoneNumber: string) {
|
||||
const regex = /^57/;
|
||||
const regex = /^55/;
|
||||
|
||||
if (!regex.test(phoneNumber)) {
|
||||
phoneNumber = "57" + phoneNumber;
|
||||
phoneNumber = "55" + phoneNumber;
|
||||
}
|
||||
|
||||
return phoneNumber;
|
||||
|
|
|
@ -51,10 +51,10 @@ const schedule = async () => {
|
|||
} catch (error) {
|
||||
console.log("error on schedule: ", error);
|
||||
} finally {
|
||||
timer = setInterval(schedule, 299999);
|
||||
timer = setInterval(schedule, 180000);
|
||||
}
|
||||
};
|
||||
|
||||
timer = setInterval(schedule, 299999);
|
||||
timer = setInterval(schedule, 180000);
|
||||
|
||||
export default schedule;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { MessageMedia, Message as WbotMessage } from "whatsapp-web.js";
|
||||
import AppError from "../../errors/AppError";
|
||||
import GetTicketWbot from "../../helpers/GetTicketWbot";
|
||||
|
@ -15,22 +14,19 @@ import { mediaTypeWhatsappOfficial } from "./wbotMessageListener";
|
|||
import { bytesToMB } from "../../helpers/BytesToMB";
|
||||
|
||||
interface Request {
|
||||
media?: Express.Multer.File;
|
||||
media: Express.Multer.File;
|
||||
ticket: Ticket;
|
||||
mic_audio?: any;
|
||||
filePath?: string;
|
||||
mic_audio?: any
|
||||
}
|
||||
|
||||
const SendWhatsAppMedia = async ({
|
||||
media,
|
||||
ticket,
|
||||
mic_audio,
|
||||
filePath
|
||||
mic_audio
|
||||
}: Request): Promise<WbotMessage | any> => {
|
||||
const { phoneNumberId } = ticket;
|
||||
|
||||
if (phoneNumberId) {
|
||||
if (media) {
|
||||
const { type, mbMaxSize }: any = mediaTypeWhatsappOfficial(media.mimetype);
|
||||
|
||||
const filesize: any = bytesToMB(media.size);
|
||||
|
@ -45,78 +41,24 @@ const SendWhatsAppMedia = async ({
|
|||
sendWhatsMediaOfficialAPI(ticket, media, type, mic_audio);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
let newMedia: MessageMedia;
|
||||
if (filePath) {
|
||||
newMedia = MessageMedia.fromFilePath(filePath);
|
||||
} else if (media) {
|
||||
newMedia = MessageMedia.fromFilePath(media.path);
|
||||
} else {
|
||||
throw new AppError("No media provided!");
|
||||
}
|
||||
const newMedia = MessageMedia.fromFilePath(media.path);
|
||||
|
||||
sendWhatsAppMediaSocket(ticket, newMedia);
|
||||
|
||||
const lastMessage = filePath ? path.basename(filePath) : media?.filename;
|
||||
|
||||
await ticket.update({ lastMessage });
|
||||
await ticket.update({ lastMessage: media.filename });
|
||||
|
||||
await updateTicketCacheByTicketId(ticket.id, {
|
||||
lastMessage,
|
||||
lastMessage: media.filename,
|
||||
updatedAt: new Date(ticket.updatedAt).toISOString()
|
||||
});
|
||||
|
||||
if (media) {
|
||||
console.log("media.path: ", media.path);
|
||||
fs.unlinkSync(media.path);
|
||||
}
|
||||
} catch (err) {
|
||||
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;
|
||||
|
|
|
@ -110,7 +110,7 @@ import AssociateContatctQueue from "../ContactServices/AssociateContatctQueue";
|
|||
import ContactQueue from "../../models/ContactQueues";
|
||||
import { encodeFileToBase64 } from "../../helpers/EncodeFileToBase64";
|
||||
import { Json } from "sequelize/types/lib/utils";
|
||||
import SendWhatsAppMedia from "./SendWhatsAppMedia";
|
||||
|
||||
var lst: any[] = getWhatsappIds();
|
||||
|
||||
interface Session extends Client {
|
||||
|
@ -278,7 +278,7 @@ const question = async (
|
|||
) {
|
||||
await botSendMessage(
|
||||
ticket,
|
||||
"Por favor adjuntar evidencias.\n¡Envía uno o más archivos simultáneamente!"
|
||||
"¡Envía uno o más archivos simultáneamente!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
@ -327,9 +327,22 @@ const question = async (
|
|||
}
|
||||
}
|
||||
|
||||
// currentId = await get({ key: `form:${ticket.id}:current` });
|
||||
|
||||
let index = ask.findIndex((obj: any) => obj.id == currentId);
|
||||
|
||||
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) {
|
||||
ask[index].value = msg?.body;
|
||||
}
|
||||
|
@ -339,22 +352,18 @@ const question = async (
|
|||
|
||||
if (index + 1 <= ask.length - 1) {
|
||||
if (ask[index + 1]?.item?.file && !sendFile) {
|
||||
// await botSendMessage(
|
||||
// ticket,
|
||||
// "¿Quieres enviar archivo? Ingrese *Sí* o *No*"
|
||||
// );
|
||||
await botSendMessage(
|
||||
ticket,
|
||||
"¿Quieres enviar archivo? Ingrese *Sí* o *No*"
|
||||
);
|
||||
await set(
|
||||
`form:${ticket.id}:file`,
|
||||
JSON.stringify({ status: "waiting" })
|
||||
);
|
||||
set(
|
||||
`form:${ticket.id}:file`,
|
||||
JSON.stringify({ ...sendFile, status: "yes" })
|
||||
);
|
||||
// return;
|
||||
return;
|
||||
}
|
||||
// Next question
|
||||
|
||||
// Next question
|
||||
await botSendMessage(ticket, ask[index + 1].question);
|
||||
await set(`form:${ticket.id}:current`, `${ask[index + 1].id}`);
|
||||
} else {
|
||||
|
@ -469,13 +478,13 @@ const verifyMediaMessage = async (
|
|||
phoneNumberId: msg?.phoneNumberId,
|
||||
fromAgent: false
|
||||
};
|
||||
// if (
|
||||
// messageData.mediaType === "video" ||
|
||||
// (messageData.mediaType === "audio" &&
|
||||
// getSettingValue("blockAudioVideoMedia")?.value === "enabled")
|
||||
// ) {
|
||||
// mediaAuthorized = false;
|
||||
// }
|
||||
if (
|
||||
messageData.mediaType === "video" ||
|
||||
(messageData.mediaType === "audio" &&
|
||||
getSettingValue("blockAudioVideoMedia")?.value === "enabled")
|
||||
) {
|
||||
mediaAuthorized = false;
|
||||
}
|
||||
if (msg?.fromMe) {
|
||||
messageData = { ...messageData, fromAgent: true };
|
||||
}
|
||||
|
@ -1248,7 +1257,7 @@ const handleMessage = async (
|
|||
if (msg.type == "chat" && String(msg.body).length > 120) {
|
||||
botSendMessage(
|
||||
ticket,
|
||||
`¡Disculpa, no comprendí!\n\n¡El mensaje tiene más de 120 caracteres!\n\n_Digite 0 para volver al menú principal._`
|
||||
`Desculpe, nao compreendi!\nTexto acima de 120 caracteres!\n _Digite *0* para voltar ao menu principal._`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
@ -1385,14 +1394,14 @@ const handleMessage = async (
|
|||
return;
|
||||
}
|
||||
|
||||
const menuMsg: any = await menu(msg.body, wbot.id, contact.id, ticket);
|
||||
const menuMsg: any = await menu(msg.body, wbot.id, contact.id);
|
||||
|
||||
console.log("menuMsg: ", menuMsg);
|
||||
|
||||
await botSendMessage(
|
||||
ticket,
|
||||
menuMsg.value +
|
||||
"\n\nSi deseas volver al menú principal, escriba *0* o *#* para volver al menú anterior"
|
||||
"\n\nSi desea volver al menú principal, escriba *0* o *#* para volver al menú anterior"
|
||||
);
|
||||
|
||||
if (
|
||||
|
@ -1475,7 +1484,7 @@ const handleMessage = async (
|
|||
},
|
||||
ticketId: ticket.id
|
||||
});
|
||||
const menuMsg: any = await menu(msg.body, wbot.id, contact.id, ticket);
|
||||
const menuMsg: any = await menu(msg.body, wbot.id, contact.id);
|
||||
await botSendMessage(ticket, menuMsg.value);
|
||||
}
|
||||
|
||||
|
@ -1498,7 +1507,7 @@ const handleMessage = async (
|
|||
ticketId: ticket.id
|
||||
});
|
||||
|
||||
const menuMsg: any = await menu(msg.body, wbot.id, contact.id, ticket);
|
||||
const menuMsg: any = await menu(msg.body, wbot.id, contact.id);
|
||||
|
||||
await botSendMessage(ticket, menuMsg.value);
|
||||
|
||||
|
@ -1540,7 +1549,7 @@ const handleMessage = async (
|
|||
};
|
||||
|
||||
async function previousUra(wbot: any, contact: Contact, ticket: any) {
|
||||
const menuMsg: any = await menu("#", wbot.id, contact.id, ticket);
|
||||
const menuMsg: any = await menu("#", wbot.id, contact.id);
|
||||
botSendMessage(ticket, menuMsg.value);
|
||||
}
|
||||
|
||||
|
@ -1593,7 +1602,7 @@ function delForm(ticket: any) {
|
|||
del(`form:${ticket.id}:confirmation`);
|
||||
}
|
||||
|
||||
const menu = async (userTyped: string, whatsappId: any, contactId: any, ticket: any) => {
|
||||
const menu = async (userTyped: string, whatsappId: any, contactId: any) => {
|
||||
let whatsapp = await whatsappCache(whatsappId);
|
||||
|
||||
let lastId = await findObject(
|
||||
|
@ -1615,21 +1624,6 @@ const menu = async (userTyped: string, whatsappId: any, contactId: any, ticket:
|
|||
value: 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(
|
||||
|
@ -1890,13 +1884,10 @@ async function whatsappCache(whatsappId: any) {
|
|||
let whatsapp = await get({ key: "whatsapp:*", parse: true });
|
||||
|
||||
let uraByNumber = await get({ key: "ura_*", parse: true });
|
||||
|
||||
// console.log("------------------------> uraByNumber: ", uraByNumber);
|
||||
|
||||
whatsapp = whatsapp.filter((w: any) => +w?.id == +whatsappId);
|
||||
|
||||
console.log("------------------------> whatsapp: ", whatsapp);
|
||||
|
||||
|
||||
if (whatsapp && whatsapp.length > 0 && uraByNumber) return whatsapp[0];
|
||||
}
|
||||
|
||||
|
@ -2214,13 +2205,6 @@ async function setSoport(ticket: any, wbot: any, contact: any) {
|
|||
})
|
||||
.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 files = "";
|
||||
|
@ -2267,7 +2251,7 @@ async function setSoport(ticket: any, wbot: any, contact: any) {
|
|||
</soapenv:Body>
|
||||
</soapenv:Envelope>`;
|
||||
|
||||
console.log("DATA REQUEST: ", data);
|
||||
// console.log("DATA: ", data);
|
||||
|
||||
// return;
|
||||
var config = {
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 137 KiB |
Binary file not shown.
Before Width: | Height: | Size: 48 KiB |
|
@ -247,7 +247,7 @@ const MessageInput = ({ ticketStatus, ticketLastMessage, ticketIsRemote }) => {
|
|||
setInputMessage(ticketLastMessage)
|
||||
}
|
||||
else {
|
||||
//setInputMessage("")
|
||||
setInputMessage("")
|
||||
}
|
||||
}, [countTicketMsg, ticketIsRemote, ticketLastMessage])
|
||||
|
||||
|
|
|
@ -229,7 +229,7 @@ const TicketListItem = ({ ticket, remoteTicketsControll, settings }) => {
|
|||
variant="body2"
|
||||
color="textPrimary"
|
||||
>
|
||||
{ticket?.contact?.name}
|
||||
{ticket.contact.name}
|
||||
</Typography>
|
||||
{ticket.status === "closed" && (
|
||||
<Badge
|
||||
|
|
Loading…
Reference in New Issue