Javascript Alexa Skills:如何在本例中插入AMAZON.yesint和AMAZON.noContent?
Alexa skill提供有关平装书或在线书籍的信息。这只是一个例子,不是真实的例子。下面是一个例子 用户:“Alexa,找一位作者写的最好的书。” 亚历克斯:“好吧!这是一本书,诸如此类。” 你想再听一遍吗 用户:“是的!” 重复同样的信息。 我想知道如何实现代码,让Alexa回答“是/否”问题,并重复所说的内容。我对此做了广泛的研究,但我还是不明白。顺便说一句,我是新手Javascript Alexa Skills:如何在本例中插入AMAZON.yesint和AMAZON.noContent?,javascript,alexa,alexa-skills-kit,alexa-skill,alexa-app,Javascript,Alexa,Alexa Skills Kit,Alexa Skill,Alexa App,Alexa skill提供有关平装书或在线书籍的信息。这只是一个例子,不是真实的例子。下面是一个例子 用户:“Alexa,找一位作者写的最好的书。” 亚历克斯:“好吧!这是一本书,诸如此类。” 你想再听一遍吗 用户:“是的!” 重复同样的信息。 我想知道如何实现代码,让Alexa回答“是/否”问题,并重复所说的内容。我对此做了广泛的研究,但我还是不明白。顺便说一句,我是新手 'booksIntent': function () { var speechOutput = '';
'booksIntent': function () {
var speechOutput = '';
var speechReprompt = '';
var sourceSlot = resolveCanonical(this.event.request.intent.slots.source);
console.log('User requested source: ' + sourceSlot);
var authorSlot = resolveCanonical(this.event.request.intent.slots.author);
console.log('User requested author: ' + authorSlot);
var sources = {
'basic book' : {
'one author' : "Blah blah one author",
'two authors' : "Blah blah two authors",
'multiple authors' : "blah blah multiple authors"
},
'basic electronic' : {
'one author' : "Blah blah...some electronic information"
},
}
var authors = [
'one author',
'two authors',
'multiple authors'
];
var source =sourceSlot.toLowerCase();
if(sourceSlot && sources[source]){
var standardSource = '';
var author = 'one author'; //default author choice
if(authorSlot && author.indexOf(authorSlot) - 1){
author = authorSlot;
}
var getSource = sources[source][author];
speechOutput = 'Ok! ' + getSource;
speechReprompt= 'Would you like to hear this again?'; //I want the user to answer with a yes or no and the program to respond accordingly.
}
else{
speechOutput = 'Sorry, the information you asked is not supported yet'
speechReprompt = 'I support: this and that!'
}
this.emit(":ask", speechOutput, speechReprompt)
},
首先,您应该更新AlexaSDK的版本 您可以通过使用状态来解决是、否意图 例如,在返回语音输出之前,可以存储下一步要转到的状态 使用属性存储状态和所有内容
attributes.state ="YES_MODE"
是的
您应该检查该状态是否匹配,然后允许执行该操作
代码如下:
attributes.data = "You can store the data. What you want to repeat"
attributes.state = "YES_MODE"
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(repromptText)
.getResponse();
出于是的意图:
const YesIntentHandler = {
canHandle(handlerInput) {
const attributes = handlerInput.attributesManager.getSessionAttributes();
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'AMAZON.YesIntent'
&& attributes.state === "YES_MODE";
},
handle(handlerInput) {
const attributes = handlerInput.attributesManager.getSessionAttributes();
let data = attributes.data
//write your logic
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(repromptText)
.getResponse();
},
};
你最后是怎么解决的?