forked from orkestral/venom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
86 lines (71 loc) · 1.9 KB
/
app.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
83
84
85
86
/* eslint-disable */
const venom = require('./dist/index');
try {
venom
.create({
session: 'sessionName_0001',
headless: false,
devtools: true,
useChrome: false,
})
.then((client) => start(client))
.catch(async (err) => {
console.log('Startup error: ' + err);
});
} catch (e) {
console.log(e);
}
async function start(client) {
console.log('We have started');
console.log(await client.getWAVersion());
const page = client.waPage;
const browser = page.browser();
const pid = browser.process().pid;
console.log(JSON.stringify(pid, null, 2));
console.log(await client.isLoggedIn());
const hostData = await client.getHost();
if(hostData && hostData.id) {
console.log(hostData.id);
}
let lastMessageId = "";
client.onAnyMessage((message) => {
if (lastMessageId === message.id) {
console.log('Duplicate message: ' + lastMessageId)
} else {
lastMessageId = message.id;
console.log(message);
console.log('New message: ' + message.id + ' ' + message.type);
}
if (message['isGroupMsg']) {
const ids = client
.getGroupMembers(message['chatId'], 1000)
.then((ids) => {
console.log(ids);
});
}
});
client.onStateChange((state) => {
console.log("State change: " + client.session);
console.log("State change: " + state);
})
client.onStreamChange((stream) => {
console.log("Stream change: " + client.session);
console.log("Stream change: " + stream);
})
client.onMessageEdit((message) => {
console.log('EDIT!');
console.log(message);
});
client.onMessageDelete((message) => {
console.log('DELETE!');
console.log(message);
});
client.onMessageEdit((message) => {
console.log('EDIT!');
console.log(message);
});
client.onMessageReaction((reaction) => {
console.log('REACTION!');
console.log(reaction);
});
}