Skip to content

Instantly share code, notes, and snippets.

@chrismatthieu
Created May 17, 2016 19:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chrismatthieu/8c55310125058e19ded11aafc61ab4a0 to your computer and use it in GitHub Desktop.
Save chrismatthieu/8c55310125058e19ded11aafc61ab4a0 to your computer and use it in GitHub Desktop.
var https = require('https');
function octoblu(message, cb){
/**
* HOW TO Make an HTTP Call - POST
*/
// do a POST request
// create the JSON object
jsonObject = JSON.stringify(message);
// prepare the header
var postheaders = {
'Content-Type' : 'application/json',
'Content-Length' : Buffer.byteLength(jsonObject, 'utf8')
};
https://triggers.octoblu.com/flows/c0f28c38-63cd-45ac-aa7a-9e7c74243a6f/triggers/ea5bbb90-1c5f-11e6-8edc-0db5f34010b0
// the post options
var optionspost = {
host : 'triggers.octoblu.com',
port : 443,
path : '/flows/c0f28c38-63cd-45ac-aa7a-9e7c74243a6f/triggers/ea5bbb90-1c5f-11e6-8edc-0db5f34010b0',
method : 'POST',
headers : postheaders
};
console.info('Options prepared:');
console.info(optionspost);
console.info('Do the POST call');
// do the POST call
var reqPost = https.request(optionspost, function(res) {
console.log("statusCode: ", res.statusCode);
// uncomment it for header details
// console.log("headers: ", res.headers);
res.on('data', function(d) {
console.info('POST result:\n');
process.stdout.write(d);
console.info('\n\nPOST completed');
});
});
// write the json data
reqPost.write(jsonObject);
reqPost.end();
reqPost.on('error', function(e) {
console.error(e);
});
}
exports.handler = (event, context, callback) => {
console.log('Received event:', event.clickType);
var message = {
Message: `${event.serialNumber} -- processed by Lambda\nBattery voltage: ${event.batteryVoltage}`,
Subject: `Hello from your IoT Button ${event.serialNumber}: ${event.clickType}`
};
octoblu(message, (err, topicArn) => {
if (err) {
callback(err);
return;
}
console.log(`Calling Octoblu Trigger`);
});
};
//https://triggers.octoblu.com/flows/c0f28c38-63cd-45ac-aa7a-9e7c74243a6f/triggers/ea5bbb90-1c5f-11e6-8edc-0db5f34010b0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment