Simple Amazon Echo / Alexa Response Example Flow

This flow allows Alexa's custom skills to be deployed on Node-RED and Bluemix.

Since one of the requirements for hosting your own custom skills set outside of Lambda or AWS is that the service must support HTTP over SSL/TLS. And when hosting your applications on Bluemix, it comes with it.

For more info on the Alexa requirements, please refer to the following link: https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/developing-an-alexa-skill-as-a-web-service

Description

In this sample flow, Alexa will echo back what is being said. If there's a need to do anything to the message sent to Alexa, it can be easily done on the Do Something function node. You can either replace it with something else, such as a http request node or modify the message on that function node.

The Extract User function node can be used to match the userId with a known user database in case you would like to know what is the name of the requestor.

If you have configured different kinds of intents, you may add more output to the switch node accordingly.

Alexa Configuration

On your Alexa configuration, you need to select HTTPS as the Service Endpoint Type and the url should be https://your-bluemix-hostname.mybluemix.net/alexa

Alexa Interaction Model

Intent Schema:

{
  "intents": [{
      "intent": "RawText",
      "slots": [{
          "name": "Text",
          "type": "AMAZON.LITERAL"
      }]
  }]
}

Sample Utterances:

RawText {Put any text here that you think will be used on your chatbot|Text}
RawText {I think the world is flat|Text}
RawText {Hello, World|Text}
RawText {See you later alligator|Text}
RawText {maybe next time|Text}

Node-RED Flow

[
    {
        "id": "1dc3f3e8.a0a8fc",
        "type": "http in",
        "z": "e44c3f95.73fa2",
        "name": "/alexa",
        "url": "/alexa",
        "method": "post",
        "swaggerDoc": "",
        "x": 70,
        "y": 40,
        "wires": [["ca814964.bbca38","6392461e.325178"]]
    },
    {
        "id": "78041999.53bad8",
        "type": "function",
        "z": "e44c3f95.73fa2",
        "name": "Extract Message",
        "func": "var message = \"\";\nif (msg.payload.request.intent && msg.payload.request.intent.slots)\n    message = msg.payload.request.intent.slots.Text.value\n\nmsg.text = message;\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 430,
        "y": 140,
        "wires": [["7b3e92ef.9165cc"]]
    },
    {
        "id": "a9e9bd88.5d14c",
        "type": "switch",
        "z": "e44c3f95.73fa2",
        "name": "",
        "property": "payload.request.type",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "LaunchRequest",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "IntentRequest",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "SessionEndedRequest",
                "vt": "str"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "outputs": 4,
        "x": 190,
        "y": 140,
        "wires": [
            ["1641c37c.4d1c8d"],
            ["78041999.53bad8"],
            ["84f687ad.387e58"],
            ["84f687ad.387e58"]
        ]
    },
    {
        "id": "84f687ad.387e58",
        "type": "function",
        "z": "e44c3f95.73fa2",
        "name": "End Session Message",
        "func": "msg.payload = {\n  \"response\": {\n    \"outputSpeech\": {\n      \"type\": \"SSML\",\n      \"ssml\": \"<speak> Thank you for using Chatbot and have a nice day! </speak>\"\n    },\n    \"shouldEndSession\": true\n  },\n}\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 620,
        "y": 200,
        "wires": [["4d9a56e4.9c7578"]]
    },
    {
        "id": "1641c37c.4d1c8d",
        "type": "function",
        "z": "e44c3f95.73fa2",
        "name": "Start Session Message",
        "func": "msg.payload = {\n    \"version\": \"1.0\",\n    \"response\": {\n        \"outputSpeech\": {\n            \"type\": \"SSML\",\n            \"ssml\": \"<speak> Hi. Welcome to the Chatbot! </speak>\"\n        },\n        \"shouldEndSession\": false\n    },\n}\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 610,
        "y": 80,
        "wires": [["4d9a56e4.9c7578"]]
    },
    {
        "id": "ca814964.bbca38",
        "type": "function",
        "z": "e44c3f95.73fa2",
        "name": "Extract User",
        "func": "msg.userId = msg.payload.session.user.userId;\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 130,
        "y": 80,
        "wires": [["a9e9bd88.5d14c"]]
    },
    {
        "id": "4d9a56e4.9c7578",
        "type": "http response",
        "z": "e44c3f95.73fa2",
        "name": "",
        "x": 1130,
        "y": 140,
        "wires": []
    },
    {
        "id": "5d942366.7ce6ac",
        "type": "function",
        "z": "e44c3f95.73fa2",
        "name": "Parse Message To Alexa",
        "func": "msg.payload = {\n  \"version\": \"1.0\",\n  \"response\": {\n    \"outputSpeech\": {\n      \"type\": \"SSML\",\n      \"ssml\": \"<speak> \"  + msg.text + \" </speak>\"\n    },\n    \"reprompt\": {\n      \"outputSpeech\": {\n        \"type\": \"SSML\",\n        \"ssml\": \"<speak> \"  + msg.text + \" </speak>\"\n      }\n    },\n    \"shouldEndSession\": false\n  }\n}\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 830,
        "y": 140,
        "wires": [["4d9a56e4.9c7578"]]
    },
    {
        "id": "7b3e92ef.9165cc",
        "type": "function",
        "z": "e44c3f95.73fa2",
        "name": "Do Something",
        "func": "\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 620,
        "y": 140,
        "wires": [["5d942366.7ce6ac"]]
    },
    {
        "id": "6392461e.325178",
        "type": "debug",
        "z": "e44c3f95.73fa2",
        "name": "",
        "active": false,
        "console": "false",
        "complete": "false",
        "x": 230,
        "y": 40,
        "wires": []
    }
]
psyntium

Flow Info

created 7 months, 2 weeks ago

Node Types

Core
  • debug (x1)
  • function (x6)
  • http in (x1)
  • http response (x1)
  • switch (x1)

Tags

  • alexa
  • amazon
  • https
  • echo
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option