首页 > 解决方案 > 在意图实现中回退到特定意图

问题描述

当我检查有关履行错误处理的文档时,我发现了以下代码:

const WELCOME_INTENT = 'Default Welcome Intent';
const NUMBER_INTENT = 'Input Number';
const NUMBER_ARGUMENT = 'num';

// you can add a fallback function instead of a function for individual intents
app.fallback((conv) => {
  // intent contains the name of the intent
  // you defined in the Intents area of Dialogflow
  const intent = conv.intent;
  switch (intent) {
    case WELCOME_INTENT:
      conv.ask('Welcome! Say a number.');
      break;

    case NUMBER_INTENT:
      const num = conv.arguments.get(NUMBER_ARGUMENT);
      conv.close(`You said ${num}`);
      break;
  }
});

我想知道是否有办法直接引用自定义后备意图(my.intent.fallback)(特定于意图,my.intent)(如某些conv.intent("my.intent.fallback")api 调用)而不是conv.ask('Welcome! Say a number.');.

标签: actions-on-google

解决方案


听起来您在这里混合了两个概念。

app.fallback()函数仅用于注册一个函数,如果没有其他意图处理函数匹配,该函数将被调用。您不应该使用它来监视调用的意图。

您应该注册意图处理函数,包括命名的回退意图,例如

app.intent( 'fallback intent name', function(conv) )

推荐阅读