promisify answer on user defined question

This commit is contained in:
GotPPay
2018-03-30 12:08:38 +02:00
parent f163dde5b2
commit 0ebadcd3f7
2 changed files with 25 additions and 9 deletions

View File

@@ -71,22 +71,38 @@ module.exports = {
if (this.attributes['LaunchRequestYesNo']) {
this.attributes['LaunchRequestYesNo'] = false;
}
let answer = '';
let answer;
switch (intent.answerType){
case constants.answerType.PREDEFINED:
answer = intent.answer;
answer = new Promise((resolve,reject)=>{
resolve(intent.answer);
});
break;
case constants.answerType.EXTERNAL_SOURCE_WP_JSON:
answer = predefinedSourceHelper.getAnswerFromWP(intent.externalAnswerSource);
predefinedSourceHelper.getAnswerFromWP(intent.externalAnswerSource).then(answer=>{
answer = new Promise((resolve,reject)=>{
resolve(answer);
});
}).catch(error=>{
reject(error);
});
break;
case constants.answerType.EXTERNAL_SOURCE_RSS:
answer = 'Not implemented yet'
break;
}
this.response
.speak (answer)
.listen (constants.voiceResponseStrings.GENERIC_CONTINUE); //Phrase from listen doesn't work !!!
this.emit (':responseReady');
answer.then(answer=>{
this.response
.speak (answer)
.listen (constants.voiceResponseStrings.GENERIC_CONTINUE); //Phrase from listen doesn't work !!!
this.emit (':responseReady');
}).catch(error=>{
this.response
.speak (error)
.listen (constants.voiceResponseStrings.GENERIC_CONTINUE); //Phrase from listen doesn't work !!!
this.emit (':responseReady');
});
};
});