如何使用 Google 操作 conv.ask 获得用户的响应并转移到流程
How to use Google action conv.ask to get response from user and move to process
我想尝试使用 Google Actions node js SDK 在响应用户之前询问用户更多信息,以便我可以继续下一个过程。我曾尝试使用 conv.ask
来等待用户响应,但是,当用户响应时它只会返回到 actions.intent.TEXT
而不是意图 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
中执行此过程。
已更新:
我试图在 action.intent.Text
中创建一个全局类型变量和 switch case。
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');
})
我认为这不是一个理想的解决方案,因为当多个设备使用我的执行服务器时它会导致问题。是否可以在相同的意图函数中询问并使用用户响应,而不是使用 conv.ask
去 actions.intent.TEXT
?
使用 actions.json 文件中的意图有两个原因:
设置欢迎意图和深层链接短语的模式。
稍后在对话中塑造可能的用户响应。
然而,在情况 (2) 中,意图仍报告为 actions.intent.TEXT
。您永远不会使用 Action SDK 向您报告您定义的其他意图。所以它永远不会发送 com.example.test.WHAT
或 HOW
意图。
如果您使用自己的自然语言处理 (NLP) 系统,这正是您想要的 - 只是用户发送的文本。
如果您想要为您进行 NLP 处理并管理状态的东西,您可能希望改用 Dialogflow 之类的东西。 Dialogflow 允许您设置将与意图匹配的短语,并在您的 webhook fulfillment 中向您发送匹配的意图以及用户所说的参数。
我想尝试使用 Google Actions node js SDK 在响应用户之前询问用户更多信息,以便我可以继续下一个过程。我曾尝试使用 conv.ask
来等待用户响应,但是,当用户响应时它只会返回到 actions.intent.TEXT
而不是意图 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
中执行此过程。
已更新:
我试图在 action.intent.Text
中创建一个全局类型变量和 switch case。
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');
})
我认为这不是一个理想的解决方案,因为当多个设备使用我的执行服务器时它会导致问题。是否可以在相同的意图函数中询问并使用用户响应,而不是使用 conv.ask
去 actions.intent.TEXT
?
使用 actions.json 文件中的意图有两个原因:
设置欢迎意图和深层链接短语的模式。
稍后在对话中塑造可能的用户响应。
然而,在情况 (2) 中,意图仍报告为 actions.intent.TEXT
。您永远不会使用 Action SDK 向您报告您定义的其他意图。所以它永远不会发送 com.example.test.WHAT
或 HOW
意图。
如果您使用自己的自然语言处理 (NLP) 系统,这正是您想要的 - 只是用户发送的文本。
如果您想要为您进行 NLP 处理并管理状态的东西,您可能希望改用 Dialogflow 之类的东西。 Dialogflow 允许您设置将与意图匹配的短语,并在您的 webhook fulfillment 中向您发送匹配的意图以及用户所说的参数。