Compare commits
No commits in common. "db140a328c36949f996eb6da90551acab5c679ee" and "051e1b3b2a0ee61385f67fd09e70ae9df7910601" have entirely different histories.
db140a328c
...
051e1b3b2a
|
@ -15,9 +15,9 @@ async function omnihitDashboardSession(data: any) {
|
|||
}
|
||||
);
|
||||
} catch (error) {
|
||||
// console.log(
|
||||
// `Post request error to ${process.env.URL_DASHBOARD_SESSIONS}/api/v1/omnihit/monitor`
|
||||
// );
|
||||
console.log(
|
||||
`Post request error to ${process.env.URL_DASHBOARD_SESSIONS}/api/v1/omnihit/monitor`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ type WhatsappData = {
|
|||
value?: string;
|
||||
};
|
||||
|
||||
export async function set(key: string, value: string | object) {
|
||||
export async function set(key: string, value: string) {
|
||||
await redis.set(key, JSON.stringify(value));
|
||||
}
|
||||
|
||||
|
@ -17,20 +17,6 @@ export async function get(key: string) {
|
|||
return JSON.parse(value);
|
||||
}
|
||||
|
||||
export async function findByContain() {
|
||||
// const keys = await redis.keys("*" + substring + "*");
|
||||
const keys = await redis.keys("user:*");
|
||||
|
||||
const results: any[] = [];
|
||||
for (const key of keys) {
|
||||
const value = await redis.get(key);
|
||||
if (value) {
|
||||
results.push(JSON.parse(value));
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
export async function createObject({
|
||||
whatsappId,
|
||||
contactId,
|
||||
|
|
|
@ -23,7 +23,6 @@ import fs from "fs";
|
|||
import dir from "path";
|
||||
import { getSettingValue } from "./helpers/WhaticketSettings";
|
||||
import loadSettings from "./helpers/LoadSettings";
|
||||
import { set } from "./helpers/RedisClient";
|
||||
|
||||
const server = app.listen(process.env.PORT, () => {
|
||||
logger.info(`Server started on port: ${process.env.PORT}`);
|
||||
|
@ -44,13 +43,6 @@ gracefulShutdown(server);
|
|||
(async () => {
|
||||
console.log("os.tmpdir(): ", os.tmpdir());
|
||||
|
||||
const users = await User.findAll();
|
||||
|
||||
for (const user of users) {
|
||||
const { id, name } = user;
|
||||
await set(`user:${id}:${name.toLowerCase()}`, { id, name });
|
||||
}
|
||||
|
||||
loadSettings();
|
||||
|
||||
let whatsapps: any = await Whatsapp.findAll({
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
import { Op, Sequelize } from "sequelize";
|
||||
import Whatsapp from "../../models/Whatsapp";
|
||||
import WhatsappQueue from "../../models/WhatsappQueue";
|
||||
import { List } from "whatsapp-web.js";
|
||||
import UserQueue from "../../models/UserQueue";
|
||||
import Queue from "../../models/Queue";
|
||||
const dbConfig = require("../../config/database");
|
||||
const { QueryTypes } = require("sequelize");
|
||||
|
||||
const sequelize = new Sequelize(dbConfig);
|
||||
|
||||
const ListWhatsappQueuesByUserQueue = async (userId: string | number) => {
|
||||
try {
|
||||
let userQueue: any = await UserQueue.findAll({
|
||||
where: { userId },
|
||||
attributes: ["queueId"],
|
||||
raw: true
|
||||
});
|
||||
|
||||
if (userQueue && userQueue.length > 0) {
|
||||
userQueue = userQueue.map((u: any) => u.queueId);
|
||||
|
||||
const result = await sequelize.query(
|
||||
`select w.id, w.number, wq.whatsappId, wq.queueId, q.id, q.name from WhatsappQueues wq join Queues q on
|
||||
wq.queueId = q.id join Whatsapps w
|
||||
on wq.whatsappId = w.id where q.id in (${userQueue.join()})`,
|
||||
{ type: QueryTypes.SELECT }
|
||||
);
|
||||
return result;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error fetching joined data:", error);
|
||||
}
|
||||
return [];
|
||||
};
|
||||
|
||||
export default ListWhatsappQueuesByUserQueue;
|
|
@ -83,21 +83,14 @@ import AppError from "../../errors/AppError";
|
|||
import { setMessageAsRead } from "../../helpers/SetMessageAsRead";
|
||||
import { getSettingValue } from "../../helpers/WhaticketSettings";
|
||||
|
||||
import { Op, json } from "sequelize";
|
||||
import { Op } from "sequelize";
|
||||
|
||||
import SettingTicket from "../../models/SettingTicket";
|
||||
import mostRepeatedPhrase from "../../helpers/MostRepeatedPhrase";
|
||||
import ListWhatsAppsNumber from "../WhatsappService/ListWhatsAppsNumber";
|
||||
import {
|
||||
createObject,
|
||||
findByContain,
|
||||
findObject,
|
||||
get
|
||||
} from "../../helpers/RedisClient";
|
||||
import FindOrCreateTicketServiceBot from "../TicketServices/FindOrCreateTicketServiceBot";
|
||||
import ShowTicketService from "../TicketServices/ShowTicketService";
|
||||
import ShowQueuesByUser from "../UserServices/ShowQueuesByUser";
|
||||
import ListWhatsappQueuesByUserQueue from "../UserServices/ListWhatsappQueuesByUserQueue";
|
||||
import { createObject, findObject, get } from "../../helpers/RedisClient";
|
||||
import FindOrCreateTicketServiceBot from "../TicketServices/FindOrCreateTicketServiceBot"
|
||||
import ShowTicketService from "../TicketServices/ShowTicketService"
|
||||
|
||||
var lst: any[] = getWhatsappIds();
|
||||
|
||||
|
@ -511,10 +504,13 @@ const transferTicket = async (queueName: any, wbot: any, ticket: Ticket) => {
|
|||
|
||||
const queues = queuesWhatsGreetingMessage.queues;
|
||||
|
||||
// console.log("queues ---> ", console.log(JSON.stringify(queues, null, 6)));
|
||||
|
||||
if (typeof queueName == "string") {
|
||||
queue = queues.find(
|
||||
(q: any) => q?.name?.toLowerCase() == queueName.trim().toLowerCase()
|
||||
);
|
||||
// await deleteObject(wbot.id, `${ticket.contactId}`, "ura");
|
||||
} else if (typeof queueName == "number") {
|
||||
queue = queues[queueName];
|
||||
}
|
||||
|
@ -531,21 +527,6 @@ const botTransferTicket = async (queues: Queue, ticket: Ticket) => {
|
|||
});
|
||||
};
|
||||
|
||||
const botTransferTicketToUser = async (
|
||||
userId: number,
|
||||
ticket: Ticket,
|
||||
queueId?: number | undefined
|
||||
) => {
|
||||
console.log("USER ID: ", userId);
|
||||
|
||||
// await ticket.update({ userId: userId });
|
||||
|
||||
await UpdateTicketService({
|
||||
ticketData: { status: "open", userId, queueId },
|
||||
ticketId: ticket.id
|
||||
});
|
||||
};
|
||||
|
||||
const botSendMessage = (ticket: Ticket, msg: string) => {
|
||||
const { phoneNumberId } = ticket;
|
||||
|
||||
|
@ -717,6 +698,7 @@ const handleMessage = async (
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
if (getSettingValue("oneContactChatWithManyWhats")?.value == "disabled") {
|
||||
// Para responder para o cliente pelo mesmo whatsapp que ele enviou a mensagen
|
||||
if (wbot.id != ticket.whatsappId) {
|
||||
|
@ -802,39 +784,6 @@ const handleMessage = async (
|
|||
return;
|
||||
}
|
||||
|
||||
// Transfer to agent
|
||||
const listUser = await findByContain();
|
||||
|
||||
let filteredUsers = listUser.filter(user =>
|
||||
msg?.body?.trim()?.toLowerCase().includes(user.name)
|
||||
);
|
||||
|
||||
if (filteredUsers && filteredUsers.length > 0) {
|
||||
const whatsappQueues = await ListWhatsappQueuesByUserQueue(
|
||||
+filteredUsers[0].id
|
||||
);
|
||||
|
||||
const obj: any = whatsappQueues.find(
|
||||
(ob: any) => ob.whatsappId == wbot.id
|
||||
);
|
||||
|
||||
if (obj) {
|
||||
await botTransferTicketToUser(
|
||||
+filteredUsers[0].id,
|
||||
ticket,
|
||||
+obj.queueId
|
||||
);
|
||||
|
||||
botSendMessage(
|
||||
ticket,
|
||||
`Você foi transferido para falar com o agente ${filteredUsers[0].name}`
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
//
|
||||
|
||||
const menuMsg: any = await menu(msg.body, wbot.id, contact.id);
|
||||
|
||||
console.log("menuMsg: ", menuMsg);
|
||||
|
|
|
@ -220,7 +220,7 @@ const LoggedInLayout = ({ children }) => {
|
|||
className={classes.title}
|
||||
>
|
||||
|
||||
OMNIHIT
|
||||
OMNIHIT Espaçolaser - Lojas
|
||||
|
||||
</Typography>
|
||||
{user.id && <NotificationsPopOver />}
|
||||
|
|
Loading…
Reference in New Issue