Use multivocal libary to configure repeat intent in Dialogflow for VUI

后端 未结 1 981
半阙折子戏
半阙折子戏 2021-01-25 06:42

I\'m trying to configure my VUI to repeat a sentence in Dialogflow when it is prompted for this. Little back story, I am helping develop a social robot for elderly so repeating

相关标签:
1条回答
  • 2021-01-25 06:54

    Some answers for using multivocal using the Dialogflow Inline Editor:

    How do I include this in the package.json file?

    The directions for using npm are if you're writing the fulfillment locally and not using the Editor.

    You need to add this line in the dependencies section:

        "multivocal": "^0.14.0"
    

    and Dialogflow / Firebase Cloud Functions will take care of importing the library. You won't need the "actions-on-google", "dialogflow", or "dialogflow-fulfillment" libraries, so the section can look something like this:

      "dependencies": {
        "firebase-admin": "^5.13.1",
        "firebase-functions": "^2.0.2",
        "multivocal": "^0.14.0"
      }
    

    How do I write my index.js?

    The simple example assumes that you can put your configuration and code in a separate file ("color.js" in the example). Since you can't do that with the Inline Editor, the general boilerplate of your code will be something like this:

    // Import the library on the first line, so you can call methods on it to setup your configuration
    const Multivocal = require('multivocal');
    
    // Your configuration and code go here
    
    // Setup the webhook as the final line
    exports.dialogflowFirebaseFulfillment = Multivocal.processFirebaseWebhook;
    

    Where do the Intent Handler registration and functions go?

    Unlike the dialogflow-fulfillment library, multivocal doesn't use an explicit intentMap. It maintains one itself, so to register an Intent Handler function you would use something like

    Multivocal.addIntentHandler( intentName, handlerFunction );
    

    BUT keep in mind that handler functions are also a little different.

    What? How are they different?

    Multivocal has a lot of things handled through configuration, rather than code. So there is no direct counterpart to the agent.add() function call that you'd have with dialogflow-fulfillment or the actions-on-google library.

    Instead, your Intent Handler function should perform any logic, database calls, or whatever to get values that will be used in responses and save them in the Environment. Every Handler should return a Promise that contains the Environment.

    You should also set configuration for your Intent - the most common of which is to set the possible "Response" templates. The most simple response templates just include text, and where to insert values from the environment. It is also best practice to prompt the user for what they can do next, so we might setup a "Suffix" template to use by default, or one to use for specific Intents, Actions, or Outents.

    So if you had an Intent named "color.favorite", and had a value in the environment called "color" (that your handler may have loaded from a database), the configuration for this response in English may look something like this. It also includes a default suffix to prompt the user what they can do next.

      const config = {
        Local: {
          en: {
            Response: {
              "Intent.color.favorite": [
                  "{{color}} is one of my favorite colors as well.",
                  "Oh yes, {{color}} can be quite striking.",
                  "I can certainly understand why you like {{color}}."
              ]
            },
            Suffix: {
              Default: [
                "What other color do you like?"
                "Tell me another color."
              ]
            }
          }
        }
      }
    

    and you would register this configuration with

      new Multivocal.Config.Simple( config );
    

    You can (and are expected to) register multiple configurations, although you can combine them in one object. So the Response section above could contain response sections for each of your Intents, by name.

    Ok, but how do I handle a "repeat" Intent?

    All you need to do is provide an Intent that has its "Action" set to "multivocal.repeat" in the Dialogflow UI and that has the webhook enabled. So something like this would work:

    Multivocal already has registered a handler and configuration based on this.

    If you want to change the possible responses, you can add configuration for the "multivocal.repeat" Action. Which may look something like this:

    const enRepeat = [
      "Sorry about that, let me try again.",
      "I said:"
    ];
    
    const config = {
      Local: {
        en: {
          Response: {
            "Action.multivocal.repeat": enRepeat
          }
        }
      }
    }
    

    and then either combine this configuration with other configurations you've written, or load it as above.

    To emphasize - there is no need for you to write any code for this, just some optional configuration.

    0 讨论(0)
提交回复
热议问题