generated from bkper/bkper-tax-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webhook.js
42 lines (35 loc) · 908 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
41
42
import { connect } from 'ngrok';
import { Bkper } from 'bkper-js';
import { getOAuthToken } from 'bkper'
import { 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: 3004 });
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);