Created
September 27, 2016 00:25
-
-
Save nzthiago/867ab5251f7544ae8b5e57f7e959b4be to your computer and use it in GitHub Desktop.
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
var https = require('https'); | |
module.exports = function(context, req) { | |
context.log('Node.js HTTP trigger function processed a request. RequestUri=%s', req.originalUrl); | |
if (req.query.text) { | |
var queryURL = 'https://autocomplete.clearbit.com/v1/companies/suggest?query=' + req.query.text | |
https.get(queryURL, function(res) { | |
var responseString = ''; | |
res.on('data', function(data) { | |
responseString += data; | |
}); | |
res.on('end', function(){ | |
var responseObj = JSON.parse(responseString); | |
context.res = { | |
body: { text: 'Here\'s the logo for *' + responseObj[0].name + '*:', | |
attachments: | |
[{ image_url: responseObj[0].logo, | |
text: responseObj[0].logo }] | |
} | |
}; | |
context.done(); | |
}); | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment