Google Actions转账流程异常:第三步意图无法触发
It looks like your problem stems from two key issues: incorrect context naming/case sensitivity and missing output context setup in the second intent. Let's break this down and fix it step by step.
Root Causes
Context Case Mismatch: You mentioned the first intent outputs
transferMoney-followup, but in your second intent code, you're trying to fetchtransfermoney-followup(all lowercase for "transfermoney"). Dialogflow context names are case-sensitive, so this not only breaks parameter retrieval but can also confuse intent matching.Missing Output Context in Second Intent: Your second intent is supposed to output
transferMoneyFromAccount-followupto trigger the third intent, but your code doesn't actually set this context. Without it, the third intent's input context requirement isn't met—so when the user selects an option from the third list, Dialogflow falls back to the second intent (which still has the activetransferMoney-followupcontext) instead of triggering the third one.
Step-by-Step Fixes
1. Fix Context Case Consistency
First, standardize your context names to avoid case issues. Let's use transferMoney-followup (camelCase) consistently everywhere:
Update the second intent's parameter retrieval code:
// Replace transfermoney-followup with transferMoney-followup let amount = conv.contexts.get("transferMoney-followup").parameters.amount;
2. Add Output Context to the Second Intent
In your transferMoney.FromAccount intent, add code to set the transferMoneyFromAccount-followup context (this is what tells Dialogflow the user is ready for the third step). We'll also store the amount and fromAccountId in this context so the third intent can access them easily:
app.intent('transferMoney.FromAccount', (conv, params, option) => { let amount = conv.contexts.get("transferMoney-followup").parameters.amount; let fromAccountId = option; // Set the output context for the third step conv.contexts.set('transferMoneyFromAccount-followup', 5, { amount: amount, fromAccountId: fromAccountId }); conv.ask("Let's send that " + amount + " from " + fromAccountId); conv.ask("Where should we send them to ?"); // ... rest of your list building code remains the same });
3. Update the Third Intent to Use the Context Parameters
Right now your third intent has hardcoded values for amount, fromAccountId, and toAccountId—replace those with the values stored in the context:
app.intent('transferMoney.FromAccount.ToAccount', (conv, params, option) => { // Fetch the context set by the second intent const transferContext = conv.contexts.get('transferMoneyFromAccount-followup'); const amount = transferContext.parameters.amount; const fromAccountId = transferContext.parameters.fromAccountId; const toAccountId = option; // This is the selected target account ID conv.ask(`Let's send that ${amount} from ${fromAccountId} to ${toAccountId}`); });
4. Verify Dialogflow Console Intent Configs
Double-check your intent settings in the Dialogflow console to match:
- First intent (
transferMoney):- Output context:
transferMoney-followup(with appropriate lifespan, e.g., 5)
- Output context:
- Second intent (
transferMoney.FromAccount):- Input context:
transferMoney-followup - Output context:
transferMoneyFromAccount-followup - Trigger event:
actions_intent_OPTION
- Input context:
- Third intent (
transferMoney.FromAccount.ToAccount):- Input context:
transferMoneyFromAccount-followup - Trigger event:
actions_intent_OPTION
- Input context:
Why This Works
By setting the transferMoneyFromAccount-followup context in the second intent, you're explicitly telling Dialogflow that the user has moved to the third step. When the user selects an option from the third list, Dialogflow will prioritize the third intent (since its input context is active) instead of falling back to the second intent.
内容的提问来源于stack exchange,提问作者LefterisL

