如何在Alexa Skill中重新启动对话框 [英] How can i restart a dialog in Alexa Skill

查看:104
本文介绍了如何在Alexa Skill中重新启动对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NewContactIntent,用户可以输入名字和手机号等数据。我希望他能够随时重启对话框。因此我有一个RestartIntent,所以当用户说'Restart'时,RestartIntentHandler处理请求并将其转发回NewContactIntent。下面是代码:

I have a NewContactIntent where the user enters data like first name and mobile number etc. I want him to be able to restart the dialog at any point. Therefore I have a RestartIntent so when the user says 'Restart' the RestartIntentHandler handles the request and should forward it back to the NewContactIntent. Here is the code:

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。

It doesn't work, when I try it alexa says the error message from the ErrorHandler.

编辑

此示例有效,BarHandler调用FooHandler,所以我不知道理解为什么我的案例不起作用:

This example works and the BarHandler calls the FooHandler, so I don't understand why my case doesn't work:

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);
    }
};


推荐答案

添加重启话语



如果您只有一个意图,那么您可以添加重新启动重置作为话语,并将从中启动对话框开始。

Adding a "restart" utterance

If you have only one intent then you could add "restart" or "reset" as utterances and will start the dialog from the beginning.

问题但如果您还有两个意图要重置,话语重置将会触发任何一个。即使您处于 IntentA 的中间,然后说重置,也可能触发 IntentB 谁还有重置话语。

Issue: But if you have two more intents to be reset-ed, the utterance "reset" will trigger any of it. Even if you are in the middle of IntentA and then say "reset", it might trigger IntentB who also has a "reset" utterance.

使用resetrestart等话语添加 RestartIntent 肯定会触发 RestartIntent 并在 sessionAttribute 的帮助下,如 lastDialogIntent 将帮助您了解哪个要重新启动的对话框。

Adding a RestartIntent with utterances like "reset" or "restart" will definitely trigger RestartIntent and with the help of a sessionAttribute like lastDialogIntent will help you to understand which Dialog to restart.

问题:对话框模型的问题在于,您无法从当前意图中获取不同意图的插槽。这意味着当您说重新启动时,Alexa将触发 RestartIntent 并且您无法使用对话指令进行回复意图重置。

Issue: The problem with dialog model is that, you cannot elicit a slot of a different intent from current intent. That means when you say "restart", Alexa will trigger RestartIntent and you cannot respond with a Dialog Directive of the intent to be reseted.


请注意,在返回Dialog指令时,你不能改变意图,
so意图名称和插槽集必须与发送给你的
技能的意图相匹配。

Note that you cannot change intents when returning a Dialog directive, so the intent name and set of slots must match the intent sent to your skill.

棘手的部分是,用户必须再次从RestartIntent说出会触发所需意图的内容,例如 IntentA

The tricky part is that, the user has to say something that will trigger the required intent again from RestartIntent, say 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]

如果用户只是说黄色,有时候根据交互模型的设计,可能无法触发意图。调整您的交互模型并添加可以帮助您解决问题的话语。

If the user says just "yellow", sometimes the intent might not get triggered depending on the design of your interaction model. Tune your interaction model and add utterances which can help you with this.

以这样一种方式回应,即用户会说一些会再次重新触发意图的内容。使用 sessionAttribute 存储和检索上次使用的对话意图Ex:lastDialogIntent:BuyCarIntent以响应意图匹配的相应问题。

Respond in such a way that the user will say something that will re-trigger the intent again. Make use of the sessionAttribute to store and retrieve last used dialog intent Ex: "lastDialogIntent":"BuyCarIntent" to respond with appropriate question matching the intent.

一旦重新触发,对话框模型将从头开始。

Once it's re-triggered, dialog model will start from the beginning.

这篇关于如何在Alexa Skill中重新启动对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆