如何使用 Actionsdk 创建自定义意图和调用助手意图?
How to create a custom intent and calling helper intent using Actionsdk?
请查找我的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});
// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-functions
//
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----------->",global);
exports.testApp = functions.https.onRequest(app);
每当我使用任何颜色调用自定义意图 "BUY" 时,它不会调用我的自定义意图,而是调用 "intent.Text"。如何解决这个问题?
创建云函数时我有 select JavaScript 选项。
为了创建自定义意图,action.json 是否需要这么多更新?
是否有创建自定义意图的选项?
如何在js文件中调用这个helper内容?
app.intent('ask_for_place', (conv) => {
conv.ask(new Place(options));
});
自定义意图仅作为 "deep linking" 的欢迎意图触发。对话开始后,所有对话意图都将报告为 TEXT
.
因此,对于您在 actions.json 文件中定义的意图 com.example.sekai.BUY
,如果您的 Action 被命名为类似于 "super store",那么以下调用将触发该意图:
Hey Google, ask super store to find some blue sneakers
但是一旦对话开始,询问 "find some blue sneakers" 会触发 TEXT
意图。
带有 actions.json 的 Actions SDK 主要供提供自然语言处理并且只想在从语音转换后获取文本的系统使用。
如果您想要更复杂的自然语言处理,对话中的每个短语都会触发用户定义的 Intent,请查看 Dialogflow。
请查找我的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});
// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-functions
//
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----------->",global);
exports.testApp = functions.https.onRequest(app);
每当我使用任何颜色调用自定义意图 "BUY" 时,它不会调用我的自定义意图,而是调用 "intent.Text"。如何解决这个问题?
创建云函数时我有 select JavaScript 选项。
为了创建自定义意图,action.json 是否需要这么多更新? 是否有创建自定义意图的选项?
如何在js文件中调用这个helper内容?
app.intent('ask_for_place', (conv) => {
conv.ask(new Place(options));
});
自定义意图仅作为 "deep linking" 的欢迎意图触发。对话开始后,所有对话意图都将报告为 TEXT
.
因此,对于您在 actions.json 文件中定义的意图 com.example.sekai.BUY
,如果您的 Action 被命名为类似于 "super store",那么以下调用将触发该意图:
Hey Google, ask super store to find some blue sneakers
但是一旦对话开始,询问 "find some blue sneakers" 会触发 TEXT
意图。
带有 actions.json 的 Actions SDK 主要供提供自然语言处理并且只想在从语音转换后获取文本的系统使用。
如果您想要更复杂的自然语言处理,对话中的每个短语都会触发用户定义的 Intent,请查看 Dialogflow。