我的网络聊天在 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。
最佳答案
我找到了答案。在阅读了发布的答案和评论后,我创建了此代码的“普通”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)
一切正常。不幸的是,我不知道为什么。
关于javascript - Botframework-WebChat - 为什么它不能与 Internet Explorer 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48304605/