question

newuser-c2ffc1cf-bec6-4b81-a4f2-d1ffd3531a77 avatar image
newuser-c2ffc1cf-bec6-4b81-a4f2-d1ffd3531a77 asked ·

How do I fix the "There was a problem with the requested skill's response" error?

So I am completely new to AWS and I am making an Alexa Skill that makes a GET request to a Node.js server when the user says "Alexa, ask my servant where are we dropping?" (code below), and every time the Alexa responds with "There was a problem with the requested skill's response." However, my Node server still receives the GET request, and when I just use the skills invocation name (my servant) the Alexa responds correctly. I've been trying to resolve the issue for a few hours and have not made any progress, so any help is greatly appreciated.

var https = require('https')
var http = require('http')
exports.handler = (event, context) => {
try {
	if (event.session.new) {
		// New Session
		console.log("NEW SESSION")
        }
	switch (event.request.type) {
		case "LaunchRequest":
		// Launch Request
		console.log(`LAUNCH REQUEST`)
		context.succeed(
		generateResponse(
		buildSpeechletResponse("User invoked the skill", true),
                        {}
                    )
                )
		break;
	case "IntentRequest":
		// Intent Request
		console.log(`INTENT REQUEST`)
		switch (event.request.intent.name) {
			case "launchTP":
			var endpoint="NODE SERVER LOCATION"
			var body=""
			http.get(endpoint, (response) => {
				response.on('data', (chunk) => { body+=chunk })
				response.on('end', () => {
					context.succeed(
						generateResponse(
							buildSpeechletResponse("Reinforcements are on the way", true), {}
	                                    	)
	                                )
	                            })
	                        })
				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}`)
       }
    } catch (error) { context.fail(`Exception: ${error}`) }
}
// Helpers
buildSpeechletResponse= (outputText, shouldEndSession) => {
	return {
		outputSpeech: {
			type:"PlainText",
			text:outputText
	        },
		shouldEndSession:shouldEndSession
	}
}
generateResponse= (speechletResponse, sessionAttributes) => {
	return {
		version:"1.0",
		sessionAttributes:sessionAttributes,
		response:speechletResponse
	}
}
alexa skills kitlambdahelpintentsaws
1 comment
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

So the problem is with the response. What ssml are you sending to the alexa? Can you format you code, so that it would be easier to read? From the first glance I would guess that you don't await response from http server, but I might be wrong, because it is hard to read.

1 Like 1 ·
KR avatar image
KR answered ·

Dear Rokash,

There are two ways to we need to invocate the skill

1. Using Launch request as you did

2. Using Intent request

In order to invocate your skill with a phrase which includes conditon, noun, you need to implement the lambda function with intentRequest handler

10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

KR avatar image
KR answered ·
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Amazon_Bernardo Bezerra avatar image
Amazon_Bernardo Bezerra answered ·

Hello @KR and thank you for your message.

@RokasV suggestion was on point: you are not waiting for the reply from the HTTP server.

This blog post describes the best way to collect information from an external API.

I also noticed that you are not using the V2 of the ASK SDK, which has been available since April 18. You can find plenty of sample codes on Alexa's github repository here.

Regards,
Barry

10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.