Botframework-WebChat - 为什么它不能与 Internet Explorer 一起使用?

Botframework-WebChat - Why doesn't it work with Internet Explorer?

我的网络聊天在 Chrome 中可以正常工作,但在 IE 中不能。 我的应用程序是一个 Angular 网站,使用 WebChat 连接到我的机器人。

代码如下所示(从技术上讲,这是 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 中,我在控制台中收到此错误:

ERROR TypeError: You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.

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

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

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");
    }  

我找到了答案。在阅读了已发布的答案和评论后,我创建了此代码的 "vanilla" 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

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