Created
July 4, 2017 08:48
-
-
Save kennetham/bda6601a9a740d5666905da31794ae37 to your computer and use it in GitHub Desktop.
Azure Function Forwarding Message to Azure App Service
This file contains 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
const https = require('https'); | |
module.exports = function (context, req) { | |
// Obtain message from request. | |
const post_data = JSON.stringify(req.body); | |
// Obtain token from request. | |
// Required to forward to bot. | |
const authorization = req.headers.authorization; | |
const post_options = { | |
host: 'botservicetest.azurewebsites.net', | |
port: '443', | |
path: '/api/messages', | |
method: 'POST', | |
headers: { | |
'content-type': 'application/json', | |
'content-length': Buffer.byteLength(post_data), | |
'authorization': authorization | |
} | |
}; | |
const post_req = https.request(post_options); | |
// Post the data | |
post_req.write(post_data); | |
post_req.on('error', (e) => { | |
context.log(e); | |
}); | |
post_req.end(); | |
context.done(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment