-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
64 lines (47 loc) · 1.55 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
const express = require('express')
const moment = require('moment')
const jwt = require('jsonwebtoken');
require('dotenv').config();
const request = require('request');
var bodyParser = require('body-parser')
const app = express()
const port = 5000
const cors = require('cors');
app.use(cors())
app.use(bodyParser.json())
const userEmail = process.env.userEmail;
const payload = {
iss: process.env.APIKey,
exp: ((new Date()).getTime() + 5000)
};
const jwt_token = jwt.sign(payload, process.env.APISecret);
app.post('/event', (req, res) => {
const startTime = moment(req.body.start);
const end = moment(req.body.end);
var duration = moment.duration(end.diff(startTime));
var options = {
'method': 'POST',
'url': `https://api.zoom.us/v2/users/${userEmail}/meetings`,
'headers': {
'Content-Type': 'application/json',
'Authorization': `Bearer ${jwt_token}`,
},
body: JSON.stringify({
"topic": req.body.val,
"type":"2",
"duration": duration.asMinutes(),
"start_time":startTime.format('YYYY-MM-DDTHH:mm:ss'),
"timezone":"Europe/Paris",
"password":"123456",
"agenda":"AGENDA"
})
};
request(options, function (error, response) {
if (error) throw new Error(error);
const data = JSON.parse(response.body)
res.send({id: data.id, topic: data.topic})
});
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})