Atualização para a aplicação receber informação do centro de custo para envio da mensagem para o cliente
parent
2d02a69b19
commit
db898bc804
|
@ -1,4 +1,18 @@
|
||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
|
import BotIsOnQueue from "../helpers/BotIsOnQueue";
|
||||||
|
import GetDefaultWhatsApp from "../helpers/GetDefaultWhatsApp";
|
||||||
|
import { getIO } from "../libs/socket";
|
||||||
|
import { getWbot } from "../libs/wbot";
|
||||||
|
import Ticket from "../models/Ticket";
|
||||||
|
import ContactByCustomField from "../services/HitServices/ShowContactByCustomFieldValueService";
|
||||||
|
import ShowQueueService from "../services/QueueService/ShowQueueService";
|
||||||
|
import CreateTicketService from "../services/TicketServices/CreateTicketService";
|
||||||
|
import ShowTicketService from "../services/TicketServices/ShowTicketService";
|
||||||
|
import UpdateTicketService from "../services/TicketServices/UpdateTicketService";
|
||||||
|
import SendWhatsAppMessage from "../services/WbotServices/SendWhatsAppMessage";
|
||||||
|
|
||||||
|
import { Op, where, Sequelize } from "sequelize";
|
||||||
|
import ShowTicketServiceByContactId from "../services/TicketServices/ShowTicketServiceByContactId";
|
||||||
|
|
||||||
|
|
||||||
// type IndexQuery = {
|
// type IndexQuery = {
|
||||||
|
@ -7,20 +21,58 @@ import { Request, Response } from "express";
|
||||||
|
|
||||||
export const hit = async (req: Request, res: Response): Promise<Response> => {
|
export const hit = async (req: Request, res: Response): Promise<Response> => {
|
||||||
|
|
||||||
// const {
|
// const {
|
||||||
// centro_custo,
|
// centro_custo,
|
||||||
// } = req.body as IndexQuery;
|
// } = req.body as IndexQuery;
|
||||||
|
|
||||||
console.log('req.boy: ', req.body)
|
console.log('req.boy: ', req.body)
|
||||||
|
console.log('req.boy: ', req.body['centro_custo'])
|
||||||
|
|
||||||
if (req.headers["auth"] === '0424bd59b807674191e7d77572075f33'){
|
|
||||||
console.log('fffffffffffffffffff')
|
if (req.headers["auth"] === '0424bd59b807674191e7d77572075f33') {
|
||||||
}
|
|
||||||
else{
|
let contact = await ContactByCustomField(req.body['centro_custo'])
|
||||||
res.status(401).json({ "message": "Token Inválido!" });
|
|
||||||
}
|
// console.log('--------------> contact: ', contact)
|
||||||
|
|
||||||
|
if (contact) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
const botInfo = await BotIsOnQueue('botqueue')
|
||||||
|
|
||||||
|
let ticket = await ShowTicketServiceByContactId(contact['contact.id'])
|
||||||
|
|
||||||
|
if (ticket.id && ticket.status == 'pending') {
|
||||||
|
|
||||||
|
await SendWhatsAppMessage({ body: 'Resposta da operadora', ticket });
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (!ticket.id) {
|
||||||
|
|
||||||
|
ticket = await CreateTicketService({ contactId: contact['contact.id'], status: 'open', userId: botInfo.userIdBot });
|
||||||
|
|
||||||
|
console.log('botInfo.botQueueId: ', botInfo.botQueueId)
|
||||||
|
|
||||||
|
await UpdateTicketService({ ticketData: { queueId: botInfo.botQueueId }, ticketId: ticket.id });
|
||||||
|
|
||||||
|
await SendWhatsAppMessage({ body: 'Ola isso é um teste', ticket });
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
|
||||||
|
console.log(`Error on try sending the message monitor: `, error)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res.status(401).json({ "message": "Token Inválido!" });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return res.status(200).json({ "message": "Ok" });
|
return res.status(200).json({ "message": "Ok" });
|
||||||
};
|
};
|
|
@ -91,9 +91,8 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
|
||||||
|
|
||||||
export const store = async (req: Request, res: Response): Promise<Response> => {
|
export const store = async (req: Request, res: Response): Promise<Response> => {
|
||||||
const { contactId, status, userId }: TicketData = req.body;
|
const { contactId, status, userId }: TicketData = req.body;
|
||||||
|
|
||||||
|
|
||||||
// test del
|
|
||||||
let ticket = await Ticket.findOne({ where: { contactId, status: 'queueChoice' } });
|
let ticket = await Ticket.findOne({ where: { contactId, status: 'queueChoice' } });
|
||||||
|
|
||||||
if (ticket) {
|
if (ticket) {
|
||||||
|
@ -108,8 +107,7 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
|
||||||
io.to(ticket.status).emit("ticket", {
|
io.to(ticket.status).emit("ticket", {
|
||||||
action: "update",
|
action: "update",
|
||||||
ticket
|
ticket
|
||||||
});
|
});
|
||||||
//
|
|
||||||
|
|
||||||
|
|
||||||
// const ticket = await CreateTicketService({ contactId, status, userId });
|
// const ticket = await CreateTicketService({ contactId, status, userId });
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
|
||||||
|
import Contact from "../../models/Contact";
|
||||||
|
import ContactCustomField from "../../models/ContactCustomField";
|
||||||
|
|
||||||
|
const ContactByCustomField = async (value: string | number): Promise<any> => {
|
||||||
|
|
||||||
|
const contact = await ContactCustomField.findOne({
|
||||||
|
where: { value },
|
||||||
|
raw: true,
|
||||||
|
attributes: ['id', 'value', 'contactId'],
|
||||||
|
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
model: Contact,
|
||||||
|
required: true,
|
||||||
|
attributes: ['id', 'name', 'number'],
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
return contact;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ContactByCustomField;
|
|
@ -15,9 +15,7 @@ const dateToday = splitDateTime(new Date(format(new Date(), 'yyyy-MM-dd HH:mm:ss
|
||||||
|
|
||||||
import ListTicketServiceCache from "./ListTicketServiceCache"
|
import ListTicketServiceCache from "./ListTicketServiceCache"
|
||||||
|
|
||||||
import { searchTicketCache, loadTicketsCache } from '../../helpers/TicketCache'
|
import { searchTicketCache, loadTicketsCache } from '../../helpers/TicketCache'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
interface Request {
|
interface Request {
|
||||||
|
@ -60,6 +58,9 @@ const ListTicketsService = async ({
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (searchParam && searchParam.trim().length > 0 && process.env.CACHE) {
|
if (searchParam && searchParam.trim().length > 0 && process.env.CACHE) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
import Ticket from "../../models/Ticket";
|
||||||
|
import AppError from "../../errors/AppError";
|
||||||
|
import Contact from "../../models/Contact";
|
||||||
|
import User from "../../models/User";
|
||||||
|
import Queue from "../../models/Queue";
|
||||||
|
|
||||||
|
import { Op } from "sequelize";
|
||||||
|
|
||||||
|
const ShowTicketServiceByContactId = async (contactId: string | number): Promise<Ticket> => {
|
||||||
|
|
||||||
|
const ticket = await Ticket.findOne({
|
||||||
|
|
||||||
|
where:{ contactId: contactId, [Op.or]: [ { status: 'open' }, { status: 'pending' }] },
|
||||||
|
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
model: Contact,
|
||||||
|
as: "contact",
|
||||||
|
attributes: ["id", "name", "number", "profilePicUrl", "useDialogflow", "useQueues"],
|
||||||
|
include: ["extraInfo"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
model: User,
|
||||||
|
as: "user",
|
||||||
|
attributes: ["id", "name"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
model: Queue,
|
||||||
|
as: "queue",
|
||||||
|
attributes: ["id", "name", "color"],
|
||||||
|
include: ["dialogflow"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!ticket) {
|
||||||
|
|
||||||
|
return new Ticket
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return ticket;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ShowTicketServiceByContactId;
|
|
@ -12,7 +12,7 @@ const CheckIsValidContact = async (number: string): Promise<void> => {
|
||||||
if (!isValidNumber) {
|
if (!isValidNumber) {
|
||||||
throw new AppError("invalidNumber");
|
throw new AppError("invalidNumber");
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err:any) {
|
||||||
if (err.message === "invalidNumber") {
|
if (err.message === "invalidNumber") {
|
||||||
throw new AppError("ERR_WAPP_INVALID_CONTACT");
|
throw new AppError("ERR_WAPP_INVALID_CONTACT");
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ const SendWhatsAppMessage = async ({
|
||||||
var timetaken = `########################################${timestamp}| TicketId: ${ticket.id} => Time taken to send the message`;
|
var timetaken = `########################################${timestamp}| TicketId: ${ticket.id} => Time taken to send the message`;
|
||||||
|
|
||||||
|
|
||||||
console.time(timetaken)
|
console.time(timetaken)
|
||||||
|
|
||||||
|
|
||||||
let quotedMsgSerializedId: string | undefined;
|
let quotedMsgSerializedId: string | undefined;
|
||||||
|
|
Loading…
Reference in New Issue