Search code examples
javascriptphphttpaws-lambdaalexa-skills-kit

Send a value from my website to a Lambda Function for a Amazon Echo skill


i have a problem with my code. I don't know how to continue.

I want to ask Alexa something and she should answer with the value i have on my website. What is the easiest solution for that. A HTTP Request, a API or a databank ?

This is the website where the HTTP request will be: http://plasmaboy.org/tspush.php Request Name: "value"

What i have so far:

  case "LaunchRequest":

    // Launch Request
    console.log(`LAUNCH REQUEST`)
    context.succeed(
      generateResponse(
        buildSpeechletResponse(`Welcome to my skill`, true),
        {}
      )
    )
    break;

  case "IntentRequest":
    // Intent Request
    console.log(`INTENT REQUEST`)

    switch(event.request.intent.name) {
      case "GetValueFromWebsite":
         // !!!
        // Implement the "getValueCode"
        // !!!
        })
        break;

      default:
        throw "Invalid intent"
    }

    break;

  case "SessionEndedRequest":
    // Session Ended Request
    console.log(`SESSION ENDED REQUEST`)
    break;

  default:
    context.fail(`INVALID REQUEST TYPE: ${event.request.type}`)

}

Solution

  • You can use a custom endpoint on your website instead of using an Amazon Lambda function (you can specify the endpoint you want the Alexa cloud service to send a POST request to in your Alexa Skill configuration).

    The Alexa cloud service will send your web server a POST request, which you can handle via PHP, read the value from wherever you have it on your site, and use it to send a response back to the Alexa service.

    To get started, the documentation on the structure of the request Alexa sends you is here: https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/alexa-skills-kit-interface-reference