Skip to content

Instantly share code, notes, and snippets.

@nxsyed
Created July 12, 2018 20:22
Show Gist options
  • Save nxsyed/cd1b1d90091d85942581b00fb0b86c25 to your computer and use it in GitHub Desktop.
Save nxsyed/cd1b1d90091d85942581b00fb0b86c25 to your computer and use it in GitHub Desktop.
let headersObject = request.headers;
let paramsObject = request.params;
let methodString = request.method;
let bodyString = request.body;
// Set the status code - by default it would return 200
response.status = 200;
// Set the headers the way you like
response.headers['X-Custom-Header'] = 'CustomHeaderValue';
console.log(paramsObject);
if (paramsObject.action == "notify"){
return pubnub.publish({
"channel": "notify",
"message": "Someone is at your door!"
}).then((publishResponse) => {
console.log(`Publish Status: ${publishResponse[0]}:${publishResponse[1]} with TT ${publishResponse[2]}`);
return response.send();
});
}else{
return pubnub.history({
channel : "Alexa",
count : 1,
includeTimetoken : true
}).then((res) => {
res['messages'].forEach((value, index) => {
console.log("message:", value.entry, "timetoken:", value.timetoken);
});
return response.send({'message' : res['messages'][0].entry.message});
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment