-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
114 lines (85 loc) · 3.37 KB
/
index.js
File metadata and controls
114 lines (85 loc) · 3.37 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
const express = require('express');
const bodyParser = require('body-parser');
const player = require('node-wav-player');
const path = require('path');
const app = express();
const port = 3000;
app.use(bodyParser.json());
app.post('/webhook', (req, res) => {
console.log('Webhook received');
const payload = req.body;
const status_check = Number(payload.heartbeat.status);
console.log(`Status: ${payload.heartbeat.status}`);
const soundFile = status_check === 0 ? 'error.wav' : 'success.wav';
const soundPath = path.join(__dirname, soundFile);
console.log(`Attempting to play: ${soundPath}`);
player.play({
path: soundPath
})
.then(() => console.log('Playback completed'))
.catch(err => console.error('Playback failed:', err));
res.sendStatus(200);
});
app.post('/webhook1', (req, res) => {
console.log('Webhook1 received');
const payload = req.body;
const status_check = Number(payload.heartbeat.status);
console.log(`Status: ${payload.heartbeat.status}`);
const soundFile = status_check === 0 ? 'error1.wav' : 'success1.wav';
const soundPath = path.join(__dirname, soundFile);
console.log(`Attempting to play: ${soundPath}`);
player.play({
path: soundPath
})
.then(() => console.log('Playback completed'))
.catch(err => console.error('Playback failed:', err));
res.sendStatus(200);
});
app.post('/webhook2', (req, res) => {
console.log('Webhook2 received');
const payload = req.body;
const status_check = Number(payload.heartbeat.status);
console.log(`Status: ${payload.heartbeat.status}`);
const soundFile = status_check === 0 ? 'error2.wav' : 'success2.wav';
const soundPath = path.join(__dirname, soundFile);
console.log(`Attempting to play: ${soundPath}`);
player.play({
path: soundPath
})
.then(() => console.log('Playback completed'))
.catch(err => console.error('Playback failed:', err));
res.sendStatus(200);
});
app.post('/webhook3', (req, res) => {
console.log('Webhook3 received');
const payload = req.body;
const status_check = Number(payload.heartbeat.status);
console.log(`Status: ${payload.heartbeat.status}`);
const soundFile = status_check === 0 ? 'error3.wav' : 'success3.wav';
const soundPath = path.join(__dirname, soundFile);
console.log(`Attempting to play: ${soundPath}`);
player.play({
path: soundPath
})
.then(() => console.log('Playback completed'))
.catch(err => console.error('Playback failed:', err));
res.sendStatus(200);
});
app.post('/webhook4', (req, res) => {
console.log('Webhook4 received');
const payload = req.body;
const status_check = Number(payload.heartbeat.status);
console.log(`Status: ${payload.heartbeat.status}`);
const soundFile = status_check === 0 ? 'error4.wav' : 'success4.wav';
const soundPath = path.join(__dirname, soundFile);
console.log(`Attempting to play: ${soundPath}`);
player.play({
path: soundPath
})
.then(() => console.log('Playback completed'))
.catch(err => console.error('Playback failed:', err));
res.sendStatus(200);
});
app.listen(port, () => {
console.log(`Webhooks receiver listening at http://localhost:${port}`);
});