Javascript 如何在Alexa Skill中重新启动对话框
我有一个新的ContactIntent,用户在其中输入诸如名字和手机号码等数据。我希望他能够在任何时候重新启动对话框。因此,我有一个restartinent,因此当用户说“Restart”时,restartinentandler处理请求并将其转发回NewContactIntent。代码如下:Javascript 如何在Alexa Skill中重新启动对话框,javascript,node.js,alexa,alexa-skills-kit,alexa-skill,Javascript,Node.js,Alexa,Alexa Skills Kit,Alexa Skill,我有一个新的ContactIntent,用户在其中输入诸如名字和手机号码等数据。我希望他能够在任何时候重新启动对话框。因此,我有一个restartinent,因此当用户说“Restart”时,restartinentandler处理请求并将其转发回NewContactIntent。代码如下: const NewContactIntentHandler = { canHandle(handlerInput) { return handlerInput.requestEnve
const NewContactIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'NewContactIntent';
},
handle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
const currentIntent = handlerInput.requestEnvelope.request.intent;
if (request.dialogState !== 'COMPLETED') {
return handlerInput.responseBuilder
.addDelegateDirective(currentIntent)
.getResponse();
} else {
const speechText = 'Kontakt hinzugefügt.';
return handlerInput.responseBuilder
.speak(speechText)
.getResponse();
}
}
};
const RestartIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& (handlerInput.requestEnvelope.request.intent.name === 'RestartIntent');
},
handle(handlerInput) {
return NewContactIntentHandler.handle(handlerInput);
}
};
它不起作用,当我尝试它时,alexa说来自ErrorHandler的错误消息
编辑
本例有效,BarHandler调用FooHandler,因此我不明白我的案例为何无效:
const FooIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'FooIntent';
},
handle(handlerInput) {
const speechText = 'Ich bin FooIntent!';
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.getResponse();
}
};
const BarIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'BarIntent';
},
handle(handlerInput) {
return FooIntentHandler.handle(handlerInput);
}
};
我可以想出两种可能的解决方案: 1)在NewContactIntent中添加诸如“重新启动”、“重新启动”之类的语句,当用户说重新启动时,对话框将自动从头开始。 2)添加另一个重启意图,但不要在NewContactIntent的canHandle函数中编写单独的处理程序
const NewContactIntentHandler={
canHandle(handlerInput){
return handlerInput.requestEnvelope.request.type==='IntentRequest'
&&(handlerInput.requestEnvelope.request.intent.name==='NewContactIntent'
||handlerInput.requestEnvelope.request.intent.name==='RestartIntent')
},
我可以想到两种可能的解决方案:
1)在NewContactIntent中添加诸如“重新启动”、“重新启动”之类的语句,当用户说重新启动时,对话框将自动从头开始。
2)添加另一个重启意图,但不要在NewContactIntent的canHandle函数中编写单独的处理程序
const NewContactIntentHandler={
canHandle(handlerInput){
return handlerInput.requestEnvelope.request.type==='IntentRequest'
&&(handlerInput.requestEnvelope.request.intent.name==='NewContactIntent'
||handlerInput.requestEnvelope.request.intent.name==='RestartIntent')
},
添加“重新启动”语句
如果您只有一个意图,则可以添加“重新启动”或“重置”作为话语,并从一开始就启动对话框
<强>问题:< /强>但如果您有两个重置意图,则发声<强>“重置”< /强>将触发其中任何一个。即使您在<>代码> iTnuts<代码>的中间,然后说“强”>“重置”< /强>,它可能触发<代码>智能B > /代码>,它还具有<强>“重置”< /强>发音。
添加重新启动内容 添加一个restartinent
语句,如“reset”或“restart”肯定会触发restartinent
,在sessionAttribute
的帮助下,如lastDialogIntent
将帮助您了解要重新启动的对话框
问题:对话框模型的问题是,您无法获取与当前意图不同的插槽。这意味着当您说“重新启动”时,Alexa将触发重新启动内容
,并且您无法用要重置的意图的对话框指令
作出响应
请注意,返回对话框指令时不能更改意图,
因此,意图名称和插槽集必须与发送到您的
技巧
棘手的部分是,用户必须再次从restartinent(比如IntentA
)中说出一些将触发所需意图的话
Ex:
User: I want to buy a car [triggered BuyCarIntent]
Alexa: Which color do you want? [first slot to be filled]
User: I want yellow color. [First slot filled]
Alexa: Which is your preferred make?
User: restart [triggred RestartIntent]
Alexa: okay, what color do you want? [make the user respond in such a way that the user
speech will trigger the required intent again.]
User: I want yellow color. [triggered BuyCarIntent]
如果用户只说“黄色”,根据交互模型的设计,有时可能不会触发意图。请调整交互模型并添加有助于实现此目的的语句
以这样一种方式响应,即用户会说一些将再次触发意图的话。利用会话属性
存储和检索上次使用的对话框意图,例如:“lastDialogIntent”:“BuyCarIntent”
以与意图匹配的适当问题进行响应
一旦被触发,对话框模型将从头开始。添加“重新启动”语句
如果您只有一个意图,则可以添加“重新启动”或“重置”作为话语,并从一开始就启动对话框
<强>问题:< /强>但如果您有两个重置意图,则发声<强>“重置”< /强>将触发其中任何一个。即使您在<>代码> iTnuts<代码>的中间,然后说“强”>“重置”< /强>,它可能触发<代码>智能B > /代码>,它还具有<强>“重置”< /强>发音。
添加重新启动内容 添加一个restartinent
语句,如“reset”或“restart”肯定会触发restartinent
,在sessionAttribute
的帮助下,如lastDialogIntent
将帮助您了解要重新启动的对话框
问题:对话框模型的问题是,您无法获取与当前意图不同的插槽。这意味着当您说“重新启动”时,Alexa将触发重新启动内容
,并且您无法用要重置的意图的对话框指令
作出响应
请注意,返回对话框指令时不能更改意图,
因此,意图名称和插槽集必须与发送到您的
技巧
棘手的部分是,用户必须再次从restartinent(比如IntentA
)中说出一些将触发所需意图的话
Ex:
User: I want to buy a car [triggered BuyCarIntent]
Alexa: Which color do you want? [first slot to be filled]
User: I want yellow color. [First slot filled]
Alexa: Which is your preferred make?
User: restart [triggred RestartIntent]
Alexa: okay, what color do you want? [make the user respond in such a way that the user
speech will trigger the required intent again.]
User: I want yellow color. [triggered BuyCarIntent]
如果用户只说“黄色”,根据y的设计,有时可能不会触发意图