diff --git a/backend/.gitignore b/backend/.gitignore index 88dd195..e1b1505 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -1,4 +1,4 @@ node_modules -public/* -!public/.gitkeep +/src/public/* +!src/public/.gitkeep .env \ No newline at end of file diff --git a/backend/src/middleware/is-auth.js b/backend/src/middleware/is-auth.js index 1b19142..07d07d6 100644 --- a/backend/src/middleware/is-auth.js +++ b/backend/src/middleware/is-auth.js @@ -14,9 +14,7 @@ module.exports = (req, res, next) => { } if (!decodedToken) { - const error = new Error("Falha na autenticação"); - error.statusCode = 401; - next(error); + return res.status(401).json({ message: "Unauthorized" }); } next(); diff --git a/backend/src/public/1594126363126.ogg b/backend/src/public/1594126363126.ogg deleted file mode 100644 index 00666a7..0000000 Binary files a/backend/src/public/1594126363126.ogg and /dev/null differ diff --git a/backend/src/public/1594127076117-deployeconowhats.txt b/backend/src/public/1594127076117-deployeconowhats.txt deleted file mode 100644 index ece36a4..0000000 --- a/backend/src/public/1594127076117-deployeconowhats.txt +++ /dev/null @@ -1,23 +0,0 @@ ---- vm produção - -MariaDB: root/nodecomplete -MariaDB: botter / 103economicros -dbName: econo_whatsbot - -Libs necessárias para o Puppter no linux: -sudo apt-get install -y libgbm-dev wget unzip fontconfig locales gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils - - --- configuração wsl2 - -https://docs.microsoft.com/pt-br/windows/wsl/wsl2-kernel - -wsl --set-default-version 2 - -docker run --name whats_database -e MYSQL_ROOT_PASSWORD=103economicros --restart always -p 3306:3306 -d mariadb:latest -docker exec -it whats_database bash - -CREATE DATABASE econo_whatsbot; -ALTER DATABASE econo_whatsbot CHARACTER SET utf8mb4 COLLATE utf8mb4_bin; -CREATE USER 'botter'@'%' IDENTIFIED BY 'botter'; -GRANT ALL PRIVILEGES ON econo_whatsbot.* TO 'botter'@'%'; diff --git a/backend/src/public/1594127414478-0e13e25a-9845-4a43-9f0b-53c1e95d6f41.mp3 b/backend/src/public/1594127414478-0e13e25a-9845-4a43-9f0b-53c1e95d6f41.mp3 deleted file mode 100644 index 6f0c0ff..0000000 Binary files a/backend/src/public/1594127414478-0e13e25a-9845-4a43-9f0b-53c1e95d6f41.mp3 and /dev/null differ diff --git a/backend/src/public/1594127502986-0fb575ff-ca6f-47ac-a763-18f8f6cb2203.weba b/backend/src/public/1594127502986-0fb575ff-ca6f-47ac-a763-18f8f6cb2203.weba deleted file mode 100644 index 11e9b0c..0000000 Binary files a/backend/src/public/1594127502986-0fb575ff-ca6f-47ac-a763-18f8f6cb2203.weba and /dev/null differ diff --git a/backend/src/public/1594127543109-0e13e25a-9845-4a43-9f0b-53c1e95d6f41.mp3 b/backend/src/public/1594127543109-0e13e25a-9845-4a43-9f0b-53c1e95d6f41.mp3 deleted file mode 100644 index 6f0c0ff..0000000 Binary files a/backend/src/public/1594127543109-0e13e25a-9845-4a43-9f0b-53c1e95d6f41.mp3 and /dev/null differ diff --git a/backend/src/public/1594127591213-1594126363126.ogg b/backend/src/public/1594127591213-1594126363126.ogg deleted file mode 100644 index 00666a7..0000000 Binary files a/backend/src/public/1594127591213-1594126363126.ogg and /dev/null differ diff --git a/backend/src/public/1594127894843-Untitled1.mp3 b/backend/src/public/1594127894843-Untitled1.mp3 deleted file mode 100644 index 6f2646b..0000000 Binary files a/backend/src/public/1594127894843-Untitled1.mp3 and /dev/null differ diff --git a/backend/src/public/1594128268424-testeeeeee.mp3 b/backend/src/public/1594128268424-testeeeeee.mp3 deleted file mode 100644 index c1423d3..0000000 Binary files a/backend/src/public/1594128268424-testeeeeee.mp3 and /dev/null differ diff --git a/backend/src/public/1594128876147-teste2.wav b/backend/src/public/1594128876147-teste2.wav deleted file mode 100644 index 2d9a21d..0000000 Binary files a/backend/src/public/1594128876147-teste2.wav and /dev/null differ diff --git a/backend/src/public/1594135306752-2f1192ad-95eb-473f-8afa-c0f54458c962.mp3 b/backend/src/public/1594135306752-2f1192ad-95eb-473f-8afa-c0f54458c962.mp3 deleted file mode 100644 index 1bfc225..0000000 Binary files a/backend/src/public/1594135306752-2f1192ad-95eb-473f-8afa-c0f54458c962.mp3 and /dev/null differ diff --git a/backend/src/public/1594209242031-blob b/backend/src/public/1594209242031-blob deleted file mode 100644 index 32d918d..0000000 Binary files a/backend/src/public/1594209242031-blob and /dev/null differ diff --git a/backend/src/public/1594209495148-teste.mp3 b/backend/src/public/1594209495148-teste.mp3 deleted file mode 100644 index 3b5097c..0000000 Binary files a/backend/src/public/1594209495148-teste.mp3 and /dev/null differ diff --git a/backend/src/public/1594209531928-teste.mp3 b/backend/src/public/1594209531928-teste.mp3 deleted file mode 100644 index 36dac9a..0000000 Binary files a/backend/src/public/1594209531928-teste.mp3 and /dev/null differ diff --git a/backend/src/public/1594209575652-teste.mp3 b/backend/src/public/1594209575652-teste.mp3 deleted file mode 100644 index e665406..0000000 Binary files a/backend/src/public/1594209575652-teste.mp3 and /dev/null differ diff --git a/backend/src/public/1594209640061-teste.mp3 b/backend/src/public/1594209640061-teste.mp3 deleted file mode 100644 index 0879c89..0000000 Binary files a/backend/src/public/1594209640061-teste.mp3 and /dev/null differ diff --git a/backend/src/public/1594209651878-teste.mp3 b/backend/src/public/1594209651878-teste.mp3 deleted file mode 100644 index af4802e..0000000 Binary files a/backend/src/public/1594209651878-teste.mp3 and /dev/null differ diff --git a/backend/src/public/1594209685379-teste.mp3 b/backend/src/public/1594209685379-teste.mp3 deleted file mode 100644 index 6547997..0000000 Binary files a/backend/src/public/1594209685379-teste.mp3 and /dev/null differ diff --git a/backend/src/public/1594209825576-1594209825495.mp3 b/backend/src/public/1594209825576-1594209825495.mp3 deleted file mode 100644 index 87b6a7a..0000000 Binary files a/backend/src/public/1594209825576-1594209825495.mp3 and /dev/null differ diff --git a/backend/src/public/1594209876958-blob b/backend/src/public/1594209876958-blob deleted file mode 100644 index 09276ad..0000000 Binary files a/backend/src/public/1594209876958-blob and /dev/null differ diff --git a/backend/src/public/1594209912038-blob b/backend/src/public/1594209912038-blob deleted file mode 100644 index b04d54d..0000000 Binary files a/backend/src/public/1594209912038-blob and /dev/null differ diff --git a/backend/src/public/1594210255048-1594210254935.mp3 b/backend/src/public/1594210255048-1594210254935.mp3 deleted file mode 100644 index 17911cd..0000000 Binary files a/backend/src/public/1594210255048-1594210254935.mp3 and /dev/null differ diff --git a/backend/src/public/1594210385463-1594210385336.mp3 b/backend/src/public/1594210385463-1594210385336.mp3 deleted file mode 100644 index c6eb22b..0000000 Binary files a/backend/src/public/1594210385463-1594210385336.mp3 and /dev/null differ diff --git a/backend/src/public/1594210397628-1594210397504.mp3 b/backend/src/public/1594210397628-1594210397504.mp3 deleted file mode 100644 index f31220f..0000000 Binary files a/backend/src/public/1594210397628-1594210397504.mp3 and /dev/null differ diff --git a/backend/src/public/1594210516393-1594210516262.mp3 b/backend/src/public/1594210516393-1594210516262.mp3 deleted file mode 100644 index ca45d60..0000000 Binary files a/backend/src/public/1594210516393-1594210516262.mp3 and /dev/null differ diff --git a/backend/src/public/1594210517298-1594210517175.mp3 b/backend/src/public/1594210517298-1594210517175.mp3 deleted file mode 100644 index 7acc917..0000000 Binary files a/backend/src/public/1594210517298-1594210517175.mp3 and /dev/null differ diff --git a/backend/src/public/1594210561179-1594210561047.mp3 b/backend/src/public/1594210561179-1594210561047.mp3 deleted file mode 100644 index 502260a..0000000 Binary files a/backend/src/public/1594210561179-1594210561047.mp3 and /dev/null differ diff --git a/backend/src/public/1594210592808-1594210592630.mp3 b/backend/src/public/1594210592808-1594210592630.mp3 deleted file mode 100644 index 1202cf6..0000000 Binary files a/backend/src/public/1594210592808-1594210592630.mp3 and /dev/null differ diff --git a/backend/src/public/1594210622265-1594210621806.mp3 b/backend/src/public/1594210622265-1594210621806.mp3 deleted file mode 100644 index 4343f16..0000000 Binary files a/backend/src/public/1594210622265-1594210621806.mp3 and /dev/null differ diff --git a/backend/src/public/1594210693158-1594210692847.mp3 b/backend/src/public/1594210693158-1594210692847.mp3 deleted file mode 100644 index aebe9eb..0000000 Binary files a/backend/src/public/1594210693158-1594210692847.mp3 and /dev/null differ diff --git a/backend/src/public/1594210753855-1594210753417.mp3 b/backend/src/public/1594210753855-1594210753417.mp3 deleted file mode 100644 index 4e8f5ae..0000000 Binary files a/backend/src/public/1594210753855-1594210753417.mp3 and /dev/null differ diff --git a/backend/src/public/1594210804127-1594210803692.mp3 b/backend/src/public/1594210804127-1594210803692.mp3 deleted file mode 100644 index 028e56f..0000000 Binary files a/backend/src/public/1594210804127-1594210803692.mp3 and /dev/null differ diff --git a/backend/src/public/1594210900328-1594210900137.mp3 b/backend/src/public/1594210900328-1594210900137.mp3 deleted file mode 100644 index b332e45..0000000 Binary files a/backend/src/public/1594210900328-1594210900137.mp3 and /dev/null differ diff --git a/backend/src/public/1594210942862-1594210942716.mp3 b/backend/src/public/1594210942862-1594210942716.mp3 deleted file mode 100644 index 339b733..0000000 Binary files a/backend/src/public/1594210942862-1594210942716.mp3 and /dev/null differ diff --git a/backend/src/public/1594211810591-1594211810395.mp3 b/backend/src/public/1594211810591-1594211810395.mp3 deleted file mode 100644 index ac02974..0000000 Binary files a/backend/src/public/1594211810591-1594211810395.mp3 and /dev/null differ diff --git a/backend/src/public/1594212195029-1594212194768.mp3 b/backend/src/public/1594212195029-1594212194768.mp3 deleted file mode 100644 index 5f9b632..0000000 Binary files a/backend/src/public/1594212195029-1594212194768.mp3 and /dev/null differ diff --git a/backend/src/public/1594212253309-1594212253064.mp3 b/backend/src/public/1594212253309-1594212253064.mp3 deleted file mode 100644 index ba6b004..0000000 Binary files a/backend/src/public/1594212253309-1594212253064.mp3 and /dev/null differ diff --git a/backend/src/public/1594212283618-1594212283365.mp3 b/backend/src/public/1594212283618-1594212283365.mp3 deleted file mode 100644 index 19cd5b1..0000000 Binary files a/backend/src/public/1594212283618-1594212283365.mp3 and /dev/null differ diff --git a/backend/src/public/1594212342578-1594212342312.mp3 b/backend/src/public/1594212342578-1594212342312.mp3 deleted file mode 100644 index 8d58bab..0000000 Binary files a/backend/src/public/1594212342578-1594212342312.mp3 and /dev/null differ diff --git a/backend/src/public/1594212351722-1594212351494.mp3 b/backend/src/public/1594212351722-1594212351494.mp3 deleted file mode 100644 index bfb4f8d..0000000 Binary files a/backend/src/public/1594212351722-1594212351494.mp3 and /dev/null differ diff --git a/backend/src/public/1594212457467-1594212457219.mp3 b/backend/src/public/1594212457467-1594212457219.mp3 deleted file mode 100644 index 5981c83..0000000 Binary files a/backend/src/public/1594212457467-1594212457219.mp3 and /dev/null differ diff --git a/backend/src/routes/contacts.js b/backend/src/routes/contacts.js index d2ba031..ef4719c 100644 --- a/backend/src/routes/contacts.js +++ b/backend/src/routes/contacts.js @@ -6,7 +6,6 @@ const ContactController = require("../controllers/ContactController"); const routes = express.Router(); routes.get("/contacts", isAuth, ContactController.index); -// routes.post(ContactController.postCreateContact); routes.post("/contacts", isAuth, ContactController.store); diff --git a/backend/src/routes/messages.js b/backend/src/routes/messages.js index 564da57..dfb3811 100644 --- a/backend/src/routes/messages.js +++ b/backend/src/routes/messages.js @@ -6,6 +6,7 @@ const MessageController = require("../controllers/MessageController"); const routes = express.Router(); routes.get("/messages/:contactId", isAuth, MessageController.index); + routes.post("/messages/:contactId", isAuth, MessageController.store); module.exports = routes; diff --git a/backend/src/services/wbotMessageListener.js b/backend/src/services/wbotMessageListener.js index b80beab..4fda3a5 100644 --- a/backend/src/services/wbotMessageListener.js +++ b/backend/src/services/wbotMessageListener.js @@ -14,8 +14,7 @@ const wbotMessageListener = () => { wbot.on("message", async msg => { console.log(msg); let newMessage; - // console.log(msg); - if (msg.from === "status@broadcast") { + if (msg.from === "status@broadcast" || msg.type === "location") { return; } try { @@ -28,9 +27,7 @@ const wbotMessageListener = () => { if (contact) { await contact.update({ profilePicUrl: profilePicUrl }); - } - - if (!contact) { + } else { try { contact = await Contact.create({ name: msgContact.pushname || msgContact.number.toString(), @@ -81,24 +78,26 @@ const wbotMessageListener = () => { await contact.update({ lastMessage: msg.body }); } - io.to(contact.id) - .to("notification") - .emit("appMessage", { - action: "create", - message: { - ...newMessage.dataValues, - mediaUrl: `${ - newMessage.mediaUrl - ? `http://${process.env.HOST}:${process.env.PORT}/public/${newMessage.mediaUrl}` - : "" - }`, - }, - contact: { - ...contact.dataValues, - unreadMessages: 1, - lastMessage: newMessage.messageBody, - }, - }); + const serializedMessage = { + ...newMessage.dataValues, + mediaUrl: `${ + newMessage.mediaUrl + ? `http://${process.env.HOST}:${process.env.PORT}/public/${newMessage.mediaUrl}` + : "" + }`, + }; + + const serializaedContact = { + ...contact.dataValues, + unreadMessages: 1, + lastMessage: newMessage.messageBody, + }; + + io.to(contact.id).to("notification").emit("appMessage", { + action: "create", + message: serializedMessage, + contact: serializaedContact, + }); let chat = await msg.getChat(); chat.sendSeen();