Skip to content

Instantly share code, notes, and snippets.

@sunnygleason
Created March 21, 2017 20:43
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 sunnygleason/841f45a286236a294e09cfaf926d32d5 to your computer and use it in GitHub Desktop.
Save sunnygleason/841f45a286236a294e09cfaf926d32d5 to your computer and use it in GitHub Desktop.
PubNub Image Recognition BLOCK w/ AIception
export default (request) => {
const xhr = require('xhr');
const base64 = require('codec/base64');
const authToken = 'YOUR_AUTH_TOKEN';
const url = "https://aiception.com/api/v2.1/detect_object";
const httpOptions = {
"method": "POST",
"timeout": 10000,
"headers": {
"Authorization": "Basic " + base64.btoa(authToken + ":" + 'password is ignored'),
"Content-Type": "application/json"
},
"body": JSON.stringify({image_url:request.message.image_url,async:false})
};
return xhr.fetch(url, httpOptions).then((response) => {
request.message.ai_result = JSON.parse(response.body);
return request.ok();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment