dialogflow / dialogflow-nodejs-client

Node.js SDK for Dialogflow
Apache License 2.0
658 stars 287 forks source link

Is there a way to send a textRequest with a slot already filled? #42

Closed digitalfiz closed 7 years ago

digitalfiz commented 7 years ago

I am working on a voice assistant that is location aware and I want to be able to fill the location slot with the initial request. Say something like "bot, turn the lights off" which would trigger an intent with a location slot. I tried sending it in context but that doesn't seem to fill the slot?

sstepashka commented 7 years ago

This is question for api.ai support, but... What are you name slot? Please, Could you send me screenshot of your intent?

digitalfiz commented 7 years ago

I have a test intent right now with a location parameter: https://i.imgur.com/dNmJWrP.png

When I said slots I mean the parameters

My request looks like this:

    const context = {
      name: 'location',
      parameters: {
        'location': process.env.DEVICE_LOCATION
      }
    };

  settings = {
    sessionId: 'lololololololol',
    contexts: [ context ]
  };
const request = app.textRequest(text.trim(), settings);

The call that goes to the fullfillment api has the location in the context but the parameter for location is not filled. See below:

{
  "source": "agent",
  "resolvedQuery": "input location",
  "speech": "",
  "action": "input_location",
  "actionIncomplete": false,
  "parameters": {},
  "contexts": [
    {
      "name": "input_location",
      "parameters": {
        "location": "Bedroom"
      },
      "lifespan": 4
    }
  ],
  "metadata": {
    "intentId": "-------------------------------",
    "webhookUsed": "true",
    "webhookForSlotFillingUsed": "false",
    "intentName": "input_location"
  },
  "fulfillment": {
    "speech": "",
    "messages": [
      {
        "type": 0,
        "speech": ""
      }
    ]
  },
  "score": 1
}

I realize I can make the fullfillment api look in both spots (the context and parameters) but I would like to make the location required in api.ai so it can ask questions if it's a device that doesn't have a location like a phone.

sstepashka commented 7 years ago

I've made example for your case. See screenshot of intent here. I've marked parameters as required. Fill it by context "location" with parameter "location".

So... If you pass the context then parameter will be filled immediately, else platform ask you location with phrase from promts.

'use strict';

var apiai = require("apiai");

var app = apiai("29e11ba32aec42e0b42acc1f9d01dfa7");

var options = {
    sessionId: 'session______id',
    resetContexts: true,
    contexts: [{
        name: "location",
        lifespan: 1,
        parameters: {
            location: "main room 1",
        }
    }]
};

var request = app.textRequest('trigger light', options);

request.on('response', function(response) {
    console.log(JSON.stringify(response, null, 4));
});

request.on('error', function(error) {
    console.log(error);
});

request.end();

You can comment context definition and platform ask you about you location.

P.S. Don't use "@location" entify for your case. The entity made for geo locations.

sstepashka commented 7 years ago

"#location.location" - parameter "location" from "location" context if the contexts is present else empty. "@sys.any" - entity for any string parameter.

digitalfiz commented 7 years ago

Ah my problem was I was signing the location parameter to $location. This is what I had to do to get it to work for both specifying a location and assuming one from context: https://i.imgur.com/t8piprJ.png

Also thanks for the help!

digitalfiz commented 7 years ago

Hmm I can't do that. The context is required. I can make another intent though that would handle queries with a location specified in the text.

sstepashka commented 7 years ago

If you specify location in intent, the context will be required. Just skip it and use like me. Then the context will be optional.

Sure... Or create another intent with/without the contexts.

Have we resolved your issue?

digitalfiz commented 7 years ago

Yes thank you!

sstepashka commented 7 years ago

You're welcome! No problem!