Atualização api de sessões para suportar o modulo campanha

pull/21/head
adriano 2023-08-15 09:14:10 -03:00
parent 5907fc6cb2
commit 3acf2bb261
12 changed files with 728 additions and 2272 deletions

5
.gitignore vendored
View File

@ -23,6 +23,11 @@ WWebJS
*/WWebJS/* */WWebJS/*
**WWebJS **WWebJS
.wwebjs_auth
*/wwebjs_auth/*
.wwebjs_cache
*/wwebjs_cache/*
# testing # testing
/coverage /coverage

View File

View File

@ -4,4 +4,5 @@ BASE_URL=http://localhost
PASS="strongpassword, strongpassword32" PASS="strongpassword, strongpassword32"
DB_MONGO_URL=mongodb://localhost:27017 DB_MONGO_URL=mongodb://localhost:27017
DB_MONGO_NAME=session_out_omnihit_db DB_MONGO_NAME=session_out_omnihit_db
DB_MONGO_NAME_CAMPAIGN=broker_omnihit

View File

@ -233,7 +233,7 @@ app.post('/api/session', async function (req, res) {
parseInt( parseInt(
e.name e.name
.split('->') .split('->')
[e.name.split('->').length - 1].trim() [e.name.split('->').length - 1].trim()
.match(/\d+/)[0] .match(/\d+/)[0]
) )
) )
@ -326,9 +326,8 @@ app.post('/api/session', async function (req, res) {
if (whatsapp.length > 0) { if (whatsapp.length > 0) {
if (whatsapp[0]['name'].split(' ').length > 0) { if (whatsapp[0]['name'].split(' ').length > 0) {
whatsappName = `${ whatsappName = `${whatsapp[0]['name'].split(' ')[0]
whatsapp[0]['name'].split(' ')[0] } - S${numberSession}`
} - S${numberSession}`
} }
} }
@ -361,7 +360,16 @@ app.post('/api/session', async function (req, res) {
stream.write( stream.write(
`# WHATSAPP ID OF THE TABLE Whatsapps FROM THE OMNIHIT DATABASE\n` `# WHATSAPP ID OF THE TABLE Whatsapps FROM THE OMNIHIT DATABASE\n`
) )
stream.write(`WHATSAPP_ID=${whatsappId}`) stream.write(`WHATSAPP_ID=${whatsappId}\n`)
stream.write('\n')
stream.write('# MONGO CONNECTION\n')
stream.write(`DB_MONGO_URL=${process.env.DB_MONGO_URL}\n`)
stream.write('\n')
stream.write('# MONGO COLLECTION\n')
stream.write(`DB_MONGO_NAME=${process.env.DB_MONGO_NAME_CAMPAIGN}\n`)
stream.write('\n')
stream.end() stream.end()
}) })
@ -380,7 +388,13 @@ app.post('/api/session', async function (req, res) {
console.log(`stdout: ${stdout}`) console.log(`stdout: ${stdout}`)
}) })
startPm2Process(dirSessionAppName, 'app.js', destDir, appPort) const env = {
PORT: appPort,
DB_MONGO_URL: process.env.DB_MONGO_URL,
DB_MONGO_NAME: process.env.DB_MONGO_NAME_CAMPAIGN
}
startPm2Process(dirSessionAppName, 'app.js', destDir, env)
} }
res.send('OK') res.send('OK')

View File

@ -1,44 +1,49 @@
const pm2 = require('pm2'); const pm2 = require('pm2')
const { execSync } = require("child_process"); const { execSync } = require("child_process")
function startPm2Process(process_name, file, path, port) { function startPm2Process(process_name, file, path, env) {
pm2.connect(function (err) { pm2.connect(function (err) {
if (err) { if (err) {
console.error(err); console.error(err)
// process.exit(2); // process.exit(2);
} }
console.log('ENV PM2: ', env)
pm2.start({ pm2.start({
name: process_name, name: process_name,
script: file, script: file,
cwd: path, cwd: path,
env: { env
PORT: port // env: {
} // NODE_ENV: 'production',
// PORT: port,
// }
// additional options here if needed // additional options here if needed
}, function (err, apps) { }, function (err, apps) {
if (err) { if (err) {
console.error(err); console.error(err)
// process.exit(2); // process.exit(2);
} }
else { else {
execSync(`pm2 save --force`, { cwd: path }, (error, stdout, stderr) => { execSync(`pm2 save --force`, { cwd: path }, (error, stdout, stderr) => {
if (error) { if (error) {
console.log(`error: ${error.message}`); console.log(`error: ${error.message}`)
return; return
} }
if (stderr) { if (stderr) {
console.log(`stderr: ${stderr}`); console.log(`stderr: ${stderr}`)
return; return
} }
console.log(`stdout: ${stdout}`); console.log(`stdout: ${stdout}`)
}); })
} }
pm2.disconnect(); pm2.disconnect()
}); })
}); })
} }

View File

@ -1,9 +1,9 @@
# NUMBER AND NAME THAT WILL BE DISPLAYED ON CONSOLE # NUMBER AND NAME THAT WILL BE DISPLAYED ON CONSOLE
MOBILEUID=5517988310949 MOBILEUID=5521995996701
MOBILENAME=Numero de teste MOBILENAME=test - S1
# PORT NUMBER FOR THIS API # PORT NUMBER FOR THIS API
PORT=8020 PORT=8029
# URL FROM THE OMNIHIT BACKEND API # URL FROM THE OMNIHIT BACKEND API
CLIENT_URL=http://localhost:8080 CLIENT_URL=http://localhost:8080
@ -13,8 +13,13 @@ DB=whaticket
DB_HOST=localhost DB_HOST=localhost
DB_USER=whaticket DB_USER=whaticket
DB_PASS=strongpassword DB_PASS=strongpassword
DB_PORT=3306 DB_PORT=3306
# WHATSAPP ID OF THE TABLE Whatsapps FROM THE OMNIHIT DATABASE # WHATSAPP ID OF THE TABLE Whatsapps FROM THE OMNIHIT DATABASE
WHATSAPP_ID=46 WHATSAPP_ID=229
# MONGO CONNECTION
DB_MONGO_URL=mongodb://localhost:27017
# MONGO COLLECTION
DB_MONGO_NAME=broker_omnihit

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,18 @@
const { MongoClient } = require('mongodb')
const uri = process.env.DB_MONGO_URL
const mongo = new MongoClient(uri)
async function run() {
try {
await mongo.connect()
console.log('Connectado ao mongo db')
} catch (err) {
console.log(err)
}
}
run()
module.exports = mongo

File diff suppressed because it is too large Load Diff

View File

@ -15,17 +15,18 @@
"dotenv": "^16.0.0", "dotenv": "^16.0.0",
"express": "^4.17.1", "express": "^4.17.1",
"form-data": "^4.0.0", "form-data": "^4.0.0",
"fs-extra": "^11.1.0",
"logger": "^0.0.1", "logger": "^0.0.1",
"mime": "^2.4.5", "mime": "^2.4.5",
"mongodb": "^4.1.1", "mongodb": "^4.1.1",
"mongoose": "^7.4.3",
"multer": "^1.4.4", "multer": "^1.4.4",
"mysql": "^2.18.1", "mysql": "^2.18.1",
"node-os-utils": "^1.3.5", "node-os-utils": "^1.3.5",
"qr-encode": "^0.3.0", "qr-encode": "^0.3.0",
"qrcode-terminal": "^0.12.0", "qrcode-terminal": "^0.12.0",
"socket.io": "^4.5.4", "socket.io": "^4.5.4",
"socket.io-client": "^4.5.4", "socket.io-client": "^4.5.4"
"fs-extra": "^11.1.0"
}, },
"devDependencies": { "devDependencies": {
"nodemon": "^2.0.20" "nodemon": "^2.0.20"

View File

@ -26,8 +26,7 @@ import MainHeader from '../../components/MainHeader'
import MainHeaderButtonsWrapper from '../../components/MainHeaderButtonsWrapper' import MainHeaderButtonsWrapper from '../../components/MainHeaderButtonsWrapper'
import Title from '../../components/Title' import Title from '../../components/Title'
import TableRowSkeleton from '../../components/TableRowSkeleton' import TableRowSkeleton from '../../components/TableRowSkeleton'
import api from '../../services/api'
import CampaignModal from '../../components/CampaignModal' import CampaignModal from '../../components/CampaignModal'
import ConfirmationModal from '../../components/ConfirmationModal' import ConfirmationModal from '../../components/ConfirmationModal'
import QrcodeModal from '../../components/QrcodeModal' import QrcodeModal from '../../components/QrcodeModal'
@ -175,30 +174,7 @@ const Campaign = () => {
}, 500) }, 500)
return () => clearTimeout(delayDebounceFn) return () => clearTimeout(delayDebounceFn)
}, [user.id]) }, [user.id])
useEffect(() => {
const fetchSession = async () => {
try {
// const test = await apiBroker.get('/contacts/status/insert/onqueue', {
// params: {
// adminId: user.id,
// baseURL: process.env.REACT_APP_BACKEND_URL_PRIVATE,
// identifier: 'campaign',
// },
// })
// console.log('-------------------> test: ', test)
// const { data } = await api.get('/settings')
// setSettings(data)
} catch (err) {
toastError(err)
}
}
fetchSession()
}, [])
const handleOpenCampaignModal = () => { const handleOpenCampaignModal = () => {
setSelectedCampaign(null) setSelectedCampaign(null)
@ -269,14 +245,7 @@ const Campaign = () => {
setConfirmModalOpen(true) setConfirmModalOpen(true)
} }
const handleSubmitConfirmationModal = async () => { const handleSubmitConfirmationModal = async () => {
if (confirmModalInfo.action === 'disconnect') {
try {
await api.delete(`/whatsappsession/${confirmModalInfo.campaignId}`)
} catch (err) {
toastError(err)
}
}
if (confirmModalInfo.action === 'delete') { if (confirmModalInfo.action === 'delete') {
try { try {

View File

@ -179,10 +179,7 @@ const Contacts = () => {
} }
}) })
if (insertOnQueue && insertOnQueue.data) { if (insertOnQueue && insertOnQueue.data) {
console.log('insertOnQueue: ', insertOnQueue.data)
console.log('data.app.file: ', insertOnQueue.data.app.file)
setZipFile(insertOnQueue.data.app.file) setZipFile(insertOnQueue.data.app.file)
setOnQueueProcessStatus(insertOnQueue.data.app.status) setOnQueueProcessStatus(insertOnQueue.data.app.status)