mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-19 20:29:17 +00:00
Started migration to material-ui
This commit is contained in:
@@ -8,6 +8,7 @@ const sequelize = require("sequelize");
|
||||
const { MessageMedia } = require("whatsapp-web.js");
|
||||
|
||||
const setMessagesAsRead = async contactId => {
|
||||
const io = getIO();
|
||||
try {
|
||||
const result = await Message.update(
|
||||
{ read: true },
|
||||
@@ -26,8 +27,13 @@ const setMessagesAsRead = async contactId => {
|
||||
error.satusCode = 501;
|
||||
throw error;
|
||||
}
|
||||
|
||||
io.to("notification").emit("contact", {
|
||||
action: "updateUnread",
|
||||
contactId: contactId,
|
||||
});
|
||||
} catch (err) {
|
||||
next(err);
|
||||
console.log(err);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -38,6 +44,8 @@ exports.getContactMessages = async (req, res, next) => {
|
||||
const { contactId } = req.params;
|
||||
const { searchParam, pageNumber = 1 } = req.query;
|
||||
|
||||
console.log(req.body, req.query);
|
||||
|
||||
const lowerSerachParam = searchParam.toLowerCase();
|
||||
|
||||
const whereCondition = {
|
||||
@@ -59,7 +67,7 @@ exports.getContactMessages = async (req, res, next) => {
|
||||
throw error;
|
||||
}
|
||||
|
||||
setMessagesAsRead(contactId);
|
||||
await setMessagesAsRead(contactId);
|
||||
|
||||
const messagesFound = await contact.countMessages({
|
||||
where: whereCondition,
|
||||
@@ -71,7 +79,26 @@ exports.getContactMessages = async (req, res, next) => {
|
||||
order: [["createdAt", "DESC"]],
|
||||
});
|
||||
|
||||
return res.json({ messages: contactMessages.reverse(), messagesFound });
|
||||
const serializedMessages = contactMessages.map(message => {
|
||||
return {
|
||||
id: message.id,
|
||||
createdAt: message.createdAt,
|
||||
updatedAt: message.updatedAt,
|
||||
messageBody: message.messageBody,
|
||||
userId: message.userId,
|
||||
ack: message.ack,
|
||||
read: message.read,
|
||||
mediaType: message.mediaType,
|
||||
contactId: message.contactId,
|
||||
mediaUrl: `${
|
||||
message.mediaUrl
|
||||
? `http://localhost:8080/public/${message.mediaUrl}`
|
||||
: ""
|
||||
}`,
|
||||
};
|
||||
});
|
||||
|
||||
return res.json({ messages: serializedMessages.reverse(), messagesFound });
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
@@ -90,7 +117,7 @@ exports.postCreateContactMessage = async (req, res, next) => {
|
||||
const contact = await Contact.findByPk(contactId);
|
||||
if (media) {
|
||||
const newMedia = MessageMedia.fromFilePath(req.file.path);
|
||||
message.mediaUrl = req.file.path;
|
||||
message.mediaUrl = req.file.filename;
|
||||
if (newMedia.mimetype) {
|
||||
message.mediaType = newMedia.mimetype.split("/")[0];
|
||||
} else {
|
||||
@@ -118,6 +145,7 @@ exports.postCreateContactMessage = async (req, res, next) => {
|
||||
action: "create",
|
||||
message: newMessage,
|
||||
});
|
||||
await setMessagesAsRead(contactId);
|
||||
|
||||
return res.json({ message: "Mensagem enviada" });
|
||||
} catch (err) {
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"WABrowserId":"\"W5pw0Llb60mSeV7WOHnk8A==\"","WASecretBundle":"{\"key\":\"alDLbPjonDFzCh5PEPql9cy59LNh1HFG/AZJVoucuYI=\",\"encKey\":\"FQ1MZ2eIH9hKV4dqFoBYTv1/89aopcMAa4CXgh/9csM=\",\"macKey\":\"alDLbPjonDFzCh5PEPql9cy59LNh1HFG/AZJVoucuYI=\"}","WAToken1":"\"fpvmzsdJ0KcZfIl5G4ZTqGxvg474wEfhECz4btE0TDc=\"","WAToken2":"\"1@ueYAfj0uRoSok18uTv8xzCWlvo45N3cefA6tAkUX2iJXP+AQY35sLDxyv1F+q34Ntf9vUcoc4tQG2Q==\""}
|
||||
{"WABrowserId":"\"E9dnt9Mm/JiFDCMJQHkXBw==\"","WASecretBundle":"{\"key\":\"fHTKtoDcxidboASIs5WV5JKyRrF+SfMktqHXmq/KBJU=\",\"encKey\":\"FrM3OnnEbuEr1JrtKypw5CPSc6rSD5bjbOGstv8ijk4=\",\"macKey\":\"fHTKtoDcxidboASIs5WV5JKyRrF+SfMktqHXmq/KBJU=\"}","WAToken1":"\"Q+xBrzEsm9SAVo3hRyKwC3L/kvNfieq45Jt6/pFePbw=\"","WAToken2":"\"1@WlcfjMFEzc0c9JcHHHAK5BfaDDxigchRdN+GrHmVWsix+b7Od5d9Ls21/JC5ojCqbFBwnzQ5zZ/Fbg==\""}
|
||||
@@ -32,8 +32,19 @@ module.exports = {
|
||||
wbot.on("auth_failure", msg => {
|
||||
console.error("AUTHENTICATION FAILURE", msg);
|
||||
});
|
||||
wbot.on("ready", () => {
|
||||
wbot.on("ready", async () => {
|
||||
console.log("READY");
|
||||
// const chats = await wbot.getChats(); // pega as mensagens nao lidas (recebidas quando o bot estava offline)
|
||||
// let unreadMessages; // todo > salvar isso no DB pra mostrar no frontend
|
||||
// for (let chat of chats) {
|
||||
// if (chat.unreadCount > 0) {
|
||||
// unreadMessages = await chat.fetchMessages({
|
||||
// limit: chat.unreadCount,
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
// console.log(unreadMessages);
|
||||
});
|
||||
|
||||
return wbot;
|
||||
|
||||
@@ -61,7 +61,7 @@ const wbotMessageListener = () => {
|
||||
newMessage = await contact.createMessage({
|
||||
id: msg.id.id,
|
||||
messageBody: msg.body || media.filename,
|
||||
mediaUrl: path.join("public", media.filename),
|
||||
mediaUrl: media.filename,
|
||||
mediaType: media.mimetype.split("/")[0],
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@ const Message = sequelize.define("message", {
|
||||
allowNull: false,
|
||||
primaryKey: true,
|
||||
},
|
||||
createdAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE(6),
|
||||
},
|
||||
userId: { type: Sequelize.INTEGER, defaultValue: 0 },
|
||||
ack: { type: Sequelize.INTEGER, defaultValue: 0 },
|
||||
messageBody: { type: Sequelize.STRING(250), allowNull: false },
|
||||
|
||||
24
backend/package-lock.json
generated
24
backend/package-lock.json
generated
@@ -31,9 +31,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "14.0.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.5.tgz",
|
||||
"integrity": "sha512-90hiq6/VqtQgX8Sp0EzeIsv3r+ellbGj4URKj5j30tLlZvRUpnAe9YbYnjl3pJM93GyXU0tghHhvXHq+5rnCKA=="
|
||||
"version": "14.0.11",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.11.tgz",
|
||||
"integrity": "sha512-lCvvI24L21ZVeIiyIUHZ5Oflv1hhHQ5E1S25IRlKIXaRkVgmXpJMI3wUJkmym2bTbCe+WoIibQnMVAU3FguaOg=="
|
||||
},
|
||||
"@types/yauzl": {
|
||||
"version": "2.9.1",
|
||||
@@ -2103,9 +2103,9 @@
|
||||
}
|
||||
},
|
||||
"puppeteer": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-3.1.0.tgz",
|
||||
"integrity": "sha512-jLa9sqdVx0tPnr2FcwAq+8DSjGhSM4YpkwOf3JE22Ycyqm71SW7B5uGfTyMGFoLCmbCozbLZclCjasPb0flTRw==",
|
||||
"version": "3.3.0",
|
||||
"resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-3.3.0.tgz",
|
||||
"integrity": "sha512-23zNqRltZ1PPoK28uRefWJ/zKb5Jhnzbbwbpcna2o5+QMn17F0khq5s1bdH3vPlyj+J36pubccR8wiNA/VE0Vw==",
|
||||
"requires": {
|
||||
"debug": "^4.1.0",
|
||||
"extract-zip": "^2.0.0",
|
||||
@@ -2342,9 +2342,9 @@
|
||||
"integrity": "sha1-1WgS4cAXpuTnw+Ojeh2m143TyT4="
|
||||
},
|
||||
"sequelize": {
|
||||
"version": "5.21.11",
|
||||
"resolved": "https://registry.npmjs.org/sequelize/-/sequelize-5.21.11.tgz",
|
||||
"integrity": "sha512-ZJw3Hp+NS7iHcTz4fHlKvIBm4I7xYibYRCP4HhSyMB26xgqFYFOXTaeWbHD2UUwAFaksTLw5ntzfpA9kE33SVA==",
|
||||
"version": "5.21.12",
|
||||
"resolved": "https://registry.npmjs.org/sequelize/-/sequelize-5.21.12.tgz",
|
||||
"integrity": "sha512-WRTXLoH72HQnlEUbKI1Iev2yS1/epg72Chz0fHqk0MLn4Wj2pH/TS01lpMDGQqxZPXCxRGrwk1YxwUw2C0yI9A==",
|
||||
"requires": {
|
||||
"bluebird": "^3.5.0",
|
||||
"cls-bluebird": "^2.1.0",
|
||||
@@ -2867,9 +2867,9 @@
|
||||
"integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw="
|
||||
},
|
||||
"whatsapp-web.js": {
|
||||
"version": "1.6.0",
|
||||
"resolved": "https://registry.npmjs.org/whatsapp-web.js/-/whatsapp-web.js-1.6.0.tgz",
|
||||
"integrity": "sha512-Lr4KG5nA9u18IBGCSVLxwBT1qlJXtLSA83/0efXobQ5j76fVw2I0sIe8KCcMcFnrTr0IIAnnxEqmXcEKnSiaqg==",
|
||||
"version": "1.6.1",
|
||||
"resolved": "https://registry.npmjs.org/whatsapp-web.js/-/whatsapp-web.js-1.6.1.tgz",
|
||||
"integrity": "sha512-pj0JEIuMsWTlqlNr7vRST9XrS+lj/E4i9B7c00FCzUGu6pbPr+95QrYYY56tH5bpCtpsl2NbIB3fbYe3RlxdkA==",
|
||||
"requires": {
|
||||
"@pedroslopez/moduleraid": "^4.1.0",
|
||||
"jsqr": "^1.3.1",
|
||||
|
||||
@@ -23,10 +23,10 @@
|
||||
"multer": "^1.4.2",
|
||||
"mysql2": "^2.1.0",
|
||||
"qrcode-terminal": "^0.12.0",
|
||||
"sequelize": "^5.21.11",
|
||||
"sequelize": "^5.21.12",
|
||||
"sequelize-cli": "^5.5.1",
|
||||
"socket.io": "^2.3.0",
|
||||
"whatsapp-web.js": "^1.6.0"
|
||||
"whatsapp-web.js": "^1.6.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^2.0.4"
|
||||
|
||||
Reference in New Issue
Block a user