forked from OfficeDev/Microsoft-Teams-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
82 lines (71 loc) · 2.67 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
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
const express = require('express');
const path = require('path');
const cors = require('cors');
const app = express();
const { DecryptionHelper } = require("./helper/decryption-helper");
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({
extended: true
}));
var notificationResponse = [];
var notificationList = [];
const ENV_FILE = path.join(__dirname, '.env');
require('dotenv').config({ path: ENV_FILE });
// Parse application/json
app.use(express.json());
// Define route for the controller.
app.use('/api/changeNotification', require('./controller'));
// Listen for incoming requests.
app.post('/api/notifications', async (req, res) => {
let status;
var decryptedData = [];
if (req.query && req.query.validationToken) {
status = 200;
res.send(req.query.validationToken);
}
else {
var notification = req.body;
if (JSON.stringify(notification) === '{}') {
res.send(notificationList);
}
else {
notification = req.body.value;
decryptedData = await DecryptionHelper.processEncryptedNotification(notification);
notificationResponse.push(decryptedData);
notificationResponse.forEach(element => {
if (element.viewpoint != null) {
notificationList = [];
notificationList.push({
id: element.id,
createdDate: element.createdDateTime,
displayName: element.topic,
changeType: element.changeType,
isHidden: element.isHiddenForAllMembers,
lastUpdate: element.lastUpdatedDateTime,
viewpointIsHidden: element.viewpoint.isHidden,
viewpointLastMessageReadDT: element.viewpoint.lastMessageReadDateTime
})
}
else {
notificationList = [];
notificationList.push({
id: element.id,
createdDate: element.createdDateTime,
displayName: element.topic,
changeType: element.changeType,
isHidden: element.isHiddenForAllMembers,
lastUpdate: element.lastUpdatedDateTime
})
}
});
/** Send Respond to view **/
res.send(notificationList);
}
}
});
app.listen(3000, function () {
console.log('app listening on port 3000!');
});