【问题标题】:Why am I not able to create a custom intent asking for 2 texts?为什么我无法创建要求 2 个文本的自定义意图?
【发布时间】:2021-02-14 22:25:56
【问题描述】:

我有一个自定义意图,即从 Google 助理接收 2 个文本参数。但助手不会启动我的应用程序。我只试过一个,它工作正常。问题是当我添加第二个文本参数时。我尝试过使用另一种数据类型并且它有效。例如,如果我要求一个文本和一个数字,效果很好。如果我要求文本和时间,它也有效。但是,如果我要求一个文本和一个文本,那么它不会。请问这里有什么帮助吗? 这是我在 actions.xml 文件中的意图:

<action intentName="custom.actions.intent.MyName" queryPatterns="@array/MyExampleStrings">
   <!-- Define parameters -->
   <parameter name="textA" type="https://schema.org/Text" />
   <parameter name="textB" type="https://schema.org/Text" />

   <!-- Define fulfillment -->
   <fulfillment urlTemplate="https://my.site.com/{?FirstText,SecondText}">
      <parameter-mapping intentParameter="textA" urlParameter="FirstText" />
      <parameter-mapping intentParameter="textB" urlParameter="SecondText" />
   </fulfillment>
</action>

MyExampleStrings 类似于“使用 $textB 烘焙 $textA”,例如“用番茄烘焙意大利面”。

正如我之前所说,它适用于不同的数据类型。在下一个示例中,我更改了数字的第二个文本,它可以工作:

<action intentName="custom.actions.intent.MyName" queryPatterns="@array/MyExampleStrings">
   <!-- Define parameters -->
   <parameter name="textA" type="https://schema.org/Text" />
   <parameter name="textB" type="https://schema.org/Number" /> <--NUMBER!

   <!-- Define fulfillment -->
   <fulfillment urlTemplate="https://my.site.com/{?FirstText,SecondText}">
      <parameter-mapping intentParameter="textA" urlParameter="FirstText" />
      <parameter-mapping intentParameter="textB" urlParameter="SecondText" />
   </fulfillment>
</action>

在这种情况下,如果我说“用 4 烤意大利面”之类的话,它会起作用。 为什么我不能有两个字符串??? 感谢您的帮助

【问题讨论】:

  • 我不熟悉 Google 的帮助,这不是一种解决方案,而是一种可能对您有用的解决方法,直到您找到更好的解决方法。为什么不发送一个文本并在里面添加一个特殊的分隔符?比如,spaghetti@Tomatoes 或类似的东西,一旦你在你的活动中得到文本,只需用这个字符分割并使用这些值。

标签: android actions-on-google app-actions


【解决方案1】:

我刚刚尝试使用您上面的示例复制该问题,但它按我的预期工作。这两个字段都包含在 intent?.data 字段中。所以,就我而言,它看起来像这样:

https://todo.myapp.com/custom-intents?FirstText=Example123&SecondText=Example222

您能否进一步详细说明您是如何检索查询参数的?

作为一般建议,活动中的 onCreate 函数中的日志语句应提供以下详细信息:

override fun onCreate(savedInstanceState: Bundle?) {
    Timber.tag(TAG).d("======= debugging data =========" + intent?.data)
}

【讨论】:

  • 您是使用真正的 Google Assistant 还是使用 App Actions Test Tool 进行检查的?它仅在真正的助手中失败。我现在不能给你一个日志,但它会在下一条评论中显示类似的内容:
  • todo.myapp.com/custom-intents?FirstText=Example123%20with%20Example222&SecondText=Example222
  • 知道了。感谢您对 Google 助理的说明。没错,这是一个已知问题,正在修复中。我会在这里通知你。
  • 谢谢。你怎么知道这是一个已知问题?它是否在任何地方发布?
  • 还没有。我在 Assistant DevRel 团队工作。会及时通知您。
猜你喜欢
  • 1970-01-01
  • 2011-02-21
  • 1970-01-01
  • 2010-09-29
  • 1970-01-01
  • 1970-01-01
  • 2021-08-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多