mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 04:39:20 +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 WhatsRoutes = require("./routes/whatsapp");
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
const fileStorage = multer.diskStorage({
|
const fileStorage = multer.diskStorage({
|
||||||
destination: (req, file, cb) => {
|
destination: (req, file, cb) => {
|
||||||
cb(null, path.resolve(__dirname, "..", "public"));
|
cb(null, path.resolve(__dirname, "..", "public"));
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ exports.store = async (req, res, next) => {
|
|||||||
|
|
||||||
if (media) {
|
if (media) {
|
||||||
const newMedia = MessageMedia.fromFilePath(req.file.path);
|
const newMedia = MessageMedia.fromFilePath(req.file.path);
|
||||||
|
|
||||||
message.mediaUrl = req.file.filename.replace(/\s/g, "");
|
message.mediaUrl = req.file.filename.replace(/\s/g, "");
|
||||||
if (newMedia.mimetype) {
|
if (newMedia.mimetype) {
|
||||||
message.mediaType = newMedia.mimetype.split("/")[0];
|
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
|
message.id = sentMessage.id.id;
|
||||||
// THIS SHOULD BE DELETED IN FUTURE VERSION
|
|
||||||
// message.id = sentMessage.id.id;
|
|
||||||
|
|
||||||
// const newMessage = await ticket.createMessage(message);
|
const newMessage = await ticket.createMessage(message);
|
||||||
|
|
||||||
// const serialziedMessage = {
|
const serialziedMessage = {
|
||||||
// ...newMessage.dataValues,
|
...newMessage.dataValues,
|
||||||
// mediaUrl: `${
|
mediaUrl: `${
|
||||||
// message.mediaUrl
|
message.mediaUrl
|
||||||
// ? `http://${process.env.HOST}:${process.env.PORT}/public/${message.mediaUrl}`
|
? `http://${process.env.HOST}:${process.env.PORT}/public/${message.mediaUrl}`
|
||||||
// : ""
|
: ""
|
||||||
// }`,
|
}`,
|
||||||
// };
|
};
|
||||||
|
|
||||||
// io.to(ticketId).emit("appMessage", {
|
io.to(ticketId).emit("appMessage", {
|
||||||
// action: "create",
|
action: "create",
|
||||||
// message: serialziedMessage,
|
message: serialziedMessage,
|
||||||
// });
|
});
|
||||||
|
|
||||||
await setMessagesAsRead(ticketId);
|
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({
|
newMessage = await ticket.createMessage({
|
||||||
id: msg.id.id,
|
id: msg.id.id,
|
||||||
body: msg.body || media.filename,
|
body: msg.body || media.filename,
|
||||||
|
fromMe: msg.fromMe,
|
||||||
mediaUrl: media.filename,
|
mediaUrl: media.filename,
|
||||||
mediaType: media.mimetype.split("/")[0],
|
mediaType: media.mimetype.split("/")[0],
|
||||||
});
|
});
|
||||||
@@ -136,21 +137,14 @@ const wbotMessageListener = () => {
|
|||||||
const wbot = getWbot();
|
const wbot = getWbot();
|
||||||
const io = getIO();
|
const io = getIO();
|
||||||
|
|
||||||
wbot.on("message_create", async msg => {
|
wbot.on("message", async msg => {
|
||||||
// console.log(msg);
|
// console.log(msg);
|
||||||
if (msg.from === "status@broadcast" || msg.type === "location") {
|
if (msg.from === "status@broadcast" || msg.type === "location") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let msgContact;
|
const msgContact = await msg.getContact();
|
||||||
|
|
||||||
if (msg.fromMe) {
|
|
||||||
msgContact = await wbot.getContactById(msg.to);
|
|
||||||
} else {
|
|
||||||
msgContact = await msg.getContact();
|
|
||||||
}
|
|
||||||
|
|
||||||
const profilePicUrl = await msgContact.getProfilePicUrl();
|
const profilePicUrl = await msgContact.getProfilePicUrl();
|
||||||
const contact = await verifyContact(msgContact, profilePicUrl);
|
const contact = await verifyContact(msgContact, profilePicUrl);
|
||||||
const ticket = await verifyTicket(contact);
|
const ticket = await verifyTicket(contact);
|
||||||
|
|||||||
Reference in New Issue
Block a user