Skip to content

Commit

Permalink
Default messages for finish and outOfHours
Browse files Browse the repository at this point in the history
  • Loading branch information
allgood committed May 16, 2024
1 parent 7775d19 commit 6ceb8dc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
3 changes: 1 addition & 2 deletions backend/src/services/TicketServices/UpdateTicketService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ const UpdateTicketService = async ({
if (setting?.value === "enabled") {
if (ticketTraking.ratingAt == null && !justClose) {


const ratingTxt = ratingMessage || "";
const ratingTxt = ratingMessage?.trim() || "";
let bodyRatingMessage = `\u200e${ratingTxt}\n\n`;
bodyRatingMessage +=
"Digite de 1 à 3 para qualificar nosso atendimento:\n*1* - _Insatisfeito_\n*2* - _Satisfeito_\n*3* - _Muito Satisfeito_\n\n";
Expand Down
24 changes: 13 additions & 11 deletions backend/src/services/WbotServices/wbotMessageListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -838,8 +838,8 @@ const startQueue = async (wbot: Session, ticket: Ticket, queue: Queue) => {
!isNil(currentSchedule) &&
(!currentSchedule || currentSchedule.inActivity === false)
) {

const body = formatBody(`${queue.outOfHoursMessage}\n\n*[ # ]* - Voltar ao Menu Principal`, ticket.contact);
const outOfHoursMessage = queue.outOfHoursMessage.trim() || "Estamos fora do horário de expediente";
const body = formatBody(`${outOfHoursMessage}\n\n*[ # ]* - Voltar ao Menu Principal`, ticket.contact);
const sentMessage = await wbot.sendMessage(
`${contact.number}@${ticket.isGroup ? "g.us" : "s.whatsapp.net"}`, {
text: body,
Expand Down Expand Up @@ -1028,7 +1028,7 @@ export const handleRating = async (
}

if (!Number.isNaN(rate) && Number.isInteger(rate) && !isNull(rate)) {
const { complationMessage } = await ShowWhatsAppService(
const whatsapp = await ShowWhatsAppService(
ticket.whatsappId,
ticket.companyId
);
Expand All @@ -1048,6 +1048,8 @@ export const handleRating = async (
userId: ticketTraking.userId,
rate: finalRate,
});

const complationMessage = whatsapp.complationMessage.trim() || "Atendimento finalizado";
const body = formatBody(`\u200e${complationMessage}`, ticket.contact);
await SendWhatsAppMessage({ body, ticket });

Expand Down Expand Up @@ -1306,7 +1308,9 @@ const handleMessage = async (
order: [["createdAt", "DESC"]],
});

if (unreadMessages === 0 && whatsapp.complationMessage && formatBody(whatsapp.complationMessage, contact).trim().toLowerCase() === lastMessage?.body.trim().toLowerCase()) {
const complationMessage = whatsapp.complationMessage.trim() || "Atendimento finalizado";

if (unreadMessages === 0 && complationMessage && formatBody(complationMessage, contact).trim().toLowerCase() === lastMessage?.body.trim().toLowerCase()) {
return;
}

Expand Down Expand Up @@ -1402,7 +1406,7 @@ const handleMessage = async (
!isNil(currentSchedule) &&
(!currentSchedule || currentSchedule.inActivity === false)
) {
const body = `${whatsapp.outOfHoursMessage}`;
const body = `${whatsapp.outOfHoursMessage.trim() || "Estamos fora do horário de expediente"}`;

const debouncedSentMessage = debounce(
async () => {
Expand Down Expand Up @@ -1448,15 +1452,14 @@ const handleMessage = async (

if (
scheduleType.value === "queue" &&
queue.outOfHoursMessage !== null &&
queue.outOfHoursMessage !== "" &&
!isNil(schedule)
) {
const startTime = moment(schedule.startTime, "HH:mm");
const endTime = moment(schedule.endTime, "HH:mm");

if (now.isBefore(startTime) || now.isAfter(endTime)) {
const body = `${queue.outOfHoursMessage}`;
const outOfHoursMessage = queue.outOfHoursMessage?.trim() || "Estamos fora do horário de expediente";
const body = `${outOfHoursMessage}`;
const debouncedSentMessage = debounce(
async () => {
await wbot.sendMessage(
Expand Down Expand Up @@ -1536,15 +1539,14 @@ const handleMessage = async (

if (
scheduleType.value === "queue" &&
queue.outOfHoursMessage !== null &&
queue.outOfHoursMessage !== "" &&
!isNil(schedule)
) {
const startTime = moment(schedule.startTime, "HH:mm");
const endTime = moment(schedule.endTime, "HH:mm");

if (now.isBefore(startTime) || now.isAfter(endTime)) {
const body = queue.outOfHoursMessage;
const outOfHoursMessage = queue.outOfHoursMessage?.trim() || "Estamos fora do horário de expediente";
const body = outOfHoursMessage;
const debouncedSentMessage = debounce(
async () => {
await wbot.sendMessage(
Expand Down

0 comments on commit 6ceb8dc

Please sign in to comment.