Tuesday 6 June 2017

How to interactively authenticate the custom skills in Amazon Alexa without linking to any account?

I'm new to building the Alexa Skills. I have built one custom skill that written weather updates when someone asked like "Hey Alexa, Give me weather updates for zip code 75252". Now I want to authenticate this service. Whenever user invokes the skill, It should give a welcome message and ask for the pin. When the user responds with a valid pin then only he should allow accessing the weather updates. My customer skills invocation MyWeatherUpdate is A kind of conversion I want to implement is as follows:

Me: Hey Alexa, MyWeatherUpdate Alexa: Wellcome user, Please say your pin Me: Give me weather updates for zip code 75252 Alexa: Please say your pin to access this service Me: Pin is 1234 Alexa: You have successfully validated your pin. Now you can check the weather updates Me: Give me weather updates for zip code 75252 Alexa: Temperature is 82 degrees F.

My Current Code in Lambda in NodeJS:

exports.handler = (event, context, callback) => {
 switch(event.request.type){
        case 'LaunchRequest':
            onLaunch(event.request,
            event.session,
            (sessionAttributes, speechletResponse) => {
                callback(null, buildResponse(sessionAttributes, speechletResponse));
            });
            break;
        case 'IntentRequest':
            onIntent(event.request,
            event.session,
            (sessionAttributes, speechletResponse) => {
                callback(null, buildResponse(sessionAttributes, speechletResponse));
            });
            break;
        case 'SessionEndedRequest':
            onSessionEnded(event.request, event.session);
            callback();
            break;
    }

};

function onIntent(intentRequest, session, callback) {
console.log(`onIntent requestId=${intentRequest.requestId}, sessionId=${session.sessionId}`);
const intent = intentRequest.intent;
const intentName = intentRequest.intent.name;
switch(intentName) {
        case "MyNLG":
              getCompanyInfo(intent, session, callback);
              break;
        case "AMAZON.HelpIntent":
            getWelcomeResponse(callback);
            break;
        case "GoodByeNLG" :
            handleSessionEndRequest(callback);
            break;          
        case "WeatherUpdates" : 
            getWeatherUpdates(intent, session, callback);
            break;
        default:
            throw new Error('Invalid intent');
    }

}

Can anyone please guide me any references to resolve this solution. I searched online but most of the link are related to linking with another app or purchase service using Alexa.



via Gaurav Dhavale

No comments:

Post a Comment