Skip to content

Commit e207db1

Browse files
author
Gavin Barron
committed
moving to func pack
1 parent e773f21 commit e207db1

File tree

19 files changed

+1897
-223
lines changed

19 files changed

+1897
-223
lines changed

.eslintrc.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"root": true,
3+
"extends": "eslint:recommended",
4+
"parserOptions": {
5+
"ecmaVersion": 7,
6+
"sourceType": "module"
7+
},
8+
"env": {
9+
"node": true,
10+
"mocha": true
11+
},
12+
"rules": {
13+
"no-console": 1,
14+
"no-extra-parens": "error",
15+
"array-bracket-newline": ["error", "consistent"],
16+
"brace-style": ["warn", "1tbs", { "allowSingleLine": true }],
17+
"no-trailing-spaces": "error",
18+
"no-whitespace-before-property": 1,
19+
"space-before-blocks": ["error", "always"],
20+
"keyword-spacing": ["error", { "before": true, "after": true }],
21+
"arrow-spacing": "error"
22+
}
23+
}

.gitignore

+24-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11

2-
*.js.map
3-
package-lock.json
4-
**/node_modules/
52
bin
6-
obj
3+
obj
4+
csx
5+
.vs
6+
edge
7+
Publish
8+
.vscode
9+
node_modules
10+
11+
*.user
12+
*.suo
13+
*.cscfg
14+
*.Cache
15+
project.lock.json
16+
17+
/packages
18+
/TestResults
19+
20+
/tools/NuGet.exe
21+
/App_Data
22+
/secrets
23+
/data
24+
.secrets
25+
appsettings.json
26+
local.settings.json

AcceptMeeting/function.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "queueTrigger",
66
"direction": "in",
77
"queueName": "accept-meeting",
8-
"connection": "travlerbotvkzmzc_STORAGE"
8+
"connection": "AzureWebJobsStorage"
99
}
1010
],
1111
"disabled": false

AcceptMeeting/index.js

+5-53
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,21 @@
1-
const https = require('https');
1+
const GraphHelper = require('../common/graphHelper');
22

33
module.exports = function (context, myQueueItem) {
44
context.log('Starting accept call');
55

6-
/**
7-
* Generates a POST request (of Content-type ```application/json```)
8-
* @param {string} path the path, relative to the host, to which this request will be sent
9-
* @param {string} token the access token with which the request should be authenticated
10-
* @param {string} data the data which will be 'POST'ed
11-
* @param {callback} callback
12-
*/
13-
function postData (path, token, data, callback) {
14-
var self = this;
15-
const options = {
16-
host: 'graph.microsoft.com',
17-
path: path,
18-
method: 'POST',
19-
headers: {
20-
'Content-Type': 'application/json',
21-
Authorization: 'Bearer ' + token,
22-
'Content-Length': data.length
23-
}
24-
};
25-
26-
const req = https.request(options, res => {
27-
let responseData = '';
28-
context.log('In response');
29-
30-
res.on('data', chunk => {
31-
// context.log('got data');
32-
(responseData += chunk);
33-
});
34-
res.on('end', () => {
35-
// context.log('data end');
36-
// context.log(res.statusCode);
37-
// context.log(responseData);
38-
// context.log(JSON.parse(responseData));
39-
if (res.statusCode === 201) callback(null, JSON.parse(responseData));
40-
else callback(JSON.parse(responseData), null);
41-
});
42-
});
43-
44-
req.write(data);
45-
req.end();
46-
context.log('Made request');
47-
48-
req.on('error', error => {
49-
context.log('Bad error');
50-
callback(error, null)
51-
});
52-
}
53-
546
const acceptData = {
55-
comment: '',
7+
comment: 'Accepted via the TravelTime Bot',
568
sendResponse: true
579
};
5810
const data = JSON.stringify(acceptData);
5911
context.log(`Accept call ${data}`);
6012

61-
postData(`/v1.0/${myQueueItem.meeting}/accept`, myQueueItem.accessToken, data, (error, data) => {
62-
if(error){
13+
GraphHelper.postData(`/v1.0/${myQueueItem.meeting}/accept`, myQueueItem.accessToken, data, (error, data) => {
14+
if (error) {
6315
context.done(error);
6416
return;
6517
}
66-
context.done();
18+
context.done(null, data);
6719
});
6820
};
6921

CalendarWebHookHandler/index.js

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
const azureStorage = require('azure-storage');
32
const cfg = require('../common/config')
43

@@ -16,21 +15,21 @@ module.exports = function (context, data) {
1615
return;
1716
}
1817

19-
const storageConnectionString = process.env.storageConnectionString || 'DefaultEndpointsProtocol=https;AccountName=travelerbot;AccountKey=b2cmbtSrWvJ2ebxO0PD1CQ+svlaxjUY3xtC8DdzJyeFXRGVgnsGhZkqU82rvgMiXE0ybEaWlTZpEsf/65drmNA==;EndpointSuffix=core.windows.net';
18+
const storageConnectionString = process.env.AzureWebJobsStorage;
2019
const queueSvc = azureStorage.createQueueService(storageConnectionString);
2120
// Write incoming notifications onto a queue.
22-
queueSvc.createQueueIfNotExists('hook-recieved', (err, result, response) => {
23-
if (err){
21+
queueSvc.createQueueIfNotExists('hook-recieved', err => {
22+
if (err) {
2423
// this should be a log for the dev, not a message to the user
25-
session.send('There was an error creating the hook-recieved queue: '+ err);
24+
context.log('There was an error creating the hook-recieved queue: '+ err);
2625
context.done(err);
2726
return;
2827
}
2928
// enqueue a message to process the webhook request.
3029
const request = data.body;
3130
context.log(request);
3231
const notificationCount = request.value.length;
33-
let processed = 0;
32+
let processed = 0;
3433
// web hook requests can contain multiple notifications
3534
for (let hook of request.value) {
3635
let msg = JSON.stringify(hook);
@@ -42,12 +41,11 @@ module.exports = function (context, data) {
4241
// add a log entry so that this can be investigated
4342
context.log('Unknown sender! Investigate the source of this message')
4443
context.log(data);
45-
context.res = { status: 202, body: 'All notifications processed' };
44+
context.res = { status: 202, body: 'All notifications processed' };
4645
context.done();
4746
return;
48-
break;
49-
}
50-
queueSvc.createMessage('hook-recieved', queueMessageBuffer, (err, result, response) => {
47+
}
48+
queueSvc.createMessage('hook-recieved', queueMessageBuffer, (err, result) => {
5149
processed++;
5250
// fail on any message not getting queued properly
5351
if (err) {
@@ -57,8 +55,8 @@ module.exports = function (context, data) {
5755
}
5856
context.log('webhook messge on put onto hook-recieved queue');
5957
if (processed == notificationCount) {
60-
context.res = { status: 202, body: 'All notifications processed' };
61-
context.done();
58+
context.res = { status: 202, body: 'All notifications processed' };
59+
context.done(null, result);
6260
}
6361
});
6462
}

CreateTravelBooking/function.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "queueTrigger",
66
"direction": "in",
77
"queueName": "add-travel-meeting",
8-
"connection": "travlerbotvkzmzc_STORAGE"
8+
"connection": "AzureWebJobsStorage"
99
}
1010
],
1111
"disabled": false

CreateTravelBooking/index.js

+4-41
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,8 @@
1-
const https = require('https');
1+
const GraphHelper = require('../common/graphHelper');
22

33
module.exports = function (context, myQueueItem) {
44
context.log('Starting travel meeting booking');
5-
6-
/**
7-
* Generates a POST request (of Content-type ```application/json```)
8-
* @param {string} path the path, relative to the host, to which this request will be sent
9-
* @param {string} token the access token with which the request should be authenticated
10-
* @param {string} data the data which will be 'POST'ed
11-
* @param {callback} callback
12-
*/
13-
function postData (path, token, data, callback) {
14-
var self = this;
15-
const options = {
16-
host: 'graph.microsoft.com',
17-
path: path,
18-
method: 'POST',
19-
headers: {
20-
'Content-Type': 'application/json',
21-
Authorization: 'Bearer ' + token,
22-
'Content-Length': data.length
23-
}
24-
};
255

26-
const req = https.request(options, res => {
27-
let subscriptionData = '';
28-
29-
res.on('data', chunk => (subscriptionData += chunk));
30-
res.on('end', () => {
31-
if (res.statusCode === 201) callback(null, JSON.parse(subscriptionData));
32-
else callback(JSON.parse(subscriptionData), null);
33-
});
34-
});
35-
36-
req.write(data);
37-
req.end();
38-
39-
req.on('error', error => callback(error, null));
40-
}
41-
context.log(myQueueItem.start);
42-
context.log(myQueueItem.durationInMins)
436
const start = new Date(myQueueItem.start);
447
const MS_PER_MINUTE = 60000;
458
const end = new Date(start.getTime() + myQueueItem.durationInMins * MS_PER_MINUTE).toISOString();
@@ -59,11 +22,11 @@ module.exports = function (context, myQueueItem) {
5922
}
6023
}
6124

62-
postData(`/v1.0/me/events`, myQueueItem.accessToken, JSON.stringify(meeting), (error, data) => {
63-
if(error){
25+
GraphHelper.postData(`/v1.0/me/events`, myQueueItem.accessToken, JSON.stringify(meeting), (error, data) => {
26+
if (error) {
6427
context.done(error);
6528
return;
6629
}
67-
context.done();
30+
context.done(null, data);
6831
});
6932
};

PostDeployScripts/runGulp.cmd

-30
This file was deleted.

ProcessCalendarEventNotification/function.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "queueTrigger",
66
"direction": "in",
77
"queueName": "hook-recieved",
8-
"connection": "travlerbotvkzmzc_STORAGE"
8+
"connection": "AzureWebJobsStorage"
99
},
1010
{
1111
"type": "http",

0 commit comments

Comments
 (0)