Giter VIP home page Giter VIP logo

Comments (7)

deegles avatar deegles commented on July 20, 2024

You can initialize before you call alexa.execute() in your Lambda event handler.

For example:

var Alexa = require('alexa-sdk');
exports.handler = function(event, context) {
    var alexa = Alexa.handler(event, context);
    initialize(() => {
        alexa.execute();    
    });
}

function initialize(callback) {
    // initialize your SDK here
    callback();
}

Lambda is stateless, so two requests from a single user's session may go to different containers. You shouldn't rely on checking if the session is new if you're going to depend on the SDK on subsequent requests. You can cache your SDK after initializing to conserve resources.

from alexa-skills-kit-sdk-for-nodejs.

seanfisher avatar seanfisher commented on July 20, 2024

Yes, sorry, I should be more clear. I'm not concerned about running when the Lambda session is new, but only when a request comes in from Alexa with the session.new variable set to true. Running the code as you've shown here will run the initialize function on every new Lambda request, which is not what I'm looking for.

from alexa-skills-kit-sdk-for-nodejs.

deegles avatar deegles commented on July 20, 2024

In that case, you can easily check the new session attribute in the incoming request.

var Alexa = require('alexa-sdk');
exports.handler = function(event, context) {
    var alexa = Alexa.handler(event, context);
    initialize(event, () => {
        alexa.execute();    
    });
}

function initialize(event, callback) {
    if(event.session['new']){
        // initialize your SDK here
    }
    callback();
}

You can see the JSON interface reference here.

from alexa-skills-kit-sdk-for-nodejs.

seanfisher avatar seanfisher commented on July 20, 2024

OK, that looks like it will work, thanks. What's the relationship between the special NewSession handler and doing something like this?

from alexa-skills-kit-sdk-for-nodejs.

deegles avatar deegles commented on July 20, 2024

NewSession can be defined to have different behavior depending on the current state, or can be skipped altogether. The above would run on all requests.

from alexa-skills-kit-sdk-for-nodejs.

deegles avatar deegles commented on July 20, 2024

Just out of curiosity, what analytics SDK are you using?

from alexa-skills-kit-sdk-for-nodejs.

seanfisher avatar seanfisher commented on July 20, 2024

OK, so I ended up checking the session.new as your second example demonstrates. I'm using VoiceLabs.co for the analytics.

from alexa-skills-kit-sdk-for-nodejs.

Related Issues (20)

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.