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_auth
*/wwebjs_auth/*
.wwebjs_cache
*/wwebjs_cache/*
# testing
/coverage

View File

View File

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

View File

@ -326,8 +326,7 @@ app.post('/api/session', async function (req, res) {
if (whatsapp.length > 0) {
if (whatsapp[0]['name'].split(' ').length > 0) {
whatsappName = `${
whatsapp[0]['name'].split(' ')[0]
whatsappName = `${whatsapp[0]['name'].split(' ')[0]
} - S${numberSession}`
}
}
@ -361,7 +360,16 @@ app.post('/api/session', async function (req, res) {
stream.write(
`# 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()
})
@ -380,7 +388,13 @@ app.post('/api/session', async function (req, res) {
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')

View File

@ -1,44 +1,49 @@
const pm2 = require('pm2');
const { execSync } = require("child_process");
const pm2 = require('pm2')
const { execSync } = require("child_process")
function startPm2Process(process_name, file, path, port) {
function startPm2Process(process_name, file, path, env) {
pm2.connect(function (err) {
if (err) {
console.error(err);
console.error(err)
// process.exit(2);
}
console.log('ENV PM2: ', env)
pm2.start({
name: process_name,
script: file,
cwd: path,
env: {
PORT: port
}
env
// env: {
// NODE_ENV: 'production',
// PORT: port,
// }
// additional options here if needed
}, function (err, apps) {
if (err) {
console.error(err);
console.error(err)
// process.exit(2);
}
else {
execSync(`pm2 save --force`, { cwd: path }, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
console.log(`error: ${error.message}`)
return
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
console.log(`stderr: ${stderr}`)
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
MOBILEUID=5517988310949
MOBILENAME=Numero de teste
MOBILEUID=5521995996701
MOBILENAME=test - S1
# PORT NUMBER FOR THIS API
PORT=8020
PORT=8029
# URL FROM THE OMNIHIT BACKEND API
CLIENT_URL=http://localhost:8080
@ -16,5 +16,10 @@ DB_PASS=strongpassword
DB_PORT=3306
# 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",
"express": "^4.17.1",
"form-data": "^4.0.0",
"fs-extra": "^11.1.0",
"logger": "^0.0.1",
"mime": "^2.4.5",
"mongodb": "^4.1.1",
"mongoose": "^7.4.3",
"multer": "^1.4.4",
"mysql": "^2.18.1",
"node-os-utils": "^1.3.5",
"qr-encode": "^0.3.0",
"qrcode-terminal": "^0.12.0",
"socket.io": "^4.5.4",
"socket.io-client": "^4.5.4",
"fs-extra": "^11.1.0"
"socket.io-client": "^4.5.4"
},
"devDependencies": {
"nodemon": "^2.0.20"

View File

@ -27,7 +27,6 @@ import MainHeaderButtonsWrapper from '../../components/MainHeaderButtonsWrapper'
import Title from '../../components/Title'
import TableRowSkeleton from '../../components/TableRowSkeleton'
import api from '../../services/api'
import CampaignModal from '../../components/CampaignModal'
import ConfirmationModal from '../../components/ConfirmationModal'
import QrcodeModal from '../../components/QrcodeModal'
@ -176,29 +175,6 @@ const Campaign = () => {
return () => clearTimeout(delayDebounceFn)
}, [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 = () => {
setSelectedCampaign(null)
@ -270,13 +246,6 @@ const Campaign = () => {
}
const handleSubmitConfirmationModal = async () => {
if (confirmModalInfo.action === 'disconnect') {
try {
await api.delete(`/whatsappsession/${confirmModalInfo.campaignId}`)
} catch (err) {
toastError(err)
}
}
if (confirmModalInfo.action === 'delete') {
try {

View File

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