[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report
[ ] Performance issue
[ ] Feature request
[x] Documentation issue or request
[ ] Other... Please describe:
Could you please create an example Alexa skill that's built as an express app, which shows how to pass request / context to handlers and how to verify the signature, instead of a lambda-only example? I'm dependent upon using Express to power my Skill (handling incoming https requests). So, it'd be helpful to see a best practices for building a skill this way.
skill = Alexa.SkillBuilders.custom().addRequestHandlers(
...
)
.addErrorHandlers(ErrorHandler)
.create();
try {
await new expressAdapter.SkillRequestSignatureVerifier().verify(textBody, requestHeaders);
await new expressAdapter.TimestampVerifier().verify(textBody);
} catch (err) {
// server return err message
}
skill.invoke(req.body)
.then(function(responseBody) {
res.json(responseBody);
})
.catch(function(error) {
console.log(error);
res.status(500).send('Error during the request');
});
What does it mean: "This code snippet assumes you have already consumed the request body as text and headers"??
I'm trying to integrate a new skill with V2 SDK in my Express app executed on a node server.
Hey @lucidokr , thanks for raising the issue. We have a backlog item for this request and will provide you with a code sample soon.
One issue I had trouble with the adaptor is that my boilerplate express app had app.use(bodyParser.json());
which caused a error in the first of the three request handlers pushed onto the array in the adaptor. A note to not add this middleware before adding the request handlers should be included.
Hi @lucidokr
Thanks for being patience and using our new ExpressAdapter package ! Your request is reasonable and we will work on sample skills in near future.
To answer your question: if you are using express and try to build an express app, you can ignore this part as it shows how to use SignatureVerifier and TimeStampVerifier without express. For user who don't use express, they cannot directly use our adapter class and need to figure out a way to parse the request body and request Header themselves. Therefore, for your case you just need to follow this tab. Please be aware don't use any other middleware before adding the request handlers just as @sjames1958gm mentioned.
Let me know if you met any problems while using our SDK !
Thanks,
Shen
Hi @sjames1958gm ,
Thanks for reaching out. And yes you're right, as you can see in our code base, the express adapter will send error response if other middleware is registered before the handler. Due to your report, I think only a error response might not be enough. I will reach out to the doc team to update our doc to avoid similar issues in the future.
Thanks,
Shen
Hey there,
I just created a little repo with an example. Hope this helps!
Most helpful comment
Hi @sjames1958gm ,
Thanks for reaching out. And yes you're right, as you can see in our code base, the express adapter will send error response if other middleware is registered before the handler. Due to your report, I think only a error response might not be enough. I will reach out to the doc team to update our doc to avoid similar issues in the future.
Thanks,
Shen