alexa / alexa-skills-kit-sdk-for-nodejs

The Alexa Skills Kit SDK for Node.js helps you get a skill up and running quickly, letting you focus on skill logic instead of boilerplate code.
Apache License 2.0
3.12k stars 737 forks source link

Just start learning coding again, but still don't Understand some of the code. #233

Closed 25kcdiez closed 6 years ago

25kcdiez commented 6 years ago

onIntent: function (intentRequest, session, response) { var intent = intentRequest.intent, intentName = intentRequest.intent.name, intentHandler = this.intentHandlers[intentName]; if (intentHandler) {

    console.log('dispatch intent = ' + intentName);       //the 'dispatch intent ='

    intentHandler.call(this, intent, session, response);//and the call 
} else {
    throw 'Unsupported intent = ' + intentName;
}

},

AlexaSkill.prototype.intentHandlers = {};

AlexaSkill.prototype.execute = function (event, context) { try { console.log("session applicationId: " + event.session.application.applicationId);

    // Validate that this request originated from authorized source.
    if (this._appId && event.session.application.applicationId !== this._appId) {
        console.log("The applicationIds don't match : " + event.session.application.applicationId + " and "
            + this._appId); // also it is the same code every time?
        throw "Invalid applicationId";
    }

    if (!event.session.attributes) {
        event.session.attributes = {};
    }

    if (event.session.new) {
        this.eventHandlers.onSessionStarted(event.request, event.session);
    }

    // Route the request to the proper handler which may have been overriden.
    var requestHandler = this.requestHandlers[event.request.type];
    requestHandler.call(this, event, context, new Response(context, event.session));
} catch (e) {
    console.log("Unexpected exception " + e);
    context.fail(e);
}

};

allthepies commented 6 years ago

Is there a question ?

tianrenz commented 6 years ago

Hi @25kcdiez, Is there a specific part that you need help with?

25kcdiez commented 6 years ago

Tianrenz thanks for the reply man and sorry for the late reply..

so I solve it by my self and thank's for the support tianrenz.

Just one more thing what thus this code do?

this._context() "_context".

tianrenz commented 6 years ago

@25kcdiez it passes the context parameter from Lambda function to your handler