-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathexample.js
More file actions
30 lines (24 loc) · 1.04 KB
/
Copy pathexample.js
File metadata and controls
30 lines (24 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
30
// Initialize WebHooks module.
const WebHooks = require('./index')
const webHooks = new WebHooks({
db: './webHooksDB.json' // json file that store webhook URLs
})
// sync instantation - add a new webhook called 'shortname1'
webHooks.add('shortname1', 'http://127.0.0.1:9000/prova/other_url').then(() => {
// done
}).catch((err) => {
console.log(err)
})
// add another webHook
webHooks.add('shortname2', 'http://127.0.0.1:9000/prova2/').then(() => {
// done
}).catch((err) => {
console.log(err)
})
// remove a single url attached to the given shortname
// webHooks.remove('shortname3', 'http://127.0.0.1:9000/query/').catch((err) => console.error(err))
// if no url is provided, remove all the urls attached to the given shortname
// webHooks.remove('shortname3').catch((err) => console.error(err))
// trigger a specific webHook
webHooks.trigger('shortname1', { data: 123 })
webHooks.trigger('shortname2', { data: 123456 }, { header: 'header' }) // payload will be sent as POST request with JSON body (Content-Type: application/json) and custom header