代码之家  ›  专栏  ›  技术社区  ›  Aparna

如何在Angular5应用程序中使用Microsoft Bot Framework web聊天

  •  2
  • Aparna  · 技术社区  · 7 年前

    我需要一种在angular 5应用程序中嵌入网络聊天的方法。我尝试过此处描述的无反应网站方式: https://github.com/Microsoft/BotFramework-WebChat 这是可行的。

    有没有办法只使用这些组件而不是加载整个js文件来获取Angualar 5应用程序中的聊天窗口?

    1 回复  |  直到 7 年前
        1
  •  6
  •   Gary Liu    7 年前

    如果安装的BotFramework WebChat版本大于 0.10.7 ,您可以在ng应用程序中直接使用BotFramework WebChat。

    • 安装webchat sdk: npm install botframework-webchat
    • 填充样式文件 .angular-cli.json 文件:

      "styles": [
        "../node_modules/botframework-webchat/botchat.css",
        "../node_modules/botframework-webchat/botchat-fullwindow.css"
      ],
      
    • 尝试组件中的示例,如中所述 https://github.com/Microsoft/BotFramework-WebChat/issues/478 :

      import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
      import {App} from "botframework-webchat";
      @Component({
        selector: 'app-root',
        template: `<div id="bot-chat-container" #botWindow></div>`,
      })
      export class AppComponent implements OnInit {
      
        @ViewChild("botWindow") botWindowElement: ElementRef;
      
        ngOnInit(): void {
          App({
            directLine: {secret: 'secret goes here'},
            user: {id: 'user'},
            bot: {id: 'bot'},
          }, this.botWindowElement.nativeElement)
        }
      }