Skip to content

Instantly share code, notes, and snippets.

@lheritage
Last active January 31, 2018 18:45
Show Gist options
  • Save lheritage/76f1d0b24ab68b1fdf810551c8dd1e78 to your computer and use it in GitHub Desktop.
Save lheritage/76f1d0b24ab68b1fdf810551c8dd1e78 to your computer and use it in GitHub Desktop.
This is snippets of code for the Alexa Demo built in meetups
// add at top
var http = require("http");
// In the Case IntentRequest switch statement , add this as new case
case "AddToListIntent":
console.log("We are going to add to List - AddToListIntent");
console.log("this is value" + req.body.request.intent.slots.item.value);
var body = {"item": req.body.request.intent.slots.item.value, "userID" : req.body.session.user.userId };
console.log("this is body " + JSON.stringify(body));
httpPost("/api/mylist", body, (myResult)=>{
sendResponse(req, resp, next, "We added to list", true, {});
}
);
break;
// Add end of file
function httpPost(mypath, body ,callback) {
console.log("This is body in post" + JSON.stringify(body));
var options = {
host: 'localhost',
port: 8080,
path: mypath,
method: 'POST',
headers: {
'Content-Type': 'application/json',
}
};
var req = http.request(options, res => {
res.setEncoding('utf8');
console.log('Status: ' + res.statusCode);
var returnData = "";
res.on('data', chunk => {
console.log("this is chunk " + chunk);
returnData = returnData + chunk;
});
res.on('end', () => {
callback(returnData); // this will execute whatever function the caller defined, with one argument
});
});
req.write(JSON.stringify(body));
req.end();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment