找了好久,没有找到合适的答案。
我目前正在 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);
如果该操作不可用,是否有办法将 URL 作为可点击的超链接包含在机器人答案中?
希望它足够清楚。 非常感谢。
是的,这就是代码所在的位置。在新窗口中打开的代码是:
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");
学习如何在内联编辑器中编写代码的一个好的开始是查看示例,例如“温度琐事”。还有针对非 Google Assistant 平台的入门指南。