寻找了一段时间之后,我没有找到合适的答案。
我目前正在Dialogflow中建立一个代理。该代理将集成在网页中(因此它既不是Facebook Messenger,也不是Google Assistant的一部分)。该代理应该根据用户的需求将用户重定向到网站的特定页面。
我想知道应该将哪种类型的代码放入内联编辑器中,以获取意图的答案,该答案将自动执行在浏览器的新窗口/选项卡中打开URL的动作。
就像是这样:
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.
我认为这部分代码应插入到以下代码段中,但是我是初学者,所以我不确定我的方法是否正确:
function userNeed(agent) {
// code that would open the URL
}
intentMap.set('User Need', userNeed);
如果无法执行该操作,是否有办法将网址作为可点击的超链接包含在漫游器答案中?
希望很清楚。 非常感谢。
答案 0 :(得分:0)
是的,这就是代码的去向。在新窗口中打开的代码将是:
window.open("https://www.website.com");
您还可以在用户使用setTimeout().
阅读漫游器消息之后,延迟执行此操作
setTimeout(function(){ window.open("https://www.website.com"); }, 3000);
不幸的是,我不认为Dialogflow支持此功能,但请尝试。
要发布可点击的超链接,只需在响应字符串中添加URL,然后在userNeed
函数中输入:
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");
学习内联编辑器中的代码的一个好开始是查看示例,例如temperature trivia。对于不是Google Assistant的平台,还有一个getting started guide。