forked from billbarsch/myzap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstartup.js
82 lines (77 loc) · 3.07 KB
/
startup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*##############################################################################
# File: startup.js #
# Project: myzap2.0 #
# Created Date: 2021-06-27 02:34:00 #
# Author: Eduardo Policarpo #
# Last Modified: 2021-07-11 00:35:56 #
# Modified By: Eduardo Policarpo #
##############################################################################*/
import SessionsDB from "./firebase/model.js";
import { snapshot} from './firebase/db.js';
import request from "request-promise";
import config from "./config.js";
async function getAllSessions() {
try {
const SessionsArray = [];
if (snapshot.empty) {
return null;
} else {
snapshot.forEach(doc => {
const Session = new SessionsDB(
doc.id,
doc.data().session,
doc.data().apitoken,
doc.data().sessionkey,
doc.data().wh_status,
doc.data().wh_message,
doc.data().wh_qrcode,
doc.data().wh_connect,
doc.data().WABrowserId,
doc.data().WASecretBundle,
doc.data().WAToken1,
doc.data().WAToken2,
doc.data().Engine
);
SessionsArray.push(Session);
});
return (SessionsArray);
}
} catch (error) {
return (error.message);
}
}
async function startAllSessions() {
let dados = await getAllSessions()
if (dados != null) {
if (dados === 'Missing or insufficient permissions.') {
console.log('######### ERRO DE CONFIGURACAO NO FIREBASE #########')
console.log('####### Missing or insufficient permissions. #######')
console.log('### Verifique as permissões de escrita e leitura ###')
} else {
dados.map((item) => {
var options = {
'method': 'POST',
'json': true,
'url': `${config.host}:${config.port}/start`,
'headers': {
'apitoken': item.apitoken,
'sessionkey': item.sessionkey
},
body: {
"session": item.session,
"wh_connect": item.wh_connect,
"wh_qrcode": item.wh_qrcode,
"wh_status": item.wh_status,
"wh_message": item.wh_message
}
};
request(options).then(result => {
console.log(result)
}).catch(error => {
console.log(error)
})
});
}
}
}
export default { startAllSessions };