mirror of
https://github.com/openfaas/faas.git
synced 2025-06-18 12:06:37 +00:00
Change samples to use get-stdin for brevity.
This commit is contained in:
@ -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);
|
||||
});
|
||||
}
|
@ -10,6 +10,7 @@
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"get-stdin": "^5.0.1",
|
||||
"mqtt": "^2.0.1"
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
});
|
||||
|
Reference in New Issue
Block a user