【问题标题】:Botframework-WebChat - Why doesn't it work with Internet Explorer?Botframework-WebChat - 为什么它不能与 Internet Explorer 一起使用?
【发布时间】:2018-01-18 23:08:38
【问题描述】:

我已经让网络聊天在 Chrome 中正常工作,但在 IE 中却没有。 我的应用是一个使用 WebChat 连接到我的机器人的 Angular 网站。

代码看起来像这样(技术上这是 TypeScript,而不是 JavaScript,箭头函数被转译出来):

directLine: DirectLine = new DirectLine({ secret: environment.botDirectLineSecretKey }) 

@ViewChild("botWindow") botWindowElement: ElementRef;

ngOnInit() {

    this.directLine.activity$
      .filter(activity => activity.type === "event" && activity.name === "init")
      .subscribe(activity => this.changeSize());

    BotChat.App({
      botConnection: this.directLine,
      user: { id: 'user' },
      bot: { id: 'bot' },
    }, this.botWindowElement.nativeElement);

}

changeSize(){
    console.log("here")
    var container = document.getElementById("bot-chat-container");
    container.classList.add("fullSize");
}  

在 Internet Explorer 中,我在控制台中收到此错误:

错误类型错误:您提供了一个无效的对象,其中流是 预期的。您可以提供 Observable、Promise、Array 或 Iterable。

如果我将botConnection: this.directLine 切换到directLine: this.directLine,网络聊天可以工作,但 changeSize() 方法永远不会被调用。

感谢任何帮助。此机器人正在公共网站上运行,必须支持 IE。

【问题讨论】:

  • 这是在黑暗中拍摄的,但你在.filter之前尝试过.subscribe
  • 谢谢,但没有。我明白了。 “订阅”类型上不存在属性“过滤器”。但值得一试。

标签: javascript internet-explorer botframework direct-line-botframework


【解决方案1】:

我找到了答案。在阅读了发布的答案和 cmets 之后,我创建了该代码的“香草”html/JavaScript 版本,正如上面 Eric Dahlvang 所述,它运行良好。然后,我暂时专注于 Angular 方面。

然后我注意到我的原始 Angular 代码与我的纯 JavaScript 版本和此处找到的示例存在一个差异:https://github.com/Microsoft/BotFramework-WebChat。我做了一个简单的改变:

改变了这个: directLine: DirectLine = new DirectLine({ secret: environment.botDirectLineSecretKey })

对此: directLine: DirectLine = new BotChat.DirectLine({ secret: environment.botDirectLineSecretKey })(请注意,我现在使用的是 BotChat.DirectLine)

一切正常。不幸的是,我不知道为什么。

【讨论】:

  • 很高兴看到你修复了它。想知道为什么 new DirectLine() 没有被 TypeScript 捕获,因为在您的情况下 DirectLine 似乎未定义。
【解决方案2】:

IE 不支持箭头函数:

https://caniuse.com/#feat=arrow-functions

https://docs.microsoft.com/en-us/scripting/javascript/functions-javascript#arrow-functions

如果修改为使用实际功能,您共享的代码应该可以在 IE 中运行:

    this.directLine.activity$
        .filter(isInitEvent)
        .subscribe(changeSize);

...

    function isInitEvent(activity) {
        return activity.type === "event" && activity.name === "init";
    }

    function changeSize(activity) {
        console.log("here")
        var container = document.getElementById("bot");
        container.classList.add("fullSize");
    }  

【讨论】:

  • 感谢您的回复。不幸的是,我仍然收到错误消息。如果我在 IE 中展开错误消息,可以得到这个堆栈跟踪:at e.prototype.error (https://cdn.botframework.com/botframework-webchat/latest/botchat.js:6:4949)
  • 另外,我对此进行了更多研究。对不起,我不清楚,但我的代码是 TypeScript,所以箭头函数被转译出来了。
  • @Schwammy,如果我们没有更多信息/代码详细信息,几乎不可能提供更多帮助。 Webchat 正在 IE 上工作,它只是您身边的一个特定点,我们需要更多详细信息
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-06-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-31
  • 1970-01-01
  • 2011-11-01
相关资源
最近更新 更多