javascript - 如何使用 Google action conv.ask 获取用户的响应并转移到流程
问题描述
我想尝试使用 Google Actions 节点 js SDK 在响应用户之前询问用户更多信息,这样我就可以继续下一个过程。我尝试使用conv.ask
等待用户响应,但是,当用户响应时,它只会返回actions.intent.TEXT
而不是 intent com.example.test.DO
。我应该如何实现这一目标?
app.intent('com.example.test.WHAT', (conv, input, arg) => {
conv.ask('Sure! What do you want me to help with');
})
app.intent('com.example.test.DO', (conv, input, arg) => {
//process the user response here from com.example.test.WHAT
conv.close('I have finished it');
})
app.intent('actions.intent.TEXT', (conv, input) => {
if (input === 'bye' || input === 'goodbye') {
return conv.close('See you later!')
}
conv.ask(`I didn't understand. Can you tell me something else?`)
})
动作包 JSON:
{
"name": "DO",
"intent": {
"name": "com.example.test.DO",
"trigger": {
"queryPatterns": [
"stop streaming"
]
}
},
"fulfillment": {
"conversationName": "example-test"
}
},
{
"name": "WHAT",
"intent": {
"name": "com.example.test.WHAT",
"trigger": {
"queryPatterns": [
"help me"
]
}
}
我在模拟器上的问题:
Me: Talk to myTestExample to help me
Google: Sure! What do you want me to help with?
ME: Play with me
Google: I didn't understand. Can you tell me something else?
我希望它去com.example.test.DO
而不是actions.intent.TEXT
. 或com.example.test.WHAT
在得到用户响应后执行内部处理。
更新:
我试图在里面创建一个全局类型变量和 switch case action.intent.Text
。
var type;
app.intent('actions.intent.TEXT', (conv, input) => {
if (input === 'bye' || input === 'goodbye' || input === 'stop') {
return conv.close('See you later!')
}
switch (type){
case 'WHAT':
//use the new input data to process sth here
return conv.close('I will help you to do this');
case 'HOW':
//use the new input data to process sth here
return conv.close('I will use this method to help with you');
}
conv.ask(`I didn't understand. Can you tell me something else?`)
}
app.intent('com.example.test.WHAT', (conv, input, arg) => {
type = 'WHAT';
conv.ask('Sure! What do you want me to help with');
})
app.intent('com.example.test.HOW', (conv, input, arg) => {
type = 'WHAT';
conv.ask('Sure! How do you want me to help with');
})
我认为这不是一个理想的解决方案,因为当多个设备使用我的履行服务器时会导致问题。是否可以在同一意图功能上询问和使用用户响应而不是actions.intent.TEXT
使用conv.ask
?
解决方案
使用 actions.json 文件中的意图有两个原因:
设置欢迎意图和深层链接短语的模式。
稍后在对话中塑造可能的用户响应。
然而,在情况 (2) 中,意图仍被报告为actions.intent.TEXT
。您将永远不会使用 Action SDK 向您报告您定义的其他意图。所以它永远不会发送com.example.test.WHAT
orHOW
意图。
如果您使用自己的自然语言处理 (NLP) 系统,这正是您想要的 - 只是用户发送的文本。
如果您想要为您进行 NLP 处理并管理状态的东西,您可能希望查看类似 Dialogflow 的东西。Dialogflow 允许您设置将与意图匹配的短语,并在您的 webhook 实现中向您发送匹配的意图以及用户所说的参数。
推荐阅读
- java - audioManager.setSpeakerphoneOn(true) 正在影响 android 项目中的所有活动
- python - 使用 groupby 创建新的数据框
- jasmine - 量角器,如何获取href,多个,值
- python - for 循环的三个值
- angular - Angular + Firestore 快照更改更新
- ruby - 错误:在任何存储库中都找不到有效的 gem 'gettc' (>= 0)
- sql - SQL循环外键
- php - 当我已经使用自动加载时如何使用作曲家的自动加载?
- google-chrome-extension - chrome.tabs.onUpdated 不将刷新视为更新
- excel - 2张纸之间的部分匹配在同一行中插入值作为匹配