-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
128 lines (98 loc) · 3.98 KB
/
index.js
File metadata and controls
128 lines (98 loc) · 3.98 KB
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
'use strict';
// CONSTANTS - obtained from environment variables
var PORT = process.env.PORT;
// Handle local development and testing
if (process.env.RC_ENVIRONMENT !== 'Production') {
require('dotenv').config();
}
// Dependencies
var RC = require('ringcentral');
var unirest = require('unirest');
var http = require('http');
var xlsx = require('xlsx');
var server = http.createServer();
var workbook = xlsx.readFile('Master.xlsx');
var sheet_name_list = workbook.SheetNames;
var xlData = xlsx.utils.sheet_to_json(workbook.Sheets[sheet_name_list[0]])
//login
init();
/*
Using Glip Webhook Notifications
*/
function init() {
/*
Get the current date
*/
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1;
var yyyy = today.getFullYear();
var today = mm + '/' + dd + '/' + yyyy;
/*
Create the HTTP JSON Body
*/
var myObject = {"title": "**Graduation Report as of : " + today + "**"};
var attachements = [];
var appLink = "https://ai-developer.ringcentral.com/administration.html#/application/";
var orgLink = "https://ai-developer.ringcentral.com/administration.html#/organization-info/";
/*
Count of Apps
*/
var appsGraduated = 0,
appsDeclined = 0,
appsPending = 0;
/*
Application logic for numbers
*/
for(var i=0; i < xlData.length; i++) {
var attachement = {};
var fields = [];
if (xlData[i].Grad == "Grad") {
appsGraduated++;
}
if (xlData[i].Grad == "DEC") {
appsDeclined++;
}
if (xlData[i].Grad == "Pending") {
appsPending++;
}
fields.push({"title": "Org Name", "value": "["+xlData[i].OrgName+"]"+"("+ orgLink + xlData[i].AppId.substr(0,xlData[i].AppId.indexOf('~')) + ")", "short": true});
fields.push({"title": "App Name", "value": "["+xlData[i].AppName+"]"+"("+ appLink + xlData[i].AppId + ")", "short": true});
fields.push({"title": "Scope", "value": xlData[i].Scope, "short": true});
fields.push({"title": "Request Date", "value": xlData[i].RequestDate, "short": true});
fields.push({"title": "Grad", "value": xlData[i].Grad, "short": true});
fields.push({"title": "Review Date", "value": xlData[i].ReviewDate, "short": true});
fields.push({"title": "FreeAcct", "value": xlData[i].FreeAcct, "short": true});
attachement.fields = fields;
attachement.color = '#' + (xlData[i].Scope == "Private" ? "0000FF" : "FFA500");
attachements.push(attachement);
}
myObject.attachments = attachements;
myObject.body = "**Applications Applied for Graduation** : " + xlData.length + "\n" + "**Graduated** : " + appsGraduated + "\n" + "**Declined** : " + appsDeclined + "\n" + "**Pending** : " + appsPending + "\n" + "\n" + "**Daily Graduation Report** : https://docs.google.com/spreadsheets/d/1sk-jlI5ZS0vBjnRU_UW7JMSEcz3K9R9HVWozTyseoY0/edit#gid=0" + "\n" + "\n" + "Here are supplementary graduation weekly and daily sheets with charts for you: https://docs.google.com/a/ringcentral.com/spreadsheets/d/1WVPdmFxFPn-lrwzzEPdacXguDlBT0f_ACzbnMfKnjrU/edit?usp=sharing";
textProcess(myObject);
}
function textProcess(myObject) {
return unirest.post(process.env.GLIP_WEBHOOK_URL)
.headers({'Accept': 'application/json', 'Content-Type': 'application/json'})
.send(myObject)
.end(function(response) {
console.log(response.body);
});
}
// Start the server
server.listen(PORT);
// Server Event Listeners
server.on('request', inboundRequest);
server.on('error', function (err) {
console.error(err);
});
server.on('listening', function () {
console.log('Server is listening to ', PORT);
});
server.on('close', function () {
console.log('Server has closed and is no longer accepting connections');
});
// Server Request Handler
function inboundRequest(req, res) {
//console.log('REQUEST: ', req);
}