forked from OfficeDev/Microsoft-Teams-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
141 lines (122 loc) · 3.69 KB
/
index.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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
const path = require('path');
const express = require('express');
const cors = require('cors');
const ENV_FILE = path.join(__dirname, '.env');
require('dotenv').config({ path: ENV_FILE });
const PORT = process.env.PORT || 3978;
const server = express();
const axios = require('axios');
var webhookUrl = "";
var taskList = {
"task": [
{
"Title": "Sample task 1",
"Assigned": "Alex",
"Description": "Description for sample task 1"
},
{
"Title": "Sample task 2",
"Assigned": "Wilbur",
"Description": "Description for sample task 2"
}
]
}
server.use(cors());
server.use(express.json());
server.use(express.urlencoded({
extended: true
}));
server.engine('html', require('ejs').renderFile);
server.set('view engine', 'ejs');
server.set('views', __dirname);
server.listen(PORT, () => {
console.log(`Server listening on http://localhost:${PORT}`);
});
server.use("/Images", express.static(path.resolve(__dirname, 'Images')));
server.get('/SetupAuth', (req, res, next) => {
res.render('./views/SetupAuth')
});
server.get('/TaskDetails', (req, res, next) => {
res.render('./views/TaskDetails', { taskList: JSON.stringify(taskList) })
});
server.post('/Task/Save', (req, res, next) => {
var link = process.env.BaseUrl + "/TaskDetails"
var task = {
"Title": req.body.title,
"Description": req.body.description,
"Assigned": req.body.assignedTo
};
taskList.task.push(task);
var card = {
"@type": "MessageCard",
"summary": "Task Created",
"sections": [
{
"activityTitle": "Task " + task.Title,
"facts": [
{
"name": 'Title:',
"value": task.Title
},
{
"name": 'Description:',
"value": task.Description
},
{
"name": 'Assigned To:',
"value": task.Assigned
}
]
}],
"potentialAction": [
{
"@context": "http://schema.org",
"@type": "ViewAction",
"name": "View Task List",
"target": [
process.env.BaseUrl + "/TaskDetails"
]
}
]
}
axios.post(webhookUrl, card)
.then(res => {
console.log(`statusCode: ${res.status}`)
console.log(res)
})
.catch(error => {
console.error(error)
})
});
server.get('/Create', (req, res, next) => {
res.render('./views/Create')
});
server.get('/SimpleStart', (req, res, next) => {
res.render('./views/SimpleStart', { clientId: JSON.stringify(process.env.MicrosoftAppId) })
});
server.get('/SimpleEnd', (req, res, next) => {
res.render('./views/SimpleEnd')
});
server.get('*', (req, res) => {
res.json({ error: 'Route not found' });
});
server.post('/Connector/Save', (req, res) => {
var link = process.env.BaseUrl + "/TaskDetails"
webhookUrl = req.body.webhookUrl;
var card = {
"@type": "MessageCard",
"summary": "Welcome Message",
"sections": [{
"activityTitle": "Welcome Message",
"text": "Teams todo connector is setup we will notify you when new task is created [here](" + link + ")"
}]
}
axios.post(req.body.webhookUrl, card)
.then(res => {
console.log(`statusCode: ${res.status}`)
console.log(res)
})
.catch(error => {
console.error(error)
})
});