NodeJs Botframework 和 Typescript

NodeJs Botframework and Typescript

我在 node.js 和 typescript 中使用 botframework 实现了一个机器人。我已经安装了 restify 包(如前所述 here)。另外,我想通过 NodeJS 使用流程。但是,在程序中并没有发现和检测到这些(如下所示):

因此,我的问题是如何在 botframework 的打字稿中使用 restifyNodeJS 模块?

我应该提到项目的 npm 层次结构如下:

Typescript 是 javascript 的超集,因此只需将您的 js 文件重命名为 .ts,您就已经在使用它了。

所以这个例子看起来像这样:

import * as builder from "botbuilder";
import * as restify from "restify";

// Setup Restify Server 
// prefer const or let instead of var
const server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
    console.log('%s listening to %s', server.name, server.url); 
});

// Create chat bot
const connector = new builder.ChatConnector({
    appId: process.env.MICROSOFT_APP_ID,
    appPassword: process.env.MICROSOFT_APP_PASSWORD
});

const bot = new builder.UniversalBot(connector);
server.post('/api/messages', connector.listen());

//=========================================================
// Bots Dialogs
//=========================================================

bot.dialog('/', function (session) {
    session.send("Hello World");
});

由于process是node中的全局变量,你可以使用typings添加自动完成信息...

我通过在项目中添加一个 tsconfig.json 文件解决了这个问题,如下所示:

{
    "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "removeComments": false,
    "noImplicitReturns": true,
    "noImplicitAny": true,
    "preserveConstEnums": true
    },
    "files": []
}

解决的要点是file是空的。如果仅将一个文件添加到 files,您必须将所有其他预期文件添加到 files 中的文件列表中。相应地,如果您没有在 files 中提及任何文件,则默认添加所有预期的文件。

更新

另一种解决方法是删除项目中的默认脚本文件夹。以上问题均出自此文件夹!