Isa
Isa

Reputation: 53

Dialogflow with fulfillment: get answer opening an URL http

After looking for a while, I haven't found a proper answer.

I am currently building an agent in Dialogflow. This agent would be integrated in a webpage (so it would not be a Facebook messenger neither a part of Google Assistant). The agent is supposed to redirect the user to specific pages of the website, based on what the user is looking for.

I would like to know what type of code should I put in my inline editor to got an intent answer that would automatically execute the action of opening an URL in a new windows/tab of the browser.

It would be something like :

User: "Hi, I would like the list of red bikes that are available in your shop"
Bot reply: "OK, here you have the list of all the red bikes we have in stock".
-> Then the bot open the page with the red bikes in a new tab/window.

I think this part of the code should be inserted in the following block, but I am beginner, so I am not sure if my approach is correct:

function userNeed(agent) {
    // code that would open the URL
}
intentMap.set('User Need', userNeed);

If such that action was not available, is there a way to include the URL as a clickable hyperlink in the bot answer?

Hope is it clear enough. Thank you very much.

Upvotes: 2

Views: 4358

Answers (1)

Nathan Liu
Nathan Liu

Reputation: 284

Yes, that's where the code would go. The code to open in a new window would be:

window.open("https://www.website.com");

You can also do this on a delay, after the user has read the bot message with setTimeout().

setTimeout(function(){ window.open("https://www.website.com"); }, 3000);

Unfortunately, I don't think this is supported in Dialogflow, but do try.

To post a clickable hyperlink, just add the URL in the response string, so in your userNeed function put:

agent.add("OK, here you have the list of all the red bikes we have in stock. Here's a link: https://www.website.com");

A good start to learn how to write code in the inline editor is by looking at the samples, for example the temperature trivia one. There's also a getting started guide for platforms that are not Google Assistant.

Upvotes: 1

Related Questions