Alexa Skill Set - context.succeed not getting executed from AWS lambda(nodejs)

Demyan Borya

I have made a "http.get" request from lambda function and am using the response for constructing the reply back to ASK.

In the below code - in switch case "GetName" context.succeed is never called while in switch case "GetNameParameter" context.succeed is successfully executed. Is the some problem due to "http.get" request of "GetName"? How to resolve this.

Whenever I add "http.get" request, the context.succeed method does not work and hence I cannot get alexa working.

Could anybody help in getting the problem solved.

Following is my code:

var http = require('http');
exports.handler = (event, context, callback) => {
    // TODO implement
    if(event.session.new){
      console.log("NEW SESSION");
    }
    switch(event.request.type){
      case "LaunchRequest":
      console.log("LAUNCH REQUEST");

      context.succeed(
                  generateResponse(
                    buildSpeechletResponse("Welcome", true),
                    {}
                  )
                );

      break;

      case "IntentRequest":
        console.log("IntentRequest");

        switch(event.request.intent.name){

          case "GetName":

              var endpoint = //endpoint

            var body = ""
            http.get(endpoint, (response) => {
              response.on('data', (chunk) => { body += chunk })
              response.on('end', () => {
                var data = JSON.parse(body)
                var name = data.name
                console.log("Name: "+name);

                //Not getting executed
                context.succeed(
                  generateResponse(
                    buildSpeechletResponse(`Name is ${data}`, true),
                    {}
                  )
                )
              })
            })
            break;

          case "GetNameParameter":

            context.succeed(
                    generateResponse(
                      buildSpeechletResponse("OK, Name is "+event.request.intent.slots.Name.value, true),
                      {}
                    )
                  );
            break;

        }

      break;

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

      default:
        context.fail(`INVALID REQUEST TYPE: ${event.request.type}`);
    }
    callback(null, 'Hello from Lambda');
};

buildSpeechletResponse = (outputText, shouldEndSession) => {

  return {
    outputSpeech: {
      type: "PlainText",
      text: outputText
    },
    shouldEndSession: shouldEndSession
  };

};

generateResponse = (speechletResponse, sessionAttributes) => {

  return {
    version: "1.0",
    sessionAttributes: sessionAttributes,
    response: speechletResponse
  };

};
Demyan Borya

I got it, callback was causing the problem.

Commented "callback(null, 'Hello from Lambda');" and problem was solved.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Alexa not finding my Skill

Amazon alexa skill development

Alexa skill kit vs Alexa Voice Service

Amazon Polly in Alexa Skill?

Alexa, get skill from LaunchRequest Intent

Trigger Alexa notifications from Alexa skill lambda?

Creating an Alexa conversational skill using AWS

Alexa smarthome skill routines

Getting null responce from Alexa skill using Lambda

Alexa Skill: is it possible to pause and resume the skill programmatically?

Alexa Skill: is it possible to have Alexa play a .mp3 from Alexa Developer Console - Alexa Hosted?

Debugging "read time out" for AWS lambda function in Alexa Skill

What to answer an AWS Lambda when answering Alexa Smart Home Skill asynchronous via event gateway?

Alexa skill Rest API

Alexa Media Playback Skill

Unable to set the endpoint for Alexa skill

Can you prevent users from reviewing your Alexa Skill?

Adding a simple alexa skill, doable in time? getting started with alexa

Custom Alexa Skill Alexa thinks "this year" is "this week"

Alexa skill accessing data from inside the company network

Alexa skill for asking questions

Using sessionAttributes in Alexa Skill

Simple Alexa skill with logging

Can i use Alexa skill Reminder API and Proactive events API without AWS lambda?

Alexa skill that uses data from an external API with API-KEY

Alexa skill development

Alexa Skill with Google OAuth

Connecting to external Mysql database from AWS lambda (back end of Alexa skill) returns "Access denied for user" message

How to use BearerToken received from Alexa Smart Home Skill Directive to identify the user email and profile using AWS Lambda with NodeJS?