【问题标题】:TypeError: e is not a function at Object.<anonymous> in BotFramework-webchat@4.8.0TypeError: e is not a function at Object.<anonymous> in BotFramework-webchat@4.8.0
【发布时间】:2020-07-26 02:46:27
【问题描述】:

我正在尝试使用节点自定义 BotFramework 网络聊天。

我收到 TypeError: e is not a function at Object. (custom-webchat-4.8.0.js:32) 仅适用于 4.8.0 版本,并且相同的代码适用于 4.6.0 版本。

有人知道怎么解决吗?

这里附上 HTML 文件、package.json 和 ts 文件供参考

package.json:

{
    "name": "custom-webchat",
    "version": "4.8.0",
    "scripts": {
      "build": "rimraf dist && webpack",
      "lint": "tslint -c tslint.json --project . --test src/**/*.ts",
      "deploy": "aws s3 sync dist s3://www.acai-hub.com/js --acl public-read"
    },
    "repository": {
      "type": "git",
      "url": "https://bitbucket.iaas-at-mit.de/scm/bot/bebop-webchat.git"
    },
    "dependencies": {
        "@babel/runtime": "^7.8.4",
        "adaptivecards": "1.2.5",
        "botframework-directlinejs": "^0.11.6",
        "botframework-directlinespeech-sdk": "4.8.0",
        "botframework-webchat-component": "4.8.0",
        "botframework-webchat-core": "4.8.0",
        "core-js": "^3.5.0",
        "markdown-it": "^10.0.0",
        "markdown-it-for-inline": "^0.1.1",
        "memoize-one": "^5.1.1",
        "microsoft-cognitiveservices-speech-sdk": "1.6.0",
        "microsoft-speech-browser-sdk": "^0.0.12",
        "prop-types": "^15.7.2",
        "sanitize-html": "^1.20.0",
        "url-search-params-polyfill": "^7.0.0",
        "web-speech-cognitive-services": "^6.0.0",
        "whatwg-fetch": "^3.0.0",
        "botframework-webchat": "^4.8.0"
      },
      "devDependencies": {
        "@babel/cli": "^7.8.4",
        "@babel/core": "^7.8.4",
        "@babel/plugin-proposal-class-properties": "^7.8.3",
        "@babel/plugin-proposal-object-rest-spread": "^7.8.3",
        "@babel/plugin-transform-runtime": "^7.8.3",
        "@babel/preset-env": "^7.8.4",
        "@babel/preset-react": "^7.8.3",
        "@babel/preset-typescript": "^7.8.3",
        "@types/node": "^12.12.18",
        "@types/react": "16.8.25",
        "@typescript-eslint/eslint-plugin": "^2.12.0",
        "@typescript-eslint/parser": "^2.12.0",
        "babel-plugin-istanbul": "^5.2.0",
        "babel-plugin-transform-inline-environment-variables": "^0.4.3",
        "concurrently": "^5.0.2",
        "eslint": "^6.7.2",
        "eslint-plugin-prettier": "^3.1.1",
        "eslint-plugin-react": "^7.17.0",
        "eslint-plugin-react-hooks": "^2.3.0",
        "isomorphic-react": "4.8.0",
        "isomorphic-react-dom": "4.8.0",
        "prettier": "^1.19.1",
        "source-map-loader": "^0.2.4",
        "terser-webpack-plugin": "^2.3.0",
        "typescript": "^3.7.3",
        "webpack": "^4.41.3",
        "webpack-cli": "^3.3.10",
        "webpack-stats-plugin": "^0.3.0",
        "rimraf": "^2.6.3",
        "ts-loader": "^6.0.4",
        "tslint": "^5.18.0"
      },
      "peerDependencies": {
        "react": "^16.8.6",
        "react-dom": "^16.8.6"
      }
  }

index.ts:

import { WebChat, WebChatOptions } from "./custom-webchat";

let webChat: WebChat;

export function renderWebChat(options: WebChatOptions, element: HTMLElement) {
  webChat = new WebChat(options);
  webChat.renderWebChat(element);
}

window["WebChat"] = {
  ...window["WebChat"],
  renderWebChat
};

custom-webchat.ts:

import * as BotframeworkWebChat from "botframework-webchat";

export interface WebChatOptions {
  token: string;
}

export class WebChat {
  private directline: any;
  constructor({ token}: WebChatOptions) {
    this.directline = BotframeworkWebChat.createDirectLine({ token });
  }

  renderWebChat(element: HTMLElement) {    
    BotframeworkWebChat.renderWebChat(
      {
        directLine: this.directline,        
        botAvatarInitials: 'WC',
        userAvatarInitials: 'WW'
      },
      element
    );
  }
}

HTML:

<html xmlns:th="http://www.thymeleaf.org" lang="ar">
<head th:inline="text">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, maximum-scale=1">
    <title>Demo</title>
</head>
<body th:inline="text">
    <div class="chatBot" id="bot" role="main"></div>    
    <script src="file:///D:/bebop-webchat/dist/custom-webchat-4.8.0.js"></script>
    <script>
        WebChat.renderWebChat(
            {
               token: 'R-yE15Nt-hI.18_ofkIDC1mBY7GbDABIpFC8K4wjF3989JQLAEUJ2nU'
            },
            document.getElementById("bot")
        );      
    </script>
</body>
</html>

在浏览器小部件中打开 HTML 文件后,呈现如下:

在聊天中输入 hi 后,它会在控制台中抛出如下错误:

我关注了这个 https://github.com/microsoft/BotFramework-WebChat/blob/master/CHANGELOG.md 链接以获取依赖项。

如果缺少任何依赖项,请告诉我。

注意:我只在使用 botframework-webchat@4.8.0 时遇到这个问题

【问题讨论】:

标签: javascript node.js botframework web-chat


【解决方案1】:

在遵循https://github.com/microsoft/BotFramework-WebChat/issues/3046 中提到的解决方法后,我的问题得到了解决。

感谢您的支持。

【讨论】:

    【解决方案2】:

    botframework-webchat 4.8.0 版本存在问题,因此您可以修复安装 botframework-webchat@4.7.1 并确保 package.lock 文件应具有相同的 4.7.1 版本。

    【讨论】:

      猜你喜欢
      • 2021-08-15
      • 1970-01-01
      • 2014-01-26
      • 2020-06-29
      • 2019-02-13
      • 1970-01-01
      • 1970-01-01
      • 2019-10-02
      • 2019-09-02
      相关资源
      最近更新 更多