Skip to content

Instantly share code, notes, and snippets.

@shyampurk
Last active February 18, 2018 11:47
Show Gist options
  • Save shyampurk/e890d727bfb035c159dac35fe9e02696 to your computer and use it in GitHub Desktop.
Save shyampurk/e890d727bfb035c159dac35fe9e02696 to your computer and use it in GitHub Desktop.
Watson-NLC-EventFeedback
db.get(request.message.userMessage).then((database_value)=>{
console.log("FETCHED DATABASE VALUE",database_value);
var feedback = request.message.userMessage; // Extract the feedback from the incoming Message.
fetchUserFeedback(feedback);
console.log(request.message);
});
xhr.fetch(url).then((url_fetched_data) =>{
var fetched_message_body = JSON.parse(url_fetched_data.body);
var top_class = fetched_message_body.top_class;
console.log("FETCHED CLASS FOR RECEIVED FEEDBACK --> ",top_class);
console.log(fetched_message_body);
// Preparing Object with the Classified Class
message = {"feedbackClass":top_class};
// Calling the broadcast function to send to message(Classified Class) back to the client
broadcastMessage(pubchannel,message);
// Storing the Prepared Object with to the Database with feedback as key.
db.set(feedback,message);
})
function broadcastMessage(pubchannel,message){
// Broadcasting the Message back to the page with Classified class.
pubnub.publish({
channel : pubchannel,
message : message,
callback : function(e) {
console.log( "SUCCESS!", e );
},
error : function(e) {
console.log( "FAILED! RETRY PUBLISH!", e );
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment