Created
December 20, 2017 07:55
-
-
Save jeffhollan/b33c3b6b12e6dc8a4ef0ff178e0a8e8f to your computer and use it in GitHub Desktop.
Emit Event to Event Grid from an Azure Function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function EmitEvent(ringEvent, context, callback) { | |
| context.log('Sending event to event grid.'); | |
| var eventGridPayload = [{ | |
| id: utils.generateUUID(), | |
| eventType: ringEvent['kind'], | |
| subject: 'ring/frontDoor', | |
| eventTime: new Date().toISOString(), | |
| data: ringEvent | |
| }]; | |
| var response = ''; | |
| var req = https.request(options, (res) => { | |
| res.setEncoding('utf8'); | |
| res.on('data', (chunk) => { | |
| response += chunk; | |
| }); | |
| res.on('end', () => { | |
| context.log(response); | |
| callback(response); | |
| }); | |
| }); | |
| req.write(JSON.stringify(eventGridPayload)); | |
| req.end(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment