在chatbot中编译打字稿

时间:2020-01-16 12:10:32

标签: node.js typescript visual-studio-code

我正在尝试创建一个聊天机器人,正在关注youtube上的教程

https://www.youtube.com/watch?v=cYuWse7GB9E

但是,在本教程的最后,您可以使用Ctrl + Shift + b命令构建打字稿

我的tsconfig.json文件看起来像这样

{
    "conpileOnSave":true,
    "compileOptions":{
    "module":"commonjs",
    "target":"es6",
    "sourceMap":true,
    "declaration":false,
    "removeComments":true,
    "outDir":"./dist",
    "allowJs":true
    },
    "files":[
    "./lib/types.ts",
    "./lib/app.ts"
    ]
}

我的app.ts文件看起来像这样

import { BotFrameworkAdapter, MemoryStorage,ConversationState } from "botbuilder";
import * as restify from "restify";
//import { ConfState } from "./types";

let server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, () => {
    console.log(`${server.name} listening on ${server.url}`);
})

const adaptor = new BotFrameworkAdapter({
    appId: process.env.MICROSOFT_APP_ID,
    appPassword: process.env.MICROSOFT_APP_PASSWORD
});

let conversationState;

const memoryStorage = new MemoryStorage();
conversationState = new ConversationState(memoryStorage);

//const conversationState = new ConversationState(new MemoryStorage());
adaptor.use(conversationState);

server.post("/api/messages",(req,res) => {
    adaptor.processActivity(req,res,async(context) =>{
    if(context.activity.type === "message") {
        const state = conversationState.get(context);
        await context.sendActivity(`you said ${context.activity.text}`);
    } else {
        await context.sendActivity(`${context.activity.type} event detected`);
    }
    })
});

我的问题是它可以构建,但是没有任何错误,但是“ dist”文件夹中什么也没有构建,因此当我运行包含此代码的“ node server.js”时

module.exports = require("./dist/app");

它引发错误

internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module './dist/app'

任何人都知道哪里出了问题。我已将dist文件夹的权限更改为完全,但什么都没有。

谢谢

我的完整源代码可以在这里找到

https://github.com/andrewslaughter/chatbot/tree/master/video2

0 个答案:

没有答案