配置不带.bot文件的bot

时间:2018-10-01 21:13:38

标签: botframework

是否可以在没有.bot文件的情况下在新的Microsoft Bot Framework v4中配置机器人?

我想以编程方式执行此操作,但无法在示例中找到它。

1 个答案:

答案 0 :(得分:0)

appsettings.json指向bot文件,如下所示:

{
  "botFilePath": "BotConfiguration.bot",
  "botFileSecret": ""
}

然后在startup.cs中发生这种情况:

var secretKey = Configuration.GetSection("botFileSecret")?.Value;
var botFilePath = Configuration.GetSection("botFilePath")?.Value;

// Loads .bot configuration file and adds a singleton that your Bot can access through dependency injection.
var botConfig = BotConfiguration.Load(botFilePath ?? @".\BotConfiguration.bot", secretKey);
services.AddSingleton(sp => botConfig ?? throw new InvalidOperationException($"The .bot config file could not be loaded. ({botConfig})"));

// Retrieve current endpoint.
var environment = _isProduction ? "production" : "development";
var service = botConfig.Services.Where(s => s.Type == "endpoint" && s.Name == environment).FirstOrDefault();

如果您希望在没有.bot文件的情况下进行处理,则需要对此进行更改。