如何使用 Voiceflow Chatbot 获取网站 URL?

问题描述 投票:0回答:1

我正在尝试向我的 Voiceflow 聊天机器人添加一项功能,我可以将网站 URL 保存为变量。我需要它用于聊天机器人流程,因此应将其保存为流程内的变量。

我尝试使用 javascript 模块:

websiteURL = window.location.href

它说窗口未定义。

我还询问了AI Voiceflow Assistant,它告诉我修改启动代码以将url作为变量,但它也不起作用。

<script type="text/javascript">
  (function(d, t) {
      var v = d.createElement(t), s = d.getElementsByTagName(t)[0];
      v.onload = function() {
        window.voiceflow.chat.load({
          verify: { projectID: 'XXXXCURRENT_IDXXXX' },
          url: 'https://general-runtime.voiceflow.com',
          versionID: 'production',
          variables: {
            websiteURL: window.location.href
          }
        }).then(() => {
          setTimeout(function() {
                  window.voiceflow.chat.open();
                }, 200);
        });
      }
      v.src = "https://cdn.voiceflow.com/widget/bundle.mjs"; v.type = "text/javascript"; s.parentNode.insertBefore(v, s);
  })(document, 'script');
  </script>```


javascript variables url chatbot
1个回答
0
投票

文档中有一些关于如何添加自定义变量的指南。 https://developer.voiceflow.com/docs/customization-configuration

  (function(d, t) {
  var v = d.createElement(t), s = d.getElementsByTagName(t)[0];
  v.onload = function() {
    window.voiceflow.chat.load({
      verify: { projectID: 'XXXXCURRENT_IDXXXX' },
      url: 'https://general-runtime.voiceflow.com',
      versionID: 'production',
      launch: {
        event: {
            type: "launch",
            payload: {
            websiteURL: window.location.href
            }
        }
        },
        autostart: false
    });
  }
  v.src = "https://cdn.voiceflow.com/widget/bundle.mjs"; v.type = "text/javascript"; s.parentNode.insertBefore(v, s);})(document, 'script');

您需要取出变量部分并将其替换为启动事件,并将您的 websiteURL 设置为变量。

这应该在加载时将值传递给您的last_event系统变量。然后使用 JavaScript 代码步骤验证有效负载值,并在每个新对话开始时使用默认值设置现有变量。

if (last_event) {
  websiteURL = last_event.payload.websiteURL
} else {
  websiteURL = "i dunno"
}

确保 websiteURL 是已在代理中创建的变量。在开始步骤之后立即使用 javascript 代码步骤,这应该在应用程序重新加载时将 websiteURL 变量设置为当前页面。

© www.soinside.com 2019 - 2024. All rights reserved.