Compare commits
3 Commits
ec6e84f567
...
279c4697dd
Author | SHA1 | Date |
---|---|---|
adriano | 279c4697dd | |
adriano | e020a5f75d | |
adriano | c5c5ddb5a4 |
|
@ -93,9 +93,9 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
|
||||||
|
|
||||||
let queueIds: number[] = [];
|
let queueIds: number[] = [];
|
||||||
|
|
||||||
if (queueIdsStringified) {
|
if (queueIdsStringified && queueIdsStringified.trim().length > 0) {
|
||||||
queueIds = JSON.parse(queueIdsStringified);
|
queueIds = JSON.parse(queueIdsStringified);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { tickets, count, hasMore } = await ListTicketsService({
|
const { tickets, count, hasMore } = await ListTicketsService({
|
||||||
searchParam,
|
searchParam,
|
||||||
|
@ -109,7 +109,7 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
|
||||||
unlimited,
|
unlimited,
|
||||||
searchParamContent
|
searchParamContent
|
||||||
});
|
});
|
||||||
|
|
||||||
return res.status(200).json({ tickets, count, hasMore });
|
return res.status(200).json({ tickets, count, hasMore });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -265,6 +265,10 @@ export const weebhook = async (
|
||||||
});
|
});
|
||||||
|
|
||||||
if (type == "text") {
|
if (type == "text") {
|
||||||
|
if (!message?.text?.body) {
|
||||||
|
return res.status(400).json({ error: "body not found" });
|
||||||
|
}
|
||||||
|
|
||||||
type = "chat";
|
type = "chat";
|
||||||
msg = {
|
msg = {
|
||||||
...msg,
|
...msg,
|
||||||
|
@ -272,6 +276,10 @@ export const weebhook = async (
|
||||||
type
|
type
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
if (!message[message?.type]?.id) {
|
||||||
|
return res.status(400).json({ error: "id not found" });
|
||||||
|
}
|
||||||
|
|
||||||
const mediaId = message[message.type].id;
|
const mediaId = message[message.type].id;
|
||||||
const mimetype = message[message.type].mime_type;
|
const mimetype = message[message.type].mime_type;
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ const GetDefaultWhatsApp = async ({
|
||||||
where: { isDefault: true }
|
where: { isDefault: true }
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!defaultWhatsapp && !ignoreNoWhatsappFound) {
|
if (!defaultWhatsapp) {
|
||||||
if (userId) {
|
if (userId) {
|
||||||
let whatsapps = await wbotByUserQueue({ userId, queueId });
|
let whatsapps = await wbotByUserQueue({ userId, queueId });
|
||||||
|
|
||||||
|
@ -53,13 +53,13 @@ const GetDefaultWhatsApp = async ({
|
||||||
where: { status: "CONNECTED" }
|
where: { status: "CONNECTED" }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
defaultWhatsapp = await Whatsapp.findOne({
|
defaultWhatsapp = await Whatsapp.findOne({
|
||||||
where: { status: "CONNECTED", isOfficial: false }
|
where: { status: "CONNECTED", isOfficial: false }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!defaultWhatsapp && !ignoreNoWhatsappFound) {
|
if (!defaultWhatsapp && !ignoreNoWhatsappFound) {
|
||||||
throw new AppError("ERR_NO_DEF_WAPP_FOUND");
|
throw new AppError("ERR_NO_DEF_WAPP_FOUND");
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,12 +24,16 @@ const CheckIsValidContact = async (
|
||||||
if (data?.isValid) {
|
if (data?.isValid) {
|
||||||
isValidNumber = data;
|
isValidNumber = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!isValidNumber) {
|
let _status: any;
|
||||||
|
|
||||||
const { data } = await axios.post(
|
if (!isValidNumber) {
|
||||||
|
|
||||||
|
console.log('kkkkkkkkkkkkkkkkkkkkkkkkkkkkk ')
|
||||||
|
|
||||||
|
const { data, status } = await axios.post(
|
||||||
`${process.env.WHATS_NUMBER_VALIDATOR_URL}/api/validate`,
|
`${process.env.WHATS_NUMBER_VALIDATOR_URL}/api/validate`,
|
||||||
{ mobile: number },
|
{ mobile: number },
|
||||||
{
|
{
|
||||||
|
@ -40,9 +44,13 @@ const CheckIsValidContact = async (
|
||||||
);
|
);
|
||||||
|
|
||||||
isValidNumber = data;
|
isValidNumber = data;
|
||||||
|
_status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ignoreThrow) return isValidNumber?.number;
|
if (ignoreThrow) return isValidNumber?.number;
|
||||||
|
|
||||||
|
console.log('_status: ', _status)
|
||||||
|
|
||||||
|
if (_status && _status == 422) throw new AppError("ERR_NO_WAPP_FOUND");
|
||||||
|
|
||||||
if (!isValidNumber || (isValidNumber && !isValidNumber.isValid)) {
|
if (!isValidNumber || (isValidNumber && !isValidNumber.isValid)) {
|
||||||
throw new AppError("invalidNumber");
|
throw new AppError("invalidNumber");
|
||||||
|
|
|
@ -98,7 +98,7 @@ import FindOrCreateTicketServiceBot from "../TicketServices/FindOrCreateTicketSe
|
||||||
import ShowTicketService from "../TicketServices/ShowTicketService";
|
import ShowTicketService from "../TicketServices/ShowTicketService";
|
||||||
import ShowQueuesByUser from "../UserServices/ShowQueuesByUser";
|
import ShowQueuesByUser from "../UserServices/ShowQueuesByUser";
|
||||||
import ListWhatsappQueuesByUserQueue from "../UserServices/ListWhatsappQueuesByUserQueue";
|
import ListWhatsappQueuesByUserQueue from "../UserServices/ListWhatsappQueuesByUserQueue";
|
||||||
import CreateContactService from "../ContactServices/CreateContactService"
|
import CreateContactService from "../ContactServices/CreateContactService";
|
||||||
|
|
||||||
var lst: any[] = getWhatsappIds();
|
var lst: any[] = getWhatsappIds();
|
||||||
|
|
||||||
|
@ -318,13 +318,14 @@ const verifyQueue = async (
|
||||||
selectedOption = 1;
|
selectedOption = 1;
|
||||||
choosenQueue = queues[+selectedOption - 1];
|
choosenQueue = queues[+selectedOption - 1];
|
||||||
} else {
|
} else {
|
||||||
selectedOption = msg.body;
|
selectedOption = msg?.body;
|
||||||
|
|
||||||
//////////////// EXTRAIR APENAS O NÚMERO ///////////////////
|
if (selectedOption && selectedOption.trim().length > 0) {
|
||||||
selectedOption = selectedOption.replace(/[^1-9]/g, "");
|
//////////////// EXTRAIR APENAS O NÚMERO ///////////////////
|
||||||
///////////////////////////////////
|
selectedOption = selectedOption.replace(/[^1-9]/g, "");
|
||||||
|
///////////////////////////////////
|
||||||
choosenQueue = queues[+selectedOption - 1];
|
choosenQueue = queues[+selectedOption - 1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (choosenQueue) {
|
if (choosenQueue) {
|
||||||
|
@ -610,7 +611,7 @@ const handleMessage = async (
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isValidMsg(msg)) {
|
if (!isValidMsg(msg)) {
|
||||||
return;
|
return;
|
||||||
|
@ -780,33 +781,33 @@ const handleMessage = async (
|
||||||
await verifyQueue(wbot, msg, ticket, contact);
|
await verifyQueue(wbot, msg, ticket, contact);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg.type === "vcard") {
|
if (msg.type === "vcard") {
|
||||||
try {
|
try {
|
||||||
const array = msg.body.split("\n");
|
const array = msg.body.split("\n");
|
||||||
const obj = [];
|
const obj = [];
|
||||||
let contact = "";
|
let contact = "";
|
||||||
for (let index = 0; index < array.length; index++) {
|
for (let index = 0; index < array.length; index++) {
|
||||||
const v = array[index];
|
const v = array[index];
|
||||||
const values = v.split(":");
|
const values = v.split(":");
|
||||||
for (let ind = 0; ind < values.length; ind++) {
|
for (let ind = 0; ind < values.length; ind++) {
|
||||||
if (values[ind].indexOf("+") !== -1) {
|
if (values[ind].indexOf("+") !== -1) {
|
||||||
obj.push({ number: values[ind] });
|
obj.push({ number: values[ind] });
|
||||||
}
|
}
|
||||||
if (values[ind].indexOf("FN") !== -1) {
|
if (values[ind].indexOf("FN") !== -1) {
|
||||||
contact = values[ind + 1];
|
contact = values[ind + 1];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for await (const ob of obj) {
|
|
||||||
const cont = await CreateContactService({
|
|
||||||
name: contact,
|
|
||||||
number: ob.number.replace(/\D/g, "")
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
}
|
}
|
||||||
|
for await (const ob of obj) {
|
||||||
|
const cont = await CreateContactService({
|
||||||
|
name: contact,
|
||||||
|
number: ob.number.replace(/\D/g, "")
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const botInfo = await BotIsOnQueue("botqueue");
|
const botInfo = await BotIsOnQueue("botqueue");
|
||||||
|
|
||||||
|
@ -820,7 +821,7 @@ const handleMessage = async (
|
||||||
ticket.status == "pending" ||
|
ticket.status == "pending" ||
|
||||||
ticket.status == "queueChoice")
|
ticket.status == "queueChoice")
|
||||||
) {
|
) {
|
||||||
const filteredUsers = await findByContain("user:*", "name", msg?.body);
|
const filteredUsers = await findByContain("user:*", "name", msg?.body);
|
||||||
|
|
||||||
if (filteredUsers && filteredUsers.length > 0) {
|
if (filteredUsers && filteredUsers.length > 0) {
|
||||||
if (botInfo.isOnQueue) {
|
if (botInfo.isOnQueue) {
|
||||||
|
|
|
@ -125,11 +125,11 @@ const ContactModal = ({ open, onClose, contactId, initialValues, onSave }) => {
|
||||||
}
|
}
|
||||||
handleClose()
|
handleClose()
|
||||||
}
|
}
|
||||||
toast.success(i18n.t("contactModal.success"))
|
toast.success(i18n.t("contactModal.success"))
|
||||||
setSaving(false)
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toastError(err)
|
toastError(err)
|
||||||
}
|
}
|
||||||
|
setSaving(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
Loading…
Reference in New Issue