是否可以在没有.bot文件的情况下在新的Microsoft Bot Framework v4中配置机器人?
我想以编程方式执行此操作,但无法在示例中找到它。
答案 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文件的情况下进行处理,则需要对此进行更改。