1
-
2
1
const azureStorage = require ( 'azure-storage' ) ;
3
2
const cfg = require ( '../common/config' )
4
3
@@ -16,21 +15,21 @@ module.exports = function (context, data) {
16
15
return ;
17
16
}
18
17
19
- const storageConnectionString = process . env . storageConnectionString || 'DefaultEndpointsProtocol=https;AccountName=travelerbot;AccountKey=b2cmbtSrWvJ2ebxO0PD1CQ+svlaxjUY3xtC8DdzJyeFXRGVgnsGhZkqU82rvgMiXE0ybEaWlTZpEsf/65drmNA==;EndpointSuffix=core.windows.net' ;
18
+ const storageConnectionString = process . env . AzureWebJobsStorage ;
20
19
const queueSvc = azureStorage . createQueueService ( storageConnectionString ) ;
21
20
// 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 ) {
24
23
// 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 ) ;
26
25
context . done ( err ) ;
27
26
return ;
28
27
}
29
28
// enqueue a message to process the webhook request.
30
29
const request = data . body ;
31
30
context . log ( request ) ;
32
31
const notificationCount = request . value . length ;
33
- let processed = 0 ;
32
+ let processed = 0 ;
34
33
// web hook requests can contain multiple notifications
35
34
for ( let hook of request . value ) {
36
35
let msg = JSON . stringify ( hook ) ;
@@ -42,12 +41,11 @@ module.exports = function (context, data) {
42
41
// add a log entry so that this can be investigated
43
42
context . log ( 'Unknown sender! Investigate the source of this message' )
44
43
context . log ( data ) ;
45
- context . res = { status : 202 , body : 'All notifications processed' } ;
44
+ context . res = { status : 202 , body : 'All notifications processed' } ;
46
45
context . done ( ) ;
47
46
return ;
48
- break ;
49
- }
50
- queueSvc . createMessage ( 'hook-recieved' , queueMessageBuffer , ( err , result , response ) => {
47
+ }
48
+ queueSvc . createMessage ( 'hook-recieved' , queueMessageBuffer , ( err , result ) => {
51
49
processed ++ ;
52
50
// fail on any message not getting queued properly
53
51
if ( err ) {
@@ -57,8 +55,8 @@ module.exports = function (context, data) {
57
55
}
58
56
context . log ( 'webhook messge on put onto hook-recieved queue' ) ;
59
57
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 ) ;
62
60
}
63
61
} ) ;
64
62
}
0 commit comments