-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathcall-to-slack.js
43 lines (36 loc) · 988 Bytes
/
call-to-slack.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
const axios = require('axios');
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const PORT = process.env.PORT || 3000;
const slack_url = 'https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX';
const sendToSlack = async (txt) => {
try {
await axios.post(slackUrl, {
username: 'incoming_call',
text: txt,
});
} catch (error) {
console.error(error);
}
};
app.use(bodyParser.json());
app.post('/incoming-call', async (req, res) => {
const incomingCaller = req.body.from; // Replace this with the actual POST data
await sendToSlack(`incoming_caller: ${incomingCaller}`);
res.json({
connect: 'FIRST NUMBER',
timeout: 20,
failed: {
connect: 'SECOND NUMBER',
timeout: 20,
failed: {
connect: 'THIRD NUMBER',
timeout: 20,
},
},
});
});
app.listen(PORT, () => {
console.log(`Server is running on port ${ PORT }`);
});