mirror of
https://github.com/openfaas/faas.git
synced 2025-06-22 23:03:24 +00:00
Enable routing to Alexa functions
Add first Alexa-compatible function HostnameIntent
This commit is contained in:
11
sample-functions/HostnameIntent/Dockerfile
Normal file
11
sample-functions/HostnameIntent/Dockerfile
Normal file
@ -0,0 +1,11 @@
|
||||
FROM alpine:latest
|
||||
RUN apk --update add nodejs
|
||||
COPY ./fwatchdog /usr/bin/
|
||||
|
||||
COPY package.json .
|
||||
COPY handler.js .
|
||||
COPY sample.json .
|
||||
|
||||
RUN npm i
|
||||
ENV fprocess="node handler.js"
|
||||
CMD ["fwatchdog"]
|
22
sample-functions/HostnameIntent/handler.js
Normal file
22
sample-functions/HostnameIntent/handler.js
Normal file
@ -0,0 +1,22 @@
|
||||
"use strict"
|
||||
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() {
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
12
sample-functions/HostnameIntent/package.json
Normal file
12
sample-functions/HostnameIntent/package.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "HostnameIntent",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "handler.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
}
|
16
sample-functions/HostnameIntent/sample.json
Normal file
16
sample-functions/HostnameIntent/sample.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"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": {}
|
||||
}
|
Reference in New Issue
Block a user