From 07ee1f22d561e29b2b80ac3548446b0e8d2fdebd Mon Sep 17 00:00:00 2001
From: Alex <alexellis2@gmail.com>
Date: Fri, 3 Feb 2017 08:56:15 +0000
Subject: [PATCH] Enable turning off in sample function

---
 sample-functions/ChangeColorIntent/Dockerfile | 13 +++---
 sample-functions/ChangeColorIntent/build.sh   |  2 +-
 sample-functions/ChangeColorIntent/handler.js | 43 +++++++++++--------
 sample-functions/ChangeColorIntent/off.json   | 29 +++++++++++++
 .../ChangeColorIntent/sample_response.json    | 16 +++++++
 sample-functions/NodeInfo/main.js             |  4 +-
 6 files changed, 81 insertions(+), 26 deletions(-)
 create mode 100644 sample-functions/ChangeColorIntent/off.json
 create mode 100644 sample-functions/ChangeColorIntent/sample_response.json

diff --git a/sample-functions/ChangeColorIntent/Dockerfile b/sample-functions/ChangeColorIntent/Dockerfile
index 3abd8cdb..22aa3249 100644
--- a/sample-functions/ChangeColorIntent/Dockerfile
+++ b/sample-functions/ChangeColorIntent/Dockerfile
@@ -1,15 +1,16 @@
 FROM alpine:latest
 RUN apk --update add nodejs
 
-#ADD https://github.com/alexellis/faas/releases/download/v0.3-alpha/fwatchdog /usr/bin
-COPY ./fwatchdog /usr/bin/
+ADD https://github.com/alexellis/faas/releases/download/v0.3-alpha/fwatchdog /usr/bin
+#COPY ./fwatchdog /usr/bin/
 RUN chmod +x /usr/bin/fwatchdog
 
-COPY package.json   .
-COPY handler.js     .
-COPY sendColor.js   .
-COPY sample.json    .
+COPY package.json           .
+COPY handler.js             .
+COPY sendColor.js           .
+COPY sample_response.json   .
 
 RUN npm i
+
 ENV fprocess="node handler.js"
 CMD ["fwatchdog"]
diff --git a/sample-functions/ChangeColorIntent/build.sh b/sample-functions/ChangeColorIntent/build.sh
index 79fbc49e..9c4431fa 100755
--- a/sample-functions/ChangeColorIntent/build.sh
+++ b/sample-functions/ChangeColorIntent/build.sh
@@ -1,4 +1,4 @@
 #!/bin/bash
 
-docker build -t alexellis2/faas-alexachangecolorintent .
+docker build -t alexellis2/faas-alexachangecolorintent:latest-dev1 .
 
diff --git a/sample-functions/ChangeColorIntent/handler.js b/sample-functions/ChangeColorIntent/handler.js
index 3a5d9ce1..f51e5226 100644
--- a/sample-functions/ChangeColorIntent/handler.js
+++ b/sample-functions/ChangeColorIntent/handler.js
@@ -1,6 +1,6 @@
 "use strict"
 let fs = require('fs');
-let sample = require("./sample.json");
+let sample = require("./sample_response.json");
 let SendColor = require('./sendColor');
 let sendColor = new SendColor("alexellis.io/officelights")
 
@@ -12,6 +12,7 @@ getStdin().then(content => {
 });
 
 function tellWithCard(speechOutput) {
+  console.log(sample)
   sample.response.outputSpeech.text = speechOutput
   sample.response.card.content = speechOutput
   sample.response.card.title = "Office Lights";
@@ -20,20 +21,28 @@ function tellWithCard(speechOutput) {
 }
 
 function handle(request, intent) {
-  let colorRequested = intent.slots.LedColor.value;
-  let req = {r:0,g:0,b:0};
-  if(colorRequested == "red") { 
-    req.r = 255;
-  } else if(colorRequested== "blue") {
-      req.b = 255;
-  } else if (colorRequested == "green") {
-      req.g = 255;
+  if(intent.name == "TurnOffIntent") {
+    let req = {r:0,g:0,b:0};
+    var speechOutput = "Lights off.";
+    sendColor.sendColor(req, () => {
+      return tellWithCard(speechOutput);
+    });
+  } else {
+    let colorRequested = intent.slots.LedColor.value;
+    let req = {r:0,g:0,b:0};
+    if(colorRequested == "red") { 
+      req.r = 255;
+    } else if(colorRequested== "blue") {
+        req.b = 255;
+    } else if (colorRequested == "green") {
+        req.g = 255;
+    }
+    else {
+        return tellWithCard("I heard "+colorRequested+ " but can only do: red, green, blue.", "I heard "+colorRequested+ " but can only do: red, green, blue.");
+    }
+    sendColor.sendColor(req, () => {
+      var speechOutput = "OK, " + colorRequested + ".";
+      return tellWithCard(speechOutput);
+    });
   }
-  else {
-      return tellWithCard("I heard "+colorRequested+ " but can only do: red, green, blue.", "I heard "+colorRequested+ " but can only do: red, green, blue.");
-  }
-  sendColor.sendColor(req, () => {
-    var speechOutput = "OK, " + colorRequested + ".";
-    return tellWithCard(speechOutput);
-  });
-}
\ No newline at end of file
+}
diff --git a/sample-functions/ChangeColorIntent/off.json b/sample-functions/ChangeColorIntent/off.json
new file mode 100644
index 00000000..e7937661
--- /dev/null
+++ b/sample-functions/ChangeColorIntent/off.json
@@ -0,0 +1,29 @@
+{
+  "session": {
+    "sessionId": "SessionId.3f589830-c369-45a3-9c8d-7f5271777dd8",
+    "application": {
+      "applicationId": "amzn1.ask.skill.b32fb0db-f0f0-4e64-b862-48e506f4ea68"
+    },
+    "attributes": {},
+    "user": {
+      "userId": "amzn1.ask.account.AEUHSFGVXWOYRSM2A7SVAK47L3I44TVOG6DBCTY2ACYSCUYQ65MWDZLUBZHLDD3XEMCYRLS4VSA54PQ7QBQW6FZLRJSMP5BOZE2B52YURUOSNOWORL44QGYDRXR3H7A7Y33OP3XKMUSJXIAFH7T2ZA6EQBLYRD34BPLTJXE3PDZE3V4YNFYUECXQNNH4TRG3ZBOYH2BF4BTKIIQ"
+    },
+    "new": true
+  },
+  "request": {
+    "type": "IntentRequest",
+    "requestId": "EdwRequestId.9ddf1ea0-c582-4dd0-8547-359f71639c1d",
+    "locale": "en-GB",
+    "timestamp": "2017-01-28T11:02:59Z",
+    "intent": {
+      "name": "TurnOffIntent",
+      "slots": {
+        "LedColor": {
+          "name": "LedColor",
+          "value": "red"
+        }
+      }
+    }
+  },
+  "version": "1.0"
+}
diff --git a/sample-functions/ChangeColorIntent/sample_response.json b/sample-functions/ChangeColorIntent/sample_response.json
new file mode 100644
index 00000000..5caf707d
--- /dev/null
+++ b/sample-functions/ChangeColorIntent/sample_response.json
@@ -0,0 +1,16 @@
+{
+  "version": "1.0",
+  "response": {
+    "outputSpeech": {
+      "type": "PlainText",
+      "text": "OK, red."
+    },
+    "card": {
+      "content": "OK, red.",
+      "title": "Office Lights",
+      "type": "Simple"
+    },
+    "shouldEndSession": true
+  },
+  "sessionAttributes": {}
+}
diff --git a/sample-functions/NodeInfo/main.js b/sample-functions/NodeInfo/main.js
index fd477e6e..37ae7864 100644
--- a/sample-functions/NodeInfo/main.js
+++ b/sample-functions/NodeInfo/main.js
@@ -11,9 +11,9 @@ getStdin().then((content) => {
         console.log("Arch: " + os.arch());
         console.log("CPU count: " + os.cpus().length);
         console.log("Uptime: " + os.uptime())
-        console.log("User info: " + os.userInfo());
         if (content && content.length && content.indexOf("verbose") > -1) {
             console.log(os.cpus());
+            console.log(os.networkInterfaces());
         }
     });
-});
\ No newline at end of file
+});
-- 
GitLab