简体   繁体   English

如何使用Google action conv.ask来获取用户的响应并进行处理

[英]How to use Google action conv.ask to get response from user and move to process

I want to try to use Google Actions node js SDK to ask user more information before it responses to the user, so I can continue on next process. 我想尝试使用Google Actions节点js SDK向用户询问更多信息,然后再响应用户,因此我可以继续进行下一个过程。 I have tried to use conv.ask to wait for user response, however, when user response it only goes back to actions.intent.TEXT instead of the intent com.example.test.DO . 我尝试使用conv.ask来等待用户响应,但是,当用户响应时,它只能返回到actions.intent.TEXT而不是意图com.example.test.DO How should I achieve this? 我应该如何实现呢?

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?`)
})

Action Package JSON: 动作包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"
          ]
        }
      }

My question on the simulator: 我在模拟器上的问题:

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?

I want it to go com.example.test.DO instead of actions.intent.TEXT . 我希望它去com.example.test.DO而不是actions.intent.TEXT or do the process inside com.example.test.WHAT after getting user response. 或在获得用户响应后在com.example.test.WHAT进行处理。

Updated: 更新:

I tried to make a global type variable and switch case inside action.intent.Text . 我试图制作一个全局类型变量并在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');
})

I think this is not an ideal solution, as it will cause a problem when multiple devices use my fulfillment server. 我认为这不是理想的解决方案,因为当多个设备使用我的履行服务器时,它将引起问题。 is it possible to do ask and use the user response inside on same intent function instead of going to actions.intent.TEXT with conv.ask ? 是有可能这样做询问和目的相同功能使用的用户响应内,而不是去actions.intent.TEXTconv.ask

Intents in the actions.json file are used for two reasons: 使用actions.json文件中的意图有两个原因:

  1. Setting patterns for the welcome intent and deep linking phrases. 为欢迎意图和深层链接短语设置模式。

  2. Shaping possible user responses later in the conversation. 在稍后的会话中调整可能的用户响应。

In case (2), however, the intent is still reported as actions.intent.TEXT . 但是,在情况(2)中,该意图仍然报告为actions.intent.TEXT You will never get the other intents you've defined reported to you using the Action SDK. 您将永远不会使用Action SDK向您报告已定义的其他意图。 So it will never send the com.example.test.WHAT or HOW intents. 因此它将永远不会发送com.example.test.WHATHOW意图。

This is exactly what you want if you're using your own natural language processing (NLP) system - just the text that the user sent. 如果您使用自己的自然语言处理(NLP)系统-只是用户发送的文本,这正是您想要的。

If you want something that does NLP processing for you and manages the state, you may wish to look at something like Dialogflow instead. 如果您想要为您执行NLP处理并管理状态的设备,则不妨查看Dialogflow之类的东西。 Dialogflow lets you set phrases that will be matched to intents and sends you the intent that was matched, along with parameters from what the user said, in your webhook fulfillment. Dialogflow允许您设置将与意图匹配的短语,并在您的Webhook实现中将匹配的意图以及用户所说的参数发送给您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM