-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (53 loc) · 1.51 KB
/
index.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
const WebSocket = require('ws');
console.log(process.argv)
if (process.argv.length !== 5) {
console.error('Usage node index.js <username> <password> <customerId>');
process.exit(1);
}
const username = process.argv[2]
const password = process.argv[3]
const customerId = process.argv[4]
const start = async () => {
const endpoint = 'https://bedriftsnett-api.phonero.net/authenticate';
const session = await fetch(
endpoint,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
username: username,
password:password,
}),
})
.then((res) => res.json())
console.log(session)
const ws = new WebSocket('wss://bedriftsnett-api.phonero.net/events', {
headers: {
Cookie: `BNINTEGRATORAPI=${session.sessionId};`,
'Content-Type': 'application/json',
},
});
ws.on('error', console.error);
ws.on('open', function open() {
ws.send(
JSON.stringify({
action: 'subscribe',
topic: `callStatus.${customerId}`,
param: 'initial',
})
);
setInterval(() => {
ws.send(
JSON.stringify({
action: 'ping',
})
);
}, 60000);
});
ws.on('message', function message(data) {
console.log('received: %s', data);
});
}
start();