1

I've tried to implement an Dialogflow app (Actions on Google) and it works quite well so far. However: does anyone know if it is possible to define further action parameters / context via node.js, so I can use them somehow to create dynamic "link out suggestions" in Dialogflow?

In Detail: I try to request some parameters from the users, map them on a set of urls (=implemented as some kind of database) and then write the result url into the json response. Goal: include these response url as $url, #deeplink.url (or similar) in Dialogflow's "Response > Google Assistant > Enter URL".

Is this possible in any way? Thank you in advance.

UPDATE: I also tested the approach of building a rich reponse, but it does not seem to work. Example:

const richResponse = app
.buildRichResponse()
.addSimpleResponse('Flight from ' + origin + ' to' + destination)
.addSuggestions("Find your flight:")
.addSuggestions("Basic Card", "List", "Carousel")
.addSuggestionLink("Search now", url);

(app is an instance of require('actions-on-google').DialogflowApp)

However, he seems to stop after "addSimpleResponse".

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Vrankey
  • 11
  • 3
  • I'm not sure what exactly it is you're trying to do but perhaps you could take a look at "rich responses" for the assistant. – Bart Nov 28 '17 at 11:15
  • create an Intent > Integrate webhook > run business logic on server > return response. Done! – Priyam Gupta Nov 28 '17 at 11:39
  • That's what I've tried first, but somehow it didn't work. Do you have an example of a working RichResponse containing a single link out suggestion? – Vrankey Nov 28 '17 at 13:48
  • I try to go the way of building a rich response via webhook again now.... I've attached some code in the first post. Does anybody see an error? – Vrankey Nov 29 '17 at 09:41

1 Answers1

2

Yes. You can create a context in your webhook, and include parameters in that context that contain the values that you want. To use your example, you could create a context "deeplink" and set a parameter in it named "url" with the URL you're going to link to. You should probably also have a "title" parameter, since the Link Out Suggestion and Basic Card requires a title or website name in addition to the link.

Creating a context is fairly simple, but depends on exactly how you're generating the JSON. If you're using the actions-on-google library for node.js, you would create it with a command something like

var contextParameters = {
  title: "Example Website!",
  url:   "http://example.com/"
};
app.setContext( "deeplink", 1, contextParameters );

If you're creating the response JSON yourself, you will have a contextOut array with the context objects you want to set. This portion of the JSON might look something like

"contextOut": [
  {
    "name": "deeplink",
    "lifespan": 1,
    "parameters": {
      "title": "Example Website!",
      "url": "http://example.com/"
    }
  }
]

Then, in the fields for the Link Out or Basic Card, you would reference them as #deeplink.title and #deeplink.url. For a Link Out, it might look something like this:

enter image description here

However, once you're doing fulfillment, sometimes it becomes easier to generate the VUI and GUI elements in the webhook instead of setting them as part of the Dialogflow builder. This is particularly true if you have a varying number of cards or carousel items that you want to generate.

The Actions on Google documentation provides the various UI elements that can be returned along with sample JSON and node.js code to generate each. These are the same elements that Dialogflow offers through the Actions on Google response tab - just that you can generate them from your webhook instead.

Prisoner
  • 49,922
  • 7
  • 53
  • 105
  • Thank you very much for detailed answer! However, that's exactly what I have tried to do, but the context doesn't show up in the response JSON I see in Dialogflow. – Vrankey Nov 28 '17 at 13:48
  • Please update your question to include screen shots showing exactly what you've done, code samples showing how you're setting the context, and the JSON being returned from Dialogflow. – Prisoner Nov 28 '17 at 14:02