Skip to content

Commit

Permalink
Mensagem automática de transferência de setor
Browse files Browse the repository at this point in the history
  • Loading branch information
rtenorioh authored Mar 20, 2022
1 parent 576c1c0 commit e6c1dce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
22 changes: 16 additions & 6 deletions backend/src/controllers/TicketController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ShowTicketService from "../services/TicketServices/ShowTicketService";
import UpdateTicketService from "../services/TicketServices/UpdateTicketService";
import SendWhatsAppMessage from "../services/WbotServices/SendWhatsAppMessage";
import ShowWhatsAppService from "../services/WhatsappService/ShowWhatsAppService";
import ShowQueueService from "../services/QueueService/ShowQueueService";
import formatBody from "../helpers/Mustache";

type IndexQuery = {
Expand All @@ -25,6 +26,7 @@ interface TicketData {
status: string;
queueId: number;
userId: number;
transf: boolean;
}

export const index = async (req: Request, res: Response): Promise<Response> => {
Expand All @@ -35,7 +37,7 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
searchParam,
showAll,
queueIds: queueIdsStringified,
withUnreadMessages
withUnreadMessages,
} = req.query as IndexQuery;

const userId = req.user.id;
Expand All @@ -54,7 +56,7 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
showAll,
userId,
queueIds,
withUnreadMessages
withUnreadMessages,
});

return res.status(200).json({ tickets, count, hasMore });
Expand All @@ -68,7 +70,7 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
const io = getIO();
io.to(ticket.status).emit("ticket", {
action: "update",
ticket
ticket,
});

return res.status(200).json(ticket);
Expand All @@ -91,9 +93,17 @@ export const update = async (

const { ticket } = await UpdateTicketService({
ticketData,
ticketId
ticketId,
});

if (ticketData.transf) {
const { greetingMessage } = await ShowQueueService(ticketData.queueId);
if (greetingMessage) {
const msgtxt = "*Mensagem Automática:* \n" + greetingMessage;
await SendWhatsAppMessage({ body: msgtxt, ticket });
}
}

if (ticket.status === "closed") {
const whatsapp = await ShowWhatsAppService(ticket.whatsappId);

Expand All @@ -102,7 +112,7 @@ export const update = async (
if (farewellMessage) {
await SendWhatsAppMessage({
body: formatBody(farewellMessage, ticket.contact),
ticket
ticket,
});
}
}
Expand All @@ -124,7 +134,7 @@ export const remove = async (
.to("notification")
.emit("ticket", {
action: "delete",
ticketId: +ticketId
ticketId: +ticketId,
});

return res.status(200).json({ message: "ticket deleted" });
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/TransferTicketModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ const TransferTicketModal = ({ modalOpen, onClose, ticketid }) => {
if (!selectedUser) {
data.status = 'pending';
data.userId = null;
data.transf = true;
}
}

Expand Down

0 comments on commit e6c1dce

Please sign in to comment.