如何使用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"。如何解决此问题?

在创建云函数时,我选择了JavaScript选项。

为了创建自定义意图,action.json中是否需要这些更新?是否有创建自定义意图的选项?

如何在js文件中调用这个helper内容?

app.intent('ask_for_place', (conv) => {
conv.ask(new Place(options));
});

自定义意图仅作为"深度链接"的欢迎意图触发。一旦会话开始,所有会话意图都将报告为TEXT

因此,对于您在actions.json文件中定义的意图com.example.sekai.BUY,如果您的Action被命名为类似"超级存储"的名称,那么以下调用将触发该意图:

嘿,谷歌,让超级商店找到一些蓝色运动鞋

但一旦对话开始,询问"找一些蓝色运动鞋"就会触发TEXT的意图。

带有Actions.json的Actions SDK主要用于提供自然语言处理的系统,这些系统只想在文本从语音转换后获得文本。

如果您想要更复杂的自然语言处理,会话中的每个短语都会触发用户定义的Intent,请查看Dialogflow。

最新更新