-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateMeetingWithExternalFiles.js
75 lines (61 loc) · 2.8 KB
/
createMeetingWithExternalFiles.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
//this package is made to do GET/POST requests
var auth = require("./auth.js");
var fs = require("fs");//this package reads from files
var path = require("path");//this package is used to get the directory
var fn = "config.json";//this file has our client ID and secret credentials to get the access token
var fnMeeting = "meeting.json";//this file has the details of the meeting
var oauthRec = {};
var meetingRec = {};
var uri = "api.bluejeans.com";
var authPath = "/oauth2/token?Client";
var userId = process.argv[2];//the parameters must be entered in this order when running this script
var start = process.argv[3];//start of the meeting
var duration = process.argv[4];//duration of the meeting
var jssrc = path.dirname(process.argv[1]);//name of the file directory
fs.readFile(jssrc + "\\" + fn, (err,data)=> { //reading the file with the client ID and secret credentials
if(err) {
console.log("Error reading file: " + fn +"\n"+err);
process.exit();
}
try{
oauthRec = JSON.parse(data.toString());//putting the file into the correct format for our auth function
}
catch(error){
console.error(error);
}
auth.post( uri, authPath,oauthRec).then(function(results){
var meetingPath = '/v1/user/' + userId +
'/scheduled_meeting?access_token=' + results.access_token + '&email=false'; //creating the path for the meeting
fs.readFile(jssrc + "\\" + fnMeeting, (err,data)=> {//reading the file with the details of the meeting
if(err) {
console.log("Error reading file: " + fn +"\n"+err);
process.exit();
}
try {
meetingRec = JSON.parse(data.toString());//putting the meeting details into the correct format
}
catch(error) {
console.error(error);
}
meetingRec.start = start;//the start of the meeting is an input
meetingRec.end = +meetingRec.start + +duration;//calculating the end of the meeting, the "+" in front of each variable
//transforms them from strings to integers so that the end of the meeting can be calculated by adding the start
//and duration together
auth.post(uri,meetingPath,meetingRec).then(function(results){
console.log("Meeting ID: " + results.numericMeetingId);
var startDate = new Date(+meetingRec.start);
var endDate = new Date(meetingRec.end);
console.log("Start: " + startDate);
console.log("End: " + endDate);
},function(errors){
var errorMessage = errors.replace(/\n/g,"\n ");
console.log("Error when trying to create meeting:\n " + errorMessage);
process.exit();
});
});
},function(errors){
var errorMessage = errors.replace(/\n/g,"\n ");
console.log("Error when trying to create access token:\n " + errorMessage);
process.exit();
});
});