You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Actions SDK自定义BUY Intent触发TEXT问题修复及相关技术问询

问题:自定义BUY Intent被误触发为actions.intent.TEXT,及相关疑问

我用Actions SDK开发对话应用,配置了action.json和index.js,但调用带颜色参数的自定义BUY Intent时,实际触发的是actions.intent.TEXT,想知道怎么修复。另外还有两个疑问:

  1. 创建自定义Intent是否仅需修改action.json,有无其他创建方式?
  2. 如何在JS文件中调用Place helper Intent的代码段?

我的配置代码

action.json

{ 
  "actions": [ 
    { 
      "description": "Default Welcome Intent", 
      "name": "MAIN", 
      "fulfillment": { 
        "conversationName": "testapp" 
      }, 
      "intent": { 
        "name": "actions.intent.MAIN", 
        "trigger": { 
          "queryPatterns": [ "talk to Developer" ] 
        } 
      } 
    }, 
    { 
      "name": "BUY", 
      "intent": { 
        "name": "com.example.sekai.BUY", 
        "parameters": [{ 
          "name": "color", 
          "type": "SchemaOrg_Color" 
        }], 
        "trigger": { 
          "queryPatterns": [ 
            "find some $SchemaOrg_Color:color sneakers", 
            "buy some blue suede shoes", 
            "get running shoes" 
          ] 
        } 
      }, 
      "fulfillment": { 
        "conversationName": "testapp" 
      } 
    } 
  ], 
  "conversations": { 
    "testapp": { 
      "name": "testapp", 
      "url": "https://us-central1-samplejs2-id.cloudfunctions.net/testApp", 
      "fulfillmentApiVersion": 2, 
      "inDialogIntents": [ { "name": "actions.intent.CANCEL" } ] 
    } 
  }, 
  "locale": "en" 
}

index.js

'use strict'; 
const functions = require('firebase-functions'); 
const admin = require('firebase-admin'); 
const {actionssdk} = require('actions-on-google'); 
const app = actionssdk({debug: true}); 

app.intent('com.example.sekai.BUY', (conv, input) => { 
  console.log("Inside custom intent"); 
  conv.ask('<speak>Hi! <break time="1"/> ' + ' The color you typed is' + `<say-as >${input}</say-as>.</speak>`); 
}); 

app.intent('actions.intent.MAIN', (conv, input) => { 
  conv.ask('<speak>Hi! <break time="1"/> ' + 'You are entering into samplejs application by typing ' + `<say-as >${input}</say-as>.</speak>`); 
}); 

app.intent('actions.intent.CANCEL', (conv) => { 
  conv.close(`Okay, let's try this again later.`); 
}); 

app.intent('actions.intent.TEXT', (conv, input) => { 
  if (input === 'bye') { 
    return conv.close('Goodbye!'); 
  } 
  conv.ask('<speak>You said, ' + `<say-as >${input}</say-as>.</speak>`); 
}); 

//exports.app = app; 
console.log("global-----------&gt;",global); 
exports.testApp = functions.https.onRequest(app); 

一、修复BUY Intent被误触发为TEXT的问题

咱们从几个核心点排查修复:

  1. 确认Intent匹配逻辑与参数解析
    Actions SDK会优先匹配有明确触发模式且参数能被正确提取的Intent。你的BUY Intent里的color参数用了SchemaOrg_Color实体,注意:

    • 如果用户输入的query不含可识别的颜色词(比如只说"get running shoes"),系统无法提取color参数,就会跳过BUY Intent,触发兜底的actions.intent.TEXT。
    • 检查queryPatterns的写法:$SchemaOrg_Color:color的占位符是对的,但要确保用户输入的颜色是SchemaOrg能识别的标准词(比如"blue"、"red"),生僻颜色可能无法被解析。
  2. 验证配置一致性与部署生效

    • 确保action.json里的Intent名称com.example.sekai.BUY和index.js中app.intent()的第一个参数完全一致(大小写、命名空间都不能错)。
    • 修改action.json后,必须用gactions update命令重新上传配置并部署,否则新的Intent配置不会生效,系统还是会用旧规则匹配。
  3. 借助debug日志定位问题
    你已经开启了debug: true,可以去Firebase Functions的日志里查看每次请求的Intent识别结果——日志会明确显示系统匹配到的Intent名称,能快速判断是匹配规则问题还是代码处理问题。

二、自定义Intent的创建方式

不止修改action.json这一种,还有两种常用方式:

  • Actions Console可视化创建:直接在Actions Console里拖拽配置自定义Intent,设置触发短语、参数、实体等,操作更直观,适合快速搭建。配置完成后可以导出对应的action.json,也能直接在控制台生效。
  • Actions REST API创建:如果需要自动化批量管理Action配置,可以用Actions API来创建、更新Intent,适合复杂场景下的配置自动化。
  • 手动修改action.json:就是你现在用的方式,适合对配置细节有精细控制的需求,修改后需要用gactions工具上传到平台。

三、调用Place helper Intent的方法

要使用Place helper,得按以下步骤来:

  1. 先导入Place类
    在index.js的导入部分添加Place:

    const {actionssdk, Place} = require('actions-on-google');
    
  2. 配置Place的参数并调用
    Place需要传入配置对象,指定提示语、地点类型等,示例如下:

    app.intent('ask_for_place', (conv) => {
      const options = {
        prompt: 'Where would you like to pick up your shoes?',
        context: 'Looking for a shoe store location',
        types: ['store'] // 可选地点类型:'locality'、'address'、'restaurant'等
      };
      conv.ask(new Place(options));
    });
    
  3. 处理地点结果
    用户选择地点后,系统会触发actions.intent.PLACE Intent,你需要注册对应的处理函数来获取地点信息:

    app.intent('actions.intent.PLACE', (conv, params) => {
      const place = params.place;
      if (place) {
        conv.close(`Got it, we'll send your shoes to ${place.formattedAddress}`);
      } else {
        conv.close(`Sorry, I couldn't find that location.`);
      }
    });
    

    另外,要在action.json的inDialogIntents或actions数组里注册actions.intent.PLACE,确保系统能正确触发这个Intent。

内容的提问来源于stack exchange,提问作者Thirumani

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:52:39