Skip to content

Instantly share code, notes, and snippets.

@nzthiago
Created September 27, 2016 00:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nzthiago/867ab5251f7544ae8b5e57f7e959b4be to your computer and use it in GitHub Desktop.
Save nzthiago/867ab5251f7544ae8b5e57f7e959b4be to your computer and use it in GitHub Desktop.
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