Javascript 如何使用Google action conv.ask获得用户的响应并转到流程
我想尝试使用Google Actions node js SDK在用户响应之前询问用户更多信息,以便继续下一个过程。我尝试使用Javascript 如何使用Google action conv.ask获得用户的响应并转到流程,javascript,node.js,actions-on-google,Javascript,Node.js,Actions On Google,我想尝试使用Google Actions node js SDK在用户响应之前询问用户更多信息,以便继续下一个过程。我尝试使用conv.ask等待用户响应,但是,当用户响应时,它只返回到actions.intent.TEXT,而不是intentcom.example.test.DO。我应该如何做到这一点 app.intent('com.example.test.WHAT', (conv, input, arg) => { conv.ask('Sure! What do you want
conv.ask
等待用户响应,但是,当用户响应时,它只返回到actions.intent.TEXT
,而不是intentcom.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
中创建一个全局类型变量并切换大小写
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');
})
我认为这不是一个理想的解决方案,因为当多个设备使用我的fulfillment server时,它会导致问题。是否可以在相同的意图函数中执行询问并使用用户响应,而不是使用
conv.ask
转到actions.intent.TEXT
?actions.json文件中的意图有两个原因:
actions.intent.TEXT
。使用Action SDK,您将永远无法获得已定义的其他意图报告。因此,它永远不会发送com.example.test.WHAT
或HOW
意图
如果您正在使用自己的自然语言处理(NLP)系统,这正是您想要的——只是用户发送的文本
如果您想要一些可以为您执行NLP处理并管理状态的东西,那么您可能希望查看类似Dialogflow的东西。Dialogflow允许您设置与意图匹配的短语,并将匹配的意图以及用户在webhook实现中所说的参数发送给您。OK。我会试试Dialogflow。谢谢