-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathStartReceivingNotifications.js
More file actions
29 lines (27 loc) · 1.04 KB
/
StartReceivingNotifications.js
File metadata and controls
29 lines (27 loc) · 1.04 KB
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
import whatsAppClient from '@green-api/whatsapp-api-client';
// instance manager https://console.green-api.com
const idInstance = ''; // your instance id
const apiTokenInstance = ''; // your instance api token
// Start Receiving Notifications
(async () => {
const restAPI = whatsAppClient.restAPI(({
idInstance,
apiTokenInstance
}))
try {
await restAPI.webhookService.startReceivingNotifications()
restAPI.webhookService.onReceivingMessageText((body) => {
console.log('onReceivingMessageText', body)
restAPI.webhookService.stopReceivingNotifications();
console.log("Notifications is about to stop in 5 sec if no messages will be queued...")
})
restAPI.webhookService.onReceivingDeviceStatus((body) => {
console.log('onReceivingDeviceStatus', body)
})
restAPI.webhookService.onReceivingAccountStatus((body) => {
console.log('onReceivingAccountStatus', body)
})
} catch (ex) {
console.error(ex);
}
})();