-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebhook.js
More file actions
56 lines (46 loc) · 1.29 KB
/
webhook.js
File metadata and controls
56 lines (46 loc) · 1.29 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { connect } from 'ngrok';
import { Bkper } from 'bkper-js';
import { getOAuthToken } from 'bkper'
import { App } from 'bkper-js';
import dotenv from 'dotenv';
import { fileURLToPath } from 'url';
import path from 'path';
const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
const __dirname = path.dirname(__filename); // get the name of the directory
dotenv.config({path:`${__dirname}/.env`})
process.env.NODE_ENV='development';
const apiKey = process.env.BKPER_API_KEY;
Bkper.setConfig({
oauthTokenProvider: () => getOAuthToken()
})
const app = new App();
let listener;
(async function() {
try {
console.log("Starting ngrok...");
const url = await connect({ port: 3041, authtoken_from_env: true });
console.log(`Started ngrok at ${url}`);
await app.setWebhookUrlDev(url).patch();
} catch (err) {
console.log(err);
throw err;
}
})();
async function exit() {
try {
await app.setWebhookUrlDev(null).patch();
console.log(' \nRemoved webhook.')
if (listener) {
listener.close();
}
} 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);
process.stdin.resume();