mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 19:59:20 +00:00
Merge branch 'master' into master
This commit is contained in:
@@ -4,6 +4,8 @@ import AppError from "../../errors/AppError";
|
||||
import GetTicketWbot from "../../helpers/GetTicketWbot";
|
||||
import Ticket from "../../models/Ticket";
|
||||
|
||||
import formatBody from "../../helpers/Mustache";
|
||||
|
||||
interface Request {
|
||||
media: Express.Multer.File;
|
||||
ticket: Ticket;
|
||||
@@ -23,7 +25,7 @@ const SendWhatsAppMedia = async ({
|
||||
`${ticket.contact.number}@${ticket.isGroup ? "g" : "c"}.us`,
|
||||
newMedia,
|
||||
{
|
||||
caption: body,
|
||||
caption: formatBody(body as string, ticket.contact),
|
||||
sendAudioAsVoice: true
|
||||
}
|
||||
);
|
||||
|
||||
@@ -6,6 +6,8 @@ import SerializeWbotMsgId from "../../helpers/SerializeWbotMsgId";
|
||||
import Message from "../../models/Message";
|
||||
import Ticket from "../../models/Ticket";
|
||||
|
||||
import formatBody from "../../helpers/Mustache";
|
||||
|
||||
interface Request {
|
||||
body: string;
|
||||
ticket: Ticket;
|
||||
@@ -28,7 +30,7 @@ const SendWhatsAppMessage = async ({
|
||||
try {
|
||||
const sentMessage = await wbot.sendMessage(
|
||||
`${ticket.contact.number}@${ticket.isGroup ? "g" : "c"}.us`,
|
||||
body,
|
||||
formatBody(body, ticket.contact),
|
||||
{
|
||||
quotedMessageId: quotedMsgSerializedId,
|
||||
linkPreview: false
|
||||
|
||||
@@ -3,7 +3,7 @@ import { promisify } from "util";
|
||||
import { writeFile } from "fs";
|
||||
import * as Sentry from "@sentry/node";
|
||||
|
||||
import WAWebJS, {
|
||||
import {
|
||||
Contact as WbotContact,
|
||||
Message as WbotMessage,
|
||||
MessageAck,
|
||||
@@ -24,6 +24,7 @@ import { debounce } from "../../helpers/Debounce";
|
||||
import UpdateTicketService from "../TicketServices/UpdateTicketService";
|
||||
import CreateContactService from "../ContactServices/CreateContactService";
|
||||
import GetContactService from "../ContactServices/GetContactService";
|
||||
import formatBody from "../../helpers/Mustache";
|
||||
|
||||
interface Session extends Client {
|
||||
id?: number;
|
||||
@@ -172,7 +173,7 @@ const verifyQueue = async (
|
||||
ticketId: ticket.id
|
||||
});
|
||||
|
||||
const body = `\u200e${choosenQueue.greetingMessage}`;
|
||||
const body = formatBody(`\u200e${choosenQueue.greetingMessage}`, contact);
|
||||
|
||||
const sentMessage = await wbot.sendMessage(`${contact.number}@c.us`, body);
|
||||
|
||||
@@ -184,7 +185,7 @@ const verifyQueue = async (
|
||||
options += `*${index + 1}* - ${queue.name}\n`;
|
||||
});
|
||||
|
||||
const body = `\u200e${greetingMessage}\n${options}`;
|
||||
const body = formatBody(`\u200e${greetingMessage}\n${options}`, contact);
|
||||
|
||||
const debouncedSentMessage = debounce(
|
||||
async () => {
|
||||
@@ -251,7 +252,6 @@ const handleMessage = async (
|
||||
|
||||
const chat = await msg.getChat();
|
||||
|
||||
|
||||
if (chat.isGroup) {
|
||||
let msgGroupContact;
|
||||
|
||||
@@ -269,7 +269,12 @@ const handleMessage = async (
|
||||
|
||||
const contact = await verifyContact(msgContact);
|
||||
|
||||
if (unreadMessages === 0 && whatsapp.farewellMessage && whatsapp.farewellMessage === msg.body) return;
|
||||
if (
|
||||
unreadMessages === 0 &&
|
||||
whatsapp.farewellMessage &&
|
||||
formatBody(whatsapp.farewellMessage, contact) === msg.body
|
||||
)
|
||||
return;
|
||||
|
||||
const ticket = await FindOrCreateTicketService(
|
||||
contact,
|
||||
@@ -294,9 +299,35 @@ const handleMessage = async (
|
||||
await verifyQueue(wbot, msg, ticket, contact);
|
||||
}
|
||||
|
||||
if (msg.type === "vcard") { try { const array = msg.body.split("\n"); const obj = []; let contact = ""; for (let index = 0; index < array.length; index++) { const v = array[index]; const values = v.split(":"); for (let ind = 0; ind < values.length; ind++) { if (values[ind].indexOf("+") !== -1) { obj.push({ number: values[ind] }); } if (values[ind].indexOf("FN") !== -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); } }
|
||||
if (msg.type === "vcard") {
|
||||
try {
|
||||
const array = msg.body.split("\n");
|
||||
const obj = [];
|
||||
let contact = "";
|
||||
for (let index = 0; index < array.length; index++) {
|
||||
const v = array[index];
|
||||
const values = v.split(":");
|
||||
for (let ind = 0; ind < values.length; ind++) {
|
||||
if (values[ind].indexOf("+") !== -1) {
|
||||
obj.push({ number: values[ind] });
|
||||
}
|
||||
if (values[ind].indexOf("FN") !== -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);
|
||||
}
|
||||
}
|
||||
|
||||
/*if (msg.type === "multi_vcard") {
|
||||
/* if (msg.type === "multi_vcard") {
|
||||
try {
|
||||
const array = msg.vCards.toString().split("\n");
|
||||
let name = "";
|
||||
@@ -355,8 +386,7 @@ const handleMessage = async (
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}*/
|
||||
|
||||
} */
|
||||
} catch (err) {
|
||||
Sentry.captureException(err);
|
||||
logger.error(`Error handling whatsapp message: Err: ${err}`);
|
||||
|
||||
Reference in New Issue
Block a user