diff --git a/sample-functions/ChangeColorIntent/handler.js b/sample-functions/ChangeColorIntent/handler.js index 4de388f9c34c5052c89a06443d861438ed5bdae2..1439055f9b504bfc3768d1f29b584d884124a713 100644 --- a/sample-functions/ChangeColorIntent/handler.js +++ b/sample-functions/ChangeColorIntent/handler.js @@ -4,10 +4,9 @@ let sample = require("./sample.json"); let SendColor = require('./sendColor'); let sendColor = new SendColor("alexellis.io/tree1") -var content = ''; -process.stdin.resume(); -process.stdin.on('data', function(buf) { content += buf.toString(); }); -process.stdin.on('end', function() { +const getStdin = require('get-stdin'); + +getStdin().then(content => { let request = JSON.parse(content); handle(request, request.request.intent); }); @@ -20,7 +19,7 @@ function tellWithCard(speechOutput) { process.exit(0); } -function handle(request,intent) { +function handle(request, intent) { let colorRequested = intent.slots.LedColor.value; let req = {r:0,g:0,b:0}; if(colorRequested == "red") { @@ -31,10 +30,10 @@ function handle(request,intent) { req.g = 255; } else { - tellWithCard("I heard "+colorRequested+ " but can only do: red, green, blue.", "I heard "+colorRequested+ " but can only do: red, green, blue."); + return tellWithCard("I heard "+colorRequested+ " but can only do: red, green, blue.", "I heard "+colorRequested+ " but can only do: red, green, blue."); } - var speechOutput = "OK, "+colorRequested+"."; sendColor.sendColor(req, () => { - tellWithCard(speechOutput); + var speechOutput = "OK, " + colorRequested + "."; + return tellWithCard(speechOutput); }); } \ No newline at end of file diff --git a/sample-functions/ChangeColorIntent/package.json b/sample-functions/ChangeColorIntent/package.json index 4edbbdbc5b42ab52271f1214afc61b1ef2b9c102..141a2b895c240749aaf8a5831b4a7b5ce1d6bebd 100644 --- a/sample-functions/ChangeColorIntent/package.json +++ b/sample-functions/ChangeColorIntent/package.json @@ -10,6 +10,7 @@ "author": "", "license": "ISC", "dependencies": { + "get-stdin": "^5.0.1", "mqtt": "^2.0.1" } } diff --git a/sample-functions/ChangeColorIntent/sendColor.js b/sample-functions/ChangeColorIntent/sendColor.js index 8cf168808aecc65bc8056cdacd268b84462babbc..ecca6d973e244bd3f042d87ac14e7bd05f261e39 100644 --- a/sample-functions/ChangeColorIntent/sendColor.js +++ b/sample-functions/ChangeColorIntent/sendColor.js @@ -13,7 +13,7 @@ class Send { var client = mqtt.connect(ops); client.on('connect', () => { - console.log("Connected"); + let payload = req; let cb = () => { done(); @@ -30,7 +30,7 @@ class Send { done(); }; client.on('connect', () => { - console.log("Connected"); + let payload = req; client.publish(this.topic, JSON.stringify(payload), {qos: 1}, cb); }); diff --git a/sample-functions/HostnameIntent/handler.js b/sample-functions/HostnameIntent/handler.js index ac58f2eac0eb4dd8682b922322123d63db37fe3b..5c37fb7870def02667df29f764ec85cab27b8f51 100644 --- a/sample-functions/HostnameIntent/handler.js +++ b/sample-functions/HostnameIntent/handler.js @@ -2,21 +2,24 @@ let fs = require('fs'); let sample = require("./sample.json"); -var content = ''; -process.stdin.resume(); -process.stdin.on('data', function(buf) { content += buf.toString(); }); -process.stdin.on('end', function() { +getStdin().then(content => { + let request = JSON.parse(content); + handle(request, request.request.intent); +}); + +function tellWithCard(speechOutput) { + sample.response.outputSpeech.text = speechOutput + sample.response.card.content = speechOutput + sample.response.card.title = "Hostname"; + console.log(JSON.stringify(sample)); + process.exit(0); +} + +function handle(request, intent) { fs.readFile("/etc/hostname", "utf8", (err, data) => { if(err) { return console.log(err); } -// console.log(content); - - sample.response.outputSpeech.text = "Your hostname is: " + data; - sample.response.card.content = "Your hostname is: "+ data - sample.response.card.title = "Your hostname"; - console.log(JSON.stringify(sample)); - process.exit(0); - }); -}); - + tellWithCard("Your hostname is " + data); + }); +}; diff --git a/sample-functions/HostnameIntent/package.json b/sample-functions/HostnameIntent/package.json index 3bfc09198b8c6ca53e6164b1f852da60bd0a2397..c02111d6f438aedb2df4f78e5bf59f3bc0d97fe2 100644 --- a/sample-functions/HostnameIntent/package.json +++ b/sample-functions/HostnameIntent/package.json @@ -8,5 +8,8 @@ }, "keywords": [], "author": "", - "license": "ISC" + "license": "ISC", + "dependencies": { + "get-stdin": "^5.0.1" + } } diff --git a/watchdog/main.go b/watchdog/main.go index eed4fb0577152776da8fc69c8b4067c9246aa1c9..d22c7a5263549995bfa2c527d86ee98c8c1cb42d 100644 --- a/watchdog/main.go +++ b/watchdog/main.go @@ -13,8 +13,8 @@ import ( func main() { s := &http.Server{ Addr: ":8080", - ReadTimeout: 500 * time.Millisecond, - WriteTimeout: 1 * time.Second, + ReadTimeout: 5 * time.Second, + WriteTimeout: 5 * time.Second, MaxHeaderBytes: 1 << 20, }