Skip to content
Snippets Groups Projects
Commit 4573f14f authored by Alex Ellis's avatar Alex Ellis
Browse files

Add changecolorintent

parent 8734a3a5
No related branches found
No related tags found
No related merge requests found
fwatchdog
**/node_modules/
......@@ -116,10 +116,9 @@ func makeProxy(metrics metrics.MetricOptions) http.HandlerFunc {
len(alexaService.Request.Intent.Name) > 0 {
fmt.Println("Alexa skill detected")
invokeService(w, r, metrics, alexaService.Request.Intent.Name, requestBody)
} else {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte("Provide an x-function header."))
w.Write([]byte("Provide an x-function header or a valid Alexa SDK request."))
}
}
}
......
FROM alpine:latest
RUN apk --update add nodejs
COPY ./fwatchdog /usr/bin/
COPY package.json .
COPY handler.js .
COPY sendColor.js .
COPY sample.json .
RUN npm i
ENV fprocess="node handler.js"
CMD ["fwatchdog"]
"use strict"
let fs = require('fs');
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() {
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 = "Christmas Lights";
console.log(JSON.stringify(sample));
process.exit(0);
}
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;
}
else {
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);
});
}
\ No newline at end of file
docker build -t changecolorintent . ; docker service rm ChangeColorIntent ; docker service create --network=functions --name ChangeColorIntent changecolorintent
{
"name": "src",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"mqtt": "^2.0.1"
}
}
{
"version": "1.0",
"response": {
"outputSpeech": {
"type": "PlainText",
"text": "There's currently 6 people in space"
},
"card": {
"content": "There's currently 6 people in space",
"title": "People in space",
"type": "Simple"
},
"shouldEndSession": true
},
"sessionAttributes": {}
}
"use strict"
var mqtt = require('mqtt');
class Send {
constructor(topic) {
this.topic = topic;
}
sendIntensity(req, done) {
var ops = { port: 1883, host: "iot.eclipse.org" };
var client = mqtt.connect(ops);
client.on('connect', () => {
console.log("Connected");
let payload = req;
let cb = () => {
done();
};
client.publish(this.topic, JSON.stringify(payload), {qos: 1}, cb);
});
}
sendColor(req, done) {
var ops = { port: 1883, host: "iot.eclipse.org" };
var client = mqtt.connect(ops);
let cb = () => {
done();
};
client.on('connect', () => {
console.log("Connected");
let payload = req;
client.publish(this.topic, JSON.stringify(payload), {qos: 1}, cb);
});
}
}
module.exports = Send;
\ No newline at end of file
docker build -t hostnameintent . ; docker service rm HostnameIntent ; docker service create --network=functions --name HostnameIntent hostnameintent
......@@ -13,8 +13,8 @@ import (
func main() {
s := &http.Server{
Addr: ":8080",
ReadTimeout: 2 * time.Second,
WriteTimeout: 2 * time.Second,
ReadTimeout: 500 * time.Millisecond,
WriteTimeout: 1 * time.Second,
MaxHeaderBytes: 1 << 20,
}
......@@ -39,4 +39,3 @@ func main() {
log.Fatal(s.ListenAndServe())
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment