alexa-skills-kit-sdk-for-nodejs: Cannot be used with API gateway
I’m submitting a…
[ ] Regression (a behavior that used to work and stopped working in a new release)
[X ] Bug report
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Other... Please describe:
Expected Behavior
I should get a successful response from api gateway.
Current Behavior
In the simulator, I’m getting a “There was a problem with the requested skill’s response” response, and when looking at the device log, I’m seeing "invocationResponse": null,
Possible Solution
No idea
Steps to Reproduce (for bugs)
create a simple skill with a launch request handler, and wire it with an API gateway. (I used SAM)
const LaunchRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
},
handle(handlerInput) {
const speechText = 'Thank you for contacting us. How can I help you today?';
console.log(handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.withSimpleCard(speechText)
.getResponse());
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.withSimpleCard(speechText)
.getResponse();
},
};
I’ve fixed the handlerInput by changing
return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
to
return handlerInput.requestEnvelope.body.request.type === 'LaunchRequest';
but I cannot seem to get the response back to the alexa simulator.
What have you tried:
return {
statusCode: 200,
body: JSON.stringify(handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.withSimpleCard(speechText)
.getResponse())
}; // got same outcome
handle(handlerInput, context, callback)
...
callback(null, {
statusCode: 200,
body: JSON.stringify(handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.withSimpleCard(speechText)
.getResponse())
}); //undefined method callback
Context
I need to be able to talk to the skill behind an API gateway.
Your Environment
- ASK SDK for Node.js used: x.x.x “ask-sdk-core”: “^2.0.3”, “ask-sdk-model”: “^1.2.0”
- Operating System and version: Windows 10
Node.js and NPM Info
- Node.js version used for development: 8.9.3
- NPM version used for development: 5.6.0
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 18 (6 by maintainers)
HI all,
Sorry for the late reply.
ResponseBuilder.getResponse
only returns theresponse
part of the full skill response. You can find the full response format here. SDK wraps the object returned fromResponseBuilder
into the full response for you after the request handler returns. To put it in an example.skill.invoke(event)
is expecting theevent
to conform with the expect request format as shown here. If you set up the API gateway with lambda custom integration as proxy, theevent
passed in lambda handler will contain the full http request as shown here. In this case, you need to pass in the body of the request as it contains the actual request envelope. see below:Also, the api gateway expects the output of lambda to follow the format as shown here. Note that the body needs to be a string not a json object.
Regards,
No, when we say API Gateway, we mean when you setup a skill to use HTTP instead of lambda, and use the API Gateway as a lambda proxy, the “body” of the response is empty.
Attached above is the code snippet of a working sample that uses API Gateway with Lambda proxy setting enabled.
@tianrenz @ask-sdk any updates?
@tianrenz @ask-sdk This is a SAM project. I had to change how we got the incoming body from the docs, which makes me think how the result is being returned isn’t formatted properly for API Gateway
index.js
alexa-skill.js
assistant.yml
That doesn’t help me. The return from the handler is an invalid format for api gateway. Just put the lambda behind an api gateway and hit it from the Alexa skill builder “test” and you’ll see what issues I’m having.
On Fri, May 11, 2018, 5:27 PM Tianren Zhang notifications@github.com wrote: