简体   繁体   中英

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. 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 . 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:

{
      "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 . or do the process inside com.example.test.WHAT after getting user response.

Updated:

I tried to make a global type variable and switch case inside 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 ?

Intents in the actions.json file are used for two reasons:

  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 . You will never get the other intents you've defined reported to you using the Action SDK. So it will never send the com.example.test.WHAT or HOW intents.

This is exactly what you want if you're using your own natural language processing (NLP) system - just the text that the user sent.

If you want something that does NLP processing for you and manages the state, you may wish to look at something like Dialogflow instead. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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