-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
57 lines (45 loc) · 1.71 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
45
46
47
48
49
50
51
52
53
54
55
56
57
const express = require('express')
const app = express()
require('dotenv').config();
const {db} = require('./Database/mongodb')
const { sendNotification } = require('./Notifications/slackNotificationService');
const { sendSslMessage } = require('./SMS/sslWirelessSMSProvider');
const port = process.env.PORT || 3000;
const Redis = require("ioredis");
const redis = new Redis({
host: process.env.REDIS_HOST,
port: process.env.REDIS_PORT,
password: process.env.REDIS_PASSWORD,
});
const subscriber = new Redis({
host: process.env.REDIS_HOST,
port: process.env.REDIS_PORT,
password: process.env.REDIS_PASSWORD,
});
/**============Channel name =========== */
const smsSendChannel = process.env.REDIS_SMS_CHANNEL || 'laravelsmschannel'
const slackNotificationChannel = process.env.REDIS_SLACK_NOTIFICATION_CHANNEL || 'laravelslackchannel';
subscriber.subscribe(smsSendChannel);
subscriber.subscribe(slackNotificationChannel);
/**===============Subscribe Channel=============================================== */
subscriber.on('message', (channel, message) => {
if(channel === smsSendChannel){
let data = JSON.parse(message);
let phone = data && data.phone ? data.phone : "01700000000";
let sms = data && data.message ? data.message : "Test message";
if(process.env.SMS_SEND){
sendSslMessage(phone,sms);
}
}
if(channel === slackNotificationChannel){
const slackWebhookUrl = process.env.SLACK_WEB_HOOK_URL;
sendNotification(slackWebhookUrl, JSON.parse(message));
}
});
/**===================================================================== */
app.get('/', (req, res) => {
res.send(`Landing page`);
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})