-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
44 lines (38 loc) · 1.09 KB
/
server.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
43
44
const { createWebhookModule } = require("sipgateio");
const axios = require("axios").default;
require("dotenv").config();
const slackWebhookUrl = process.env.SLACK_WEBHOOK_URL;
if (!slackWebhookUrl) {
console.error(
"Please provide a Slack webhook URL via the environment variable SLACK_WEBHOOK_URL"
);
return;
}
const serverAddress = process.env.WEBHOOK_SERVER_ADDRESS;
if (!serverAddress) {
console.error(
"Please provide a server address via the environment variable WEBHOOK_SERVER_ADDRESS"
);
return;
}
const webhookServerOptions = {
port: process.env.WEBHOOK_SERVER_PORT || 8080,
serverAddress,
};
createWebhookModule()
.createServer(webhookServerOptions)
.then((server) => {
console.log(
`Server running at ${webhookServerOptions.serverAddress}\n` +
"Ready for calls 📞"
);
server.onHangUp((hangUpEvent) => {
if (hangUpEvent.cause === "cancel") {
axios
.post(slackWebhookUrl, {
text: `Canceled call from ${hangUpEvent.from} to ${hangUpEvent.to}`,
})
.catch(console.error);
}
});
});