mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 03:39:29 +00:00
fix: revert message to ingore msg sent from phone
This commit is contained in:
@@ -17,7 +17,6 @@ const TicketsRoutes = require("./routes/tickets");
|
||||
const WhatsRoutes = require("./routes/whatsapp");
|
||||
|
||||
const app = express();
|
||||
|
||||
const fileStorage = multer.diskStorage({
|
||||
destination: (req, file, cb) => {
|
||||
cb(null, path.resolve(__dirname, "..", "public"));
|
||||
|
||||
@@ -111,6 +111,7 @@ exports.store = async (req, res, next) => {
|
||||
|
||||
if (media) {
|
||||
const newMedia = MessageMedia.fromFilePath(req.file.path);
|
||||
|
||||
message.mediaUrl = req.file.filename.replace(/\s/g, "");
|
||||
if (newMedia.mimetype) {
|
||||
message.mediaType = newMedia.mimetype.split("/")[0];
|
||||
@@ -129,27 +130,25 @@ exports.store = async (req, res, next) => {
|
||||
);
|
||||
}
|
||||
|
||||
// CHANGED MESSAGE CREATION LOGIC TO wbotMessageListener, to handle both send from app and cellphone
|
||||
// THIS SHOULD BE DELETED IN FUTURE VERSION
|
||||
// message.id = sentMessage.id.id;
|
||||
message.id = sentMessage.id.id;
|
||||
|
||||
// const newMessage = await ticket.createMessage(message);
|
||||
const newMessage = await ticket.createMessage(message);
|
||||
|
||||
// const serialziedMessage = {
|
||||
// ...newMessage.dataValues,
|
||||
// mediaUrl: `${
|
||||
// message.mediaUrl
|
||||
// ? `http://${process.env.HOST}:${process.env.PORT}/public/${message.mediaUrl}`
|
||||
// : ""
|
||||
// }`,
|
||||
// };
|
||||
const serialziedMessage = {
|
||||
...newMessage.dataValues,
|
||||
mediaUrl: `${
|
||||
message.mediaUrl
|
||||
? `http://${process.env.HOST}:${process.env.PORT}/public/${message.mediaUrl}`
|
||||
: ""
|
||||
}`,
|
||||
};
|
||||
|
||||
// io.to(ticketId).emit("appMessage", {
|
||||
// action: "create",
|
||||
// message: serialziedMessage,
|
||||
// });
|
||||
io.to(ticketId).emit("appMessage", {
|
||||
action: "create",
|
||||
message: serialziedMessage,
|
||||
});
|
||||
|
||||
await setMessagesAsRead(ticketId);
|
||||
|
||||
return res.json({ message: "Mensagem enviada", ticket });
|
||||
return res.json({ message: "Mensagem enviada", newMessage, ticket });
|
||||
};
|
||||
|
||||
@@ -84,6 +84,7 @@ const handlMedia = async (msg, ticket) => {
|
||||
newMessage = await ticket.createMessage({
|
||||
id: msg.id.id,
|
||||
body: msg.body || media.filename,
|
||||
fromMe: msg.fromMe,
|
||||
mediaUrl: media.filename,
|
||||
mediaType: media.mimetype.split("/")[0],
|
||||
});
|
||||
@@ -136,21 +137,14 @@ const wbotMessageListener = () => {
|
||||
const wbot = getWbot();
|
||||
const io = getIO();
|
||||
|
||||
wbot.on("message_create", async msg => {
|
||||
wbot.on("message", async msg => {
|
||||
// console.log(msg);
|
||||
if (msg.from === "status@broadcast" || msg.type === "location") {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
let msgContact;
|
||||
|
||||
if (msg.fromMe) {
|
||||
msgContact = await wbot.getContactById(msg.to);
|
||||
} else {
|
||||
msgContact = await msg.getContact();
|
||||
}
|
||||
|
||||
const msgContact = await msg.getContact();
|
||||
const profilePicUrl = await msgContact.getProfilePicUrl();
|
||||
const contact = await verifyContact(msgContact, profilePicUrl);
|
||||
const ticket = await verifyTicket(contact);
|
||||
|
||||
Reference in New Issue
Block a user