如何将Bot Framework对话框拆分为不同的文件 [英] How can I split Bot Framework Dialogs in different files

查看:196
本文介绍了如何将Bot Framework对话框拆分为不同的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使我的bot代码更易于管理,并将一些对话框合并在一起放在不同的文件中.

I am trying to make my bot code a bit more manageable and put some dialogs which belong together in different files.

这里有一个关于JavaScript的类似的古老问题.

但是我正在努力用Typescript做同样的事情.可能这是一个更普通的Typescript问题,因为我是一个初学者,但对于不同的导入可能性仍然有些困惑,但是我没有找到任何适用于此的常规解决方案.

But I am struggling to do the same with Typescript. Probably this is more a general Typescript question as I am a beginner and still am a bit confused about the different import possibilities, but I didn't find any general solution which I was able to apply to this.

我试过的是这个

//testdialog.ts

export default (bot) => {
bot.dialog("/Test", [
    (session, args, next) => {
        console.log("test".green);
        session.send(`Test Dialog triggered`);
    },
]).triggerAction({ matches: "test" });
}

,然后在app.ts中将其导入,类似于以下内容:
import testdialog = require("./testdialog")(bot);

and then in app.ts import it similar to this:
import testdialog = require("./testdialog")(bot);

但是,与以bot作为JS中的参数的未命名导入相比,这似乎是完全错误的,例如require('./cars.js')(bot);

But seems like this seems completely wrong compared to an unnamed import with bot as a parameter in JS like this require('./cars.js')(bot);

推荐答案

我认为,您可以利用builder.Library()来满足您的要求.

In my opinion, you can leverage builder.Library() to achieve your requirement.

//testdialog.ts
import * as builder from 'botbuilder';

export const createLibrary = () => {
    let lib = new builder.Library('test');
    lib.dialog('test', (session) => {
        session.send('this is test dialog');
    }).triggerAction({
        matches: /test/
    });
    return lib.clone();
}

//app.ts
import * as restify from 'restify';
import * as builder from 'botbuilder';
import * as testDialog from './testdialog';

let server = restify.createServer({});
server.listen(3978, function () {
    console.log('%s listening to %s', server.name, server.url);
})

let connector = new builder.ChatConnector({});

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

bot.dialog('/', (session) => {
    session.send('welcome');
})

bot.library(testDialog.createLibrary())

这篇关于如何将Bot Framework对话框拆分为不同的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆