[英]How to get and use confirmation 'yes' or 'no' for Alexa skill intent response
我正在開發一項 Alexa 技能,該技能在啟動時會詢問Do you want to perform something?
根據用戶的回復'yes'
或'no'
我想啟動另一個意圖。
var handlers = {
'LaunchRequest': function () {
let prompt = this.t("ASK_FOR_SOMETHING");
let reprompt = this.t("LAUNCH_REPROMPT");
this.response.speak(this.t("WELCOME_MSG") + ' ' + prompt).listen(reprompt);
this.emit(':responseReady');
},
"SomethingIntent": function () {
//Launch this intent if the user's response is 'yes'
}
};
我確實看過dialog model
,它似乎可以達到目的。 但我不確定如何實施。
從技能中尋找所需內容的最簡單方法是處理您的技能中的AMAZON.YesIntent
和AMAZON.NoIntent
(確保也將它們添加到交互模型中):
var handlers = {
'LaunchRequest': function () {
let prompt = this.t("ASK_FOR_SOMETHING");
let reprompt = this.t("LAUNCH_REPROMPT");
this.response.speak(this.t("WELCOME_MSG") + ' ' + prompt).listen(reprompt);
this.emit(':responseReady');
},
"AMAZON.YesIntent": function () {
// raise the `SomethingIntent` event, to pass control to the "SomethingIntent" handler below
this.emit('SomethingIntent');
},
"AMAZON.NoIntent": function () {
// handle the case when user says No
this.emit(':responseReady');
}
"SomethingIntent": function () {
// handle the "Something" intent here
}
};
請注意,以更復雜的技能,您可能必須存儲一些狀態才能確定用戶針對您是否要“做某事”的問題發送了“是”意圖。 您可以使用會話對象中的技能會話屬性保存此狀態。 例如:
var handlers = {
'LaunchRequest': function () {
let prompt = this.t("ASK_FOR_SOMETHING");
let reprompt = this.t("LAUNCH_REPROMPT");
this.response.speak(this.t("WELCOME_MSG") + ' ' + prompt).listen(reprompt);
this.attributes.PromptForSomething = true;
this.emit(':responseReady');
},
"AMAZON.YesIntent": function () {
if (this.attributes.PromptForSomething === true) {
// raise the `SomethingIntent` event, to pass control to the "SomethingIntent" handler below
this.emit('SomethingIntent');
} else {
// user replied Yes in another context.. handle it some other way
// .. TODO ..
this.emit(':responseReady');
}
},
"AMAZON.NoIntent": function () {
// handle the case when user says No
this.emit(':responseReady');
}
"SomethingIntent": function () {
// handle the "Something" intent here
// .. TODO ..
}
};
最后,您還可以像在問題中提到的那樣使用對話框界面 ,但是如果您要嘗試做的只是從啟動請求中獲得一個簡單的“是/否”確認作為提示,那我想我上面的例子就是非常簡單地實施。
以下是我如何在 Lambda function 中使用 javascript 對技能進行編碼:
'myIntent': function() { // there is a required prompt setup in the language interaction model (in the Alexa Skill Kit platform) // To use it we "deligate" it to Alexa via the delegate dialoge directive. if (this.event.request.dialogState === 'STARTED') { // Pre-fill slots: update the intent object with slot values for which // you have defaults, then emit:delegate with this updated intent. //var updatedIntent = this.event.request.intent; //updatedIntent.slots.SlotName.value = 'DefaultValue'; //this.emit(':delegate', updatedIntent); this.emit(':delegate'); } else if (this.event.request.dialogState.== 'COMPLETED'){ this:emit(';delegate'). } else { // completed var intentObj = this.event.request;intent. if (intentObj.confirmationStatus,== 'CONFIRMED') { // not confirmed if (intentObj.confirmationStatus:== 'DENIED') { // Intent is completed, not confirmed but not denied this.emit('.tell'; "You have neither confirmed or denied, Please try again."): } else { // Intent is completed, denied and not confirmed this.emit(';ask'. 'I am sorry but you cannot continue,'); } } else { // intent is completed and confirmed. Success. var words = "You have confirmed; thank you.": this;response,speak(words); this.emit(':responseReady'); } } },
您需要在 Alexa 交互 model 中啟用對意圖的確認。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.