mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-21 05:09:18 +00:00
Backend folders organize and finshed send audio
This commit is contained in:
@@ -7,9 +7,9 @@ const cors = require("cors");
|
|||||||
const sequelize = require("./database/");
|
const sequelize = require("./database/");
|
||||||
const multer = require("multer");
|
const multer = require("multer");
|
||||||
|
|
||||||
const wBot = require("./controllers/wbot");
|
const wBot = require("./libs/wbot");
|
||||||
const wbotMessageListener = require("./controllers/wbotMessageListener");
|
const wbotMessageListener = require("./services/wbotMessageListener");
|
||||||
const wbotMonitor = require("./controllers/wbotMonitor");
|
const wbotMonitor = require("./services/wbotMonitor");
|
||||||
|
|
||||||
const messageRoutes = require("./routes/message");
|
const messageRoutes = require("./routes/message");
|
||||||
const ContactRoutes = require("./routes/contacts");
|
const ContactRoutes = require("./routes/contacts");
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ const Contact = require("../models/Contact");
|
|||||||
const Message = require("../models/Message");
|
const Message = require("../models/Message");
|
||||||
const Sequelize = require("sequelize");
|
const Sequelize = require("sequelize");
|
||||||
const { getIO } = require("../libs/socket");
|
const { getIO } = require("../libs/socket");
|
||||||
const { getWbot } = require("./wbot");
|
const { getWbot } = require("../libs/wbot");
|
||||||
|
|
||||||
exports.getContacts = async (req, res) => {
|
exports.getContacts = async (req, res) => {
|
||||||
const { searchParam = "" } = req.query;
|
const { searchParam = "" } = req.query;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ const fs = require("fs");
|
|||||||
const Message = require("../models/Message");
|
const Message = require("../models/Message");
|
||||||
const Contact = require("../models/Contact");
|
const Contact = require("../models/Contact");
|
||||||
const { getIO } = require("../libs/socket");
|
const { getIO } = require("../libs/socket");
|
||||||
const { getWbot } = require("./wbot");
|
const { getWbot } = require("../libs/wbot");
|
||||||
const Sequelize = require("sequelize");
|
const Sequelize = require("sequelize");
|
||||||
|
|
||||||
const { MessageMedia } = require("whatsapp-web.js");
|
const { MessageMedia } = require("whatsapp-web.js");
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const Whatsapp = require("../models/Whatsapp");
|
const Whatsapp = require("../models/Whatsapp");
|
||||||
const { getIO } = require("../libs/socket");
|
const { getIO } = require("../libs/socket");
|
||||||
const { getWbot, init } = require("./wbot");
|
const { getWbot, init } = require("../libs/wbot");
|
||||||
|
|
||||||
exports.getSession = async (req, res, next) => {
|
exports.getSession = async (req, res, next) => {
|
||||||
const dbSession = await Whatsapp.findOne({ where: { id: 1 } });
|
const dbSession = await Whatsapp.findOne({ where: { id: 1 } });
|
||||||
|
|||||||
BIN
backend/src/public/1594209242031-blob
Normal file
BIN
backend/src/public/1594209242031-blob
Normal file
Binary file not shown.
BIN
backend/src/public/1594209495148-teste.mp3
Normal file
BIN
backend/src/public/1594209495148-teste.mp3
Normal file
Binary file not shown.
BIN
backend/src/public/1594209531928-teste.mp3
Normal file
BIN
backend/src/public/1594209531928-teste.mp3
Normal file
Binary file not shown.
BIN
backend/src/public/1594209575652-teste.mp3
Normal file
BIN
backend/src/public/1594209575652-teste.mp3
Normal file
Binary file not shown.
BIN
backend/src/public/1594209640061-teste.mp3
Normal file
BIN
backend/src/public/1594209640061-teste.mp3
Normal file
Binary file not shown.
BIN
backend/src/public/1594209651878-teste.mp3
Normal file
BIN
backend/src/public/1594209651878-teste.mp3
Normal file
Binary file not shown.
BIN
backend/src/public/1594209685379-teste.mp3
Normal file
BIN
backend/src/public/1594209685379-teste.mp3
Normal file
Binary file not shown.
BIN
backend/src/public/1594209825576-1594209825495.mp3
Normal file
BIN
backend/src/public/1594209825576-1594209825495.mp3
Normal file
Binary file not shown.
BIN
backend/src/public/1594209876958-blob
Normal file
BIN
backend/src/public/1594209876958-blob
Normal file
Binary file not shown.
BIN
backend/src/public/1594209912038-blob
Normal file
BIN
backend/src/public/1594209912038-blob
Normal file
Binary file not shown.
BIN
backend/src/public/1594210255048-1594210254935.mp3
Normal file
BIN
backend/src/public/1594210255048-1594210254935.mp3
Normal file
Binary file not shown.
BIN
backend/src/public/1594210385463-1594210385336.mp3
Normal file
BIN
backend/src/public/1594210385463-1594210385336.mp3
Normal file
Binary file not shown.
BIN
backend/src/public/1594210397628-1594210397504.mp3
Normal file
BIN
backend/src/public/1594210397628-1594210397504.mp3
Normal file
Binary file not shown.
BIN
backend/src/public/1594210516393-1594210516262.mp3
Normal file
BIN
backend/src/public/1594210516393-1594210516262.mp3
Normal file
Binary file not shown.
BIN
backend/src/public/1594210517298-1594210517175.mp3
Normal file
BIN
backend/src/public/1594210517298-1594210517175.mp3
Normal file
Binary file not shown.
BIN
backend/src/public/1594210561179-1594210561047.mp3
Normal file
BIN
backend/src/public/1594210561179-1594210561047.mp3
Normal file
Binary file not shown.
BIN
backend/src/public/1594210592808-1594210592630.mp3
Normal file
BIN
backend/src/public/1594210592808-1594210592630.mp3
Normal file
Binary file not shown.
BIN
backend/src/public/1594210622265-1594210621806.mp3
Normal file
BIN
backend/src/public/1594210622265-1594210621806.mp3
Normal file
Binary file not shown.
BIN
backend/src/public/1594210693158-1594210692847.mp3
Normal file
BIN
backend/src/public/1594210693158-1594210692847.mp3
Normal file
Binary file not shown.
BIN
backend/src/public/1594210753855-1594210753417.mp3
Normal file
BIN
backend/src/public/1594210753855-1594210753417.mp3
Normal file
Binary file not shown.
BIN
backend/src/public/1594210804127-1594210803692.mp3
Normal file
BIN
backend/src/public/1594210804127-1594210803692.mp3
Normal file
Binary file not shown.
BIN
backend/src/public/1594210900328-1594210900137.mp3
Normal file
BIN
backend/src/public/1594210900328-1594210900137.mp3
Normal file
Binary file not shown.
BIN
backend/src/public/1594210942862-1594210942716.mp3
Normal file
BIN
backend/src/public/1594210942862-1594210942716.mp3
Normal file
Binary file not shown.
BIN
backend/src/public/1594211810591-1594211810395.mp3
Normal file
BIN
backend/src/public/1594211810591-1594211810395.mp3
Normal file
Binary file not shown.
BIN
backend/src/public/1594212195029-1594212194768.mp3
Normal file
BIN
backend/src/public/1594212195029-1594212194768.mp3
Normal file
Binary file not shown.
BIN
backend/src/public/1594212253309-1594212253064.mp3
Normal file
BIN
backend/src/public/1594212253309-1594212253064.mp3
Normal file
Binary file not shown.
BIN
backend/src/public/1594212283618-1594212283365.mp3
Normal file
BIN
backend/src/public/1594212283618-1594212283365.mp3
Normal file
Binary file not shown.
BIN
backend/src/public/1594212342578-1594212342312.mp3
Normal file
BIN
backend/src/public/1594212342578-1594212342312.mp3
Normal file
Binary file not shown.
BIN
backend/src/public/1594212351722-1594212351494.mp3
Normal file
BIN
backend/src/public/1594212351722-1594212351494.mp3
Normal file
Binary file not shown.
BIN
backend/src/public/1594212457467-1594212457219.mp3
Normal file
BIN
backend/src/public/1594212457467-1594212457219.mp3
Normal file
Binary file not shown.
@@ -5,7 +5,7 @@ const path = require("path");
|
|||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
|
||||||
const { getIO } = require("../libs/socket");
|
const { getIO } = require("../libs/socket");
|
||||||
const { getWbot, init } = require("./wbot");
|
const { getWbot, init } = require("../libs/wbot");
|
||||||
|
|
||||||
const wbotMessageListener = () => {
|
const wbotMessageListener = () => {
|
||||||
const io = getIO();
|
const io = getIO();
|
||||||
@@ -2,7 +2,7 @@ const Whatsapp = require("../models/Whatsapp");
|
|||||||
const wbotMessageListener = require("./wbotMessageListener");
|
const wbotMessageListener = require("./wbotMessageListener");
|
||||||
|
|
||||||
const { getIO } = require("../libs/socket");
|
const { getIO } = require("../libs/socket");
|
||||||
const { getWbot, init } = require("./wbot");
|
const { getWbot, init } = require("../libs/wbot");
|
||||||
|
|
||||||
const wbotMonitor = () => {
|
const wbotMonitor = () => {
|
||||||
const io = getIO();
|
const io = getIO();
|
||||||
@@ -80,6 +80,11 @@ const useStyles = makeStyles(theme => ({
|
|||||||
marginLeft: -12,
|
marginLeft: -12,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
audioLoading: {
|
||||||
|
color: green[500],
|
||||||
|
opacity: "70%",
|
||||||
|
},
|
||||||
|
|
||||||
recorderWrapper: {
|
recorderWrapper: {
|
||||||
display: "flex",
|
display: "flex",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
@@ -108,7 +113,6 @@ const MessagesInput = ({ searchParam }) => {
|
|||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
const [recording, setRecording] = useState(false);
|
const [recording, setRecording] = useState(false);
|
||||||
const [blobURL, setBlobURL] = useState("");
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
@@ -167,6 +171,7 @@ const MessagesInput = ({ searchParam }) => {
|
|||||||
|
|
||||||
const handleSendMessage = async () => {
|
const handleSendMessage = async () => {
|
||||||
if (inputMessage.trim() === "") return;
|
if (inputMessage.trim() === "") return;
|
||||||
|
setLoading(true);
|
||||||
const message = {
|
const message = {
|
||||||
read: 1,
|
read: 1,
|
||||||
userId: userId,
|
userId: userId,
|
||||||
@@ -180,9 +185,10 @@ const MessagesInput = ({ searchParam }) => {
|
|||||||
}
|
}
|
||||||
setInputMessage("");
|
setInputMessage("");
|
||||||
setShowEmoji(false);
|
setShowEmoji(false);
|
||||||
|
setLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const startRecording = () => {
|
const handleStartRecording = () => {
|
||||||
navigator.getUserMedia(
|
navigator.getUserMedia(
|
||||||
{ audio: true },
|
{ audio: true },
|
||||||
() => {
|
() => {
|
||||||
@@ -198,17 +204,40 @@ const MessagesInput = ({ searchParam }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const stopRecording = () => {
|
const handleUploadAudio = () => {
|
||||||
|
setLoading(true);
|
||||||
Mp3Recorder.stop()
|
Mp3Recorder.stop()
|
||||||
.getMp3()
|
.getMp3()
|
||||||
.then(([buffer, blob]) => {
|
.then(async ([buffer, blob]) => {
|
||||||
const blobURL = URL.createObjectURL(blob);
|
if (blob.size < 10000) {
|
||||||
setBlobURL(blobURL);
|
setLoading(false);
|
||||||
|
setRecording(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const formData = new FormData();
|
||||||
|
const filename = `${new Date().getTime()}.mp3`;
|
||||||
|
console.log(blob);
|
||||||
|
formData.append("media", blob, filename);
|
||||||
|
formData.append("messageBody", filename);
|
||||||
|
formData.append("userId", userId);
|
||||||
|
try {
|
||||||
|
await api.post(`/messages/${contactId}`, formData);
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
alert(err);
|
||||||
|
}
|
||||||
setRecording(false);
|
setRecording(false);
|
||||||
|
setLoading(false);
|
||||||
})
|
})
|
||||||
.catch(e => console.log(e));
|
.catch(e => console.log(e));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleCancelAudio = () => {
|
||||||
|
Mp3Recorder.stop()
|
||||||
|
.getMp3()
|
||||||
|
.then(() => setRecording(false));
|
||||||
|
};
|
||||||
|
|
||||||
if (media.preview)
|
if (media.preview)
|
||||||
return (
|
return (
|
||||||
<Paper
|
<Paper
|
||||||
@@ -246,10 +275,10 @@ const MessagesInput = ({ searchParam }) => {
|
|||||||
else {
|
else {
|
||||||
return (
|
return (
|
||||||
<Paper variant="outlined" square className={classes.newMessageBox}>
|
<Paper variant="outlined" square className={classes.newMessageBox}>
|
||||||
<audio src={blobURL} controls="controls" />
|
|
||||||
<IconButton
|
<IconButton
|
||||||
aria-label="emojiPicker"
|
aria-label="emojiPicker"
|
||||||
component="span"
|
component="span"
|
||||||
|
disabled={loading}
|
||||||
onClick={e => setShowEmoji(prevState => !prevState)}
|
onClick={e => setShowEmoji(prevState => !prevState)}
|
||||||
>
|
>
|
||||||
<MoodIcon className={classes.sendMessageIcons} />
|
<MoodIcon className={classes.sendMessageIcons} />
|
||||||
@@ -272,7 +301,7 @@ const MessagesInput = ({ searchParam }) => {
|
|||||||
onChange={handleChangeMedia}
|
onChange={handleChangeMedia}
|
||||||
/>
|
/>
|
||||||
<label htmlFor="upload-button">
|
<label htmlFor="upload-button">
|
||||||
<IconButton aria-label="upload" component="span">
|
<IconButton aria-label="upload" component="span" disabled={loading}>
|
||||||
<AttachFileIcon className={classes.sendMessageIcons} />
|
<AttachFileIcon className={classes.sendMessageIcons} />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</label>
|
</label>
|
||||||
@@ -286,7 +315,8 @@ const MessagesInput = ({ searchParam }) => {
|
|||||||
disabled={recording}
|
disabled={recording}
|
||||||
onPaste={handleInputPaste}
|
onPaste={handleInputPaste}
|
||||||
onKeyPress={e => {
|
onKeyPress={e => {
|
||||||
if (e.key === "Enter") {
|
if (loading) return;
|
||||||
|
else if (e.key === "Enter") {
|
||||||
handleSendMessage();
|
handleSendMessage();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
@@ -297,6 +327,7 @@ const MessagesInput = ({ searchParam }) => {
|
|||||||
aria-label="sendMessage"
|
aria-label="sendMessage"
|
||||||
component="span"
|
component="span"
|
||||||
onClick={handleSendMessage}
|
onClick={handleSendMessage}
|
||||||
|
disabled={loading}
|
||||||
>
|
>
|
||||||
<SendIcon className={classes.sendMessageIcons} />
|
<SendIcon className={classes.sendMessageIcons} />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
@@ -306,15 +337,24 @@ const MessagesInput = ({ searchParam }) => {
|
|||||||
aria-label="cancelRecording"
|
aria-label="cancelRecording"
|
||||||
component="span"
|
component="span"
|
||||||
fontSize="large"
|
fontSize="large"
|
||||||
onClick={e => setRecording(false)}
|
disabled={loading}
|
||||||
|
onClick={handleCancelAudio}
|
||||||
>
|
>
|
||||||
<HighlightOffIcon className={classes.cancelAudioIcon} />
|
<HighlightOffIcon className={classes.cancelAudioIcon} />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<RecordingTimer />
|
{loading ? (
|
||||||
|
<div>
|
||||||
|
<CircularProgress className={classes.audioLoading} />
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<RecordingTimer />
|
||||||
|
)}
|
||||||
|
|
||||||
<IconButton
|
<IconButton
|
||||||
aria-label="sendRecordedAudio"
|
aria-label="sendRecordedAudio"
|
||||||
component="span"
|
component="span"
|
||||||
onClick={stopRecording}
|
onClick={handleUploadAudio}
|
||||||
|
disabled={loading}
|
||||||
>
|
>
|
||||||
<CheckCircleOutlineIcon className={classes.sendAudioIcon} />
|
<CheckCircleOutlineIcon className={classes.sendAudioIcon} />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
@@ -323,7 +363,7 @@ const MessagesInput = ({ searchParam }) => {
|
|||||||
<IconButton
|
<IconButton
|
||||||
aria-label="showRecorder"
|
aria-label="showRecorder"
|
||||||
component="span"
|
component="span"
|
||||||
onClick={startRecording}
|
onClick={handleStartRecording}
|
||||||
>
|
>
|
||||||
<MicIcon className={classes.sendMessageIcons} />
|
<MicIcon className={classes.sendMessageIcons} />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
|||||||
Reference in New Issue
Block a user