简体   繁体   English

Google Actions跟进多个action_intent_OPTION

[英]Google Actions Follow up multiple actions_intent_OPTION

I've been playing around with Google Actions lately. 最近,我一直在玩Google Actions。 I want to create a flow were i make a transfer. 我想创建一个流程,但要进行转移。 It consists of 3 steps. 它包括3个步骤。

在此处输入图片说明

On the first step user selects the amount, then the From account and last the To account. 在第一步中,用户选择金额,然后选择“发件人”帐户,最后选择“收件者”帐户。

The first intent has the transferMoney-followup output context. 第一个意图具有transferMoney-followup输出上下文。 The second intent has the transferMoney-followup as input context and the transferMoneyFromAccount-followup as output context. 第二个意图将transferMoney-followup作为输入上下文,将transferMoneyFromAccount-followup作为输出上下文。 The third intent has the transferMoneyFromAccount-followup as input context. 第三个意图将transferMoneyFromAccount-followup作为输入上下文。

When i get from the first intent to the second one and the user selects an option i have access to the first one and the parameters from there. 当我从第一个意图转到第二个意图并且用户选择一个选项时,我可以从那里访问第一个意图和参数。

When i show now the list again this time for the 3rd intent after the selection it never reaches there and the code is never executed and the 2nd intent is executed again. 当我这次再次为选择后的第三个意图显示列表时,它永远不会到达那里,也永远不会执行代码,并且再次执行第二个意图。 My guess is i'm doing something wrong with the contexts but can't figure out what. 我的猜测是我在上下文中做错了,但无法弄清楚是什么。

const app = require('actions-on-google').dialogflow();
app.intent('transferMoney' , (conv, params) => {
    conv.ask("Sure, let's transfer " + params.amount +"...");
    let items = {
        title: 'Select an account to send money FROM',
        items: {}
    };
    for (let i = 0; i < conv.data.userInfo.banks[0].accountsInformation.accounts.length; i++) {
        let account = conv.data.userInfo.banks[0].accountsInformation.accounts[i];
        items.items[account.id] = {
            title: account.alias,
            description: account.balance + "$"
        }
    }
    conv.ask(new List(items));
});

//Create a Dialogflow intent with the `actions_intent_OPTION` event
app.intent('transferMoney.FromAccount', (conv, params, option) => {
    let amount = conv.contexts.get("transfermoney-followup").parameters.amount;
    let fromAccountId = option;
    conv.ask("Let's send that " + amount + " from " + fromAccountId);
    conv.ask("Where should we send them to ?");
    let items = {
        title: 'Select an account to send money TO',
        items: {}
    };
    for (let i = 0; i < conv.data.userInfo.banks[0].accountsInformation.accounts.length; i++) {
        let account = conv.data.userInfo.banks[0].accountsInformation.accounts[i];
        items.items[account.id] = {
            title: account.alias,
            description: account.balance + "$"
        }
    }
    conv.ask(new List(items));
});

//Create a Dialogflow intent with the `actions_intent_OPTION` event
app.intent('transferMoney.FromAccount.ToAccount', (conv, params, option) => {
    let amount = 0;
    let fromAccountId = 1;
    let toAccountId = 2;
    conv.ask("Let's send that " + amount + " from " + fromAccountId + " to " + toAccountId)
});

Let me know if you need any more information. 让我知道您是否需要更多信息。

EDIT: 1st intent 编辑:第一意图 在此处输入图片说明 2nd intent 第二意图 在此处输入图片说明 3rd intent 第三意图 在此处输入图片说明

The issue is that the lifespan of your two contexts are 2. This means that they will exist for two more replies from the user. 问题在于,您的两个上下文的寿命为2。这意味着,对于用户的另外两个答复,它们将存在。 So your "transferMoney-followup" and "transferMoneyFromAccount-followup" contexts are both valid at the same time. 因此,您的“ transferMoney-followup”和“ transferMoneyFromAccount-followup”上下文都同时有效。 When faced with this, Dialogflow ends up picking the first one that matches the criteria, and ends up going with the "transferMoney.FromAccount" Intent. 遇到这种情况时,Dialogflow最终会选择与条件匹配的第一个,并最终使用“ transferMoney.FromAccount”意图。

You have a few solutions. 您有一些解决方案。

The first is the easiest - reduce the lifespan to 1. This, however, has a couple of side-effects: 第一个是最简单的-将寿命减少到1。但是,这有两个副作用:

  • If the user says something that is handled with a Fallback Intent or that otherwise doesn't match, the Context will run out of time. 如果用户说用回退意图处理的内容或其他不匹配的内容,则上下文将用完时间。

  • The parameters that were stored with the first Context are lost by the time you get to the third Intent. 当您到达第三个Intent时,与第一个Context一起存储的参数将丢失。

A little more difficult, but probably better is to handle these in your fulfillment code. 在实现代码中处理这些要困难一些,但可能更好一些。 You'd need to do the following in the intent handler for "transferMoney.ForAccount": 您需要在“ transferMoney.ForAccount”的意图处理程序中执行以下操作:

  • Copy all the values you need into the transferMoneyFromAccount-followup context (or any other context with a long enough lifespan) and make sure the lifespan is set for "long enough". 将所需的所有值复制到transferMoneyFromAccount-followup上下文(或具有足够长寿命的任何其他上下文)中,并确保将寿命设置为“足够长”。 You can even make this fairly long. 您甚至可以使它相当长。

  • Set the lifespan for transferMoney-followup to 0. This will clear it out so it won't be caught the next time the user says something. transferMoney-followup的寿命设置为0。这将清除该寿命,因此下次用户说一些话时不会被捕获。

Depending on your needs, it might be wise to do the same sort of thing for your other intent handlers as well. 根据您的需求,对其他意图处理程序也执行相同的操作可能是明智的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM