-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathwebhook.js
More file actions
33 lines (27 loc) · 800 Bytes
/
webhook.js
File metadata and controls
33 lines (27 loc) · 800 Bytes
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
/**
* Example to receiving subscription events.
*
* Run:
* ZENVIA_API_TOKEN=your-api-token node webhook.js
*/
// const { Client, WebhookController } = require('@zenvia/sdk');
const { Client, WebhookController } = require('../dist');
const client = new Client(process.env.ZENVIA_API_TOKEN);
const webhook = new WebhookController({
messageEventHandler: (messageEvent) => {
console.log('Message event:', messageEvent);
},
messageStatusEventHandler: (messageStatusEvent) => {
console.log('Message status event:', messageStatusEvent);
},
client,
url: 'https://my-webhook.company.com',
channel: 'whatsapp',
});
webhook.on('listening', () => {
console.log('Webhook is listening');
});
webhook.on('error', (error) => {
console.error('Error:', error);
});
webhook.init();