Skip to content

Instantly share code, notes, and snippets.

@isann
Created September 14, 2018 02:46
Show Gist options
  • Save isann/6a6092af57653bc1125effc346c76646 to your computer and use it in GitHub Desktop.
Save isann/6a6092af57653bc1125effc346c76646 to your computer and use it in GitHub Desktop.
ask-sdk で非同期処理してからレスポンス ref: https://qiita.com/isann_tech/items/2cfbff4a336d0389d2db
export interface RequestHandler {
canHandle(handlerInput: HandlerInput): Promise<boolean> | boolean;
handle(handlerInput: HandlerInput): Promise<Response> | Response;
}
function execute(msg) {
return new Promise(resolve => {
setTimeout(() => {
resolve();
}, 1000);
});
}
const MyIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'MyIntent';
},
async handle(handlerInput) {
await execute('なんか非同期処理');
return handlerInput.responseBuilder
.speak('Hello My Intent')
.reprompt('Hello')
.getResponse();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment