Skip to content

Instantly share code, notes, and snippets.

@jazzedge
Created July 23, 2017 17:06
Show Gist options
  • Select an option

  • Save jazzedge/f0b637cfd4ad8bfe4bfb4c1a10f45999 to your computer and use it in GitHub Desktop.

Select an option

Save jazzedge/f0b637cfd4ad8bfe4bfb4c1a10f45999 to your computer and use it in GitHub Desktop.
Bot Vision API Test
//Vision API test
// Build the url we'll be calling to get top news
var url = "https://westeurope.api.cognitive.microsoft.com/vision/v1.0/describe/";
// Build options for the request
session.send(attachment.contentUrl + '/' + attachment.name);
var options = {
method: 'POST', // thie API call is a post request
uri: url,
headers: {
'Ocp-Apim-Subscription-Key': '10da26d86a0447348c1eafb03e11209d',
'Content-Type': "application/json"
},
body: {
url: attachment.contentUrl + '/' + attachment.name,
language: 'en'
},
json: true
}
//Make the call
rp(options).then(function (body){
// The request is successful
console.log(body["description"]["captions"]);
session.send(body["description"]["captions"][0]["text"]);
}).catch(function (err){
// An error occurred and the request failed
session.send("Argh, something went wrong. : ", err);
}).finally(function () {
// This is executed at the end, regardless of whether the request is successful or not
//session.endDialog();
});
//End of Vision API test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment