Giter VIP home page Giter VIP logo

alexa-sdk-nodejs-openfaas-example's Introduction

alexa-sdk-nodejs-openfaas-example

Example of Alexa SDK with Node.js and OpenFaaS

Example

William is a skill which is based upon the Hello World of the Alexa SDK for Node.js

Create your skill

  • Create a Custom Skill
  • Use a HTTPS URL with your OpenFaaS gateway URL and the function name:
https://my-openfaas.com/function/william-skill

If you don't want to setup your own TLS for your OpenFaaS server, or if it's behind a firewall then use the ngrok to create a tunnel with HTTPS.

Setup your intent

Go to the JSON editor and paste in the following:

{
    "interactionModel": {
        "languageModel": {
            "invocationName": "william",
            "intents": [
                {
                    "name": "AMAZON.FallbackIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.CancelIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.HelpIntent",
                    "samples": [
                        "what can I say"
                    ]
                },
                {
                    "name": "AMAZON.StopIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.NavigateHomeIntent",
                    "samples": []
                },
                {
                    "name": "HelloWorldIntent",
                    "slots": [],
                    "samples": [
                        "hi",
                        "hello there"
                    ]
                }
            ],
            "types": []
        }
    }
}
  • Now click Save Model
  • Finally click Build Model

Deploy William

  • Now edit william/stack.yml and replace "alexellis2" for your own Docker Hub username

  • Pull the node10-express template:

faas-cli template store pull node10-express
  • Deploy William via the william-skill function
faas-cli up

Ask William a question

You can now ask William a question in the AWS Alexa console:

ask william hello

And here's the result!

Extend the example

See if you can get William to say Hello in another language such as German: Hallo!

Now edit the HelloWorldIntentHandler in william-skill/handler.js and run faas-cli up

Adapting the Skills SDK to the node10-express handler

Adapting the Skills SDK to the OpenFaaS node10-express template handler was simply a case of wrapping the handler. Your mileage may vary, and you may need to perform additional tweaks.

module.exports = function(event, context) {

  const skillHandler = skillBuilder
  .addRequestHandlers(
    LaunchRequestHandler,
    HelloWorldIntentHandler,
    HelpIntentHandler,
    CancelAndStopIntentHandler,
    SessionEndedRequestHandler
  )
  .addErrorHandlers(ErrorHandler)
  .lambda();

  skillHandler(event.body, context, function(err, res) {
    console.log(err, res);

    context.status(200).succeed(res);
  });

}

For additional help please see the Alexa SDK documentation.

alexa-sdk-nodejs-openfaas-example's People

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.