-
Notifications
You must be signed in to change notification settings - Fork 1
/
webhook.js
40 lines (34 loc) · 889 Bytes
/
webhook.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
import { connect } from 'ngrok';
import { getOAuthToken } from 'bkper';
import { Bkper, App } from 'bkper-js';
import dotenv from 'dotenv';
dotenv.config();
process.env.NODE_ENV = 'development';
Bkper.setConfig({
oauthTokenProvider: () => getOAuthToken(),
apiKeyProvider: () => process.env.BKPER_API_KEY,
})
const app = new App();
(async function () {
try {
const url = await connect({ port: 3001 });
console.log(`Started ngrok at ${url}`);
await app.setWebhookUrlDev(url).patch();
} catch (err) {
console.log(err);
}
})();
async function exit() {
try {
await app.setWebhookUrlDev(null).patch();
console.log(' \nRemoved webhook.');
} catch (err) {
console.log(err);
}
process.exit();
}
process.on('exit', exit);
process.on('SIGINT', exit);
process.on('SIGUSR1', exit);
process.on('SIGUSR2', exit);
process.on('uncaughtException', exit);