Alexa-skills-kit-sdk-for-nodejs: Best way to register async handler

Created on 24 Nov 2017  路  4Comments  路  Source: alexa/alexa-skills-kit-sdk-for-nodejs

Hi,

I am working on alexa and i have multiple intent handler and all the intent handler is asynchronous. What is the best way to register async handler as sometime i am getting unhandled promise rejection . This is how my handler class look like

`export default {
LaunchRequest: function() {
this.emit("AMAZON.HelpIntent");
},
getTask: function() {
// try {
sessionHandler.call(this, getTask)
},
getTaskDetail: function() {
// try {
sessionHandler.call(this, getTaskDetail)
},
getPersonalDetail: function() {
sessionHandler.call(this, getPersonalDetail);
},
ValidateSession: function() {
try {
ValidateSession.call(this);
} catch (error) {

  this.emit(":tell", speech.unhandledError);
}

}
}; getTask and getPersonalDetail are async implementation which is like this module.exports = async function() {
//Business logic

}`

Most helpful comment

Was there any progress this? I would like to "await" within the handle function.

All 4 comments

Hi, @roshancsc,
All handler functions are synchronized. Are you trying to set the response inside an async function? Can you set the response inside a then() callback and also have a catch() function to handler the error.

Thanks @TianTXie for the response I implemented the way you mentioned but it would be a good to have feature where package can register asynchronous handler. It would give a nice abstraction as most of the alexa skill would require database or webservice access.

@roshancsc ,
Thanks for your suggestions. We are currently in the process of redesigning the sdk. Your ideas are very illuminating. We will keep them in mind and try to solve those complications in the new design. Stay tuned!

Was there any progress this? I would like to "await" within the handle function.

Was this page helpful?
0 / 5 - 0 ratings