public void ConfigureServices(IServiceCollection services)
public void ConfigureServices(IServiceCollection services)
{
{
services.AddBot<SimplePromptBot>(options =>
services.AddBot<SimplePromptBot>(options =>
{
{
var secretKey = Configuration.GetSection("botFileSecret")?.Value;
var secretKey = Configuration.GetSection("botFileSecret")?.Value;
var botFilePath = Configuration.GetSection("botFilePath")?.Value;
var botFilePath = Configuration.GetSection("botFilePath")?.Value;
if (!File.Exists(botFilePath))
if (!File.Exists(botFilePath))
{
{
throw new FileNotFoundException($"The .bot configuration file was not found. botFilePath: {botFilePath}");
throw new FileNotFoundException($"The .bot configuration file was not found. botFilePath: {botFilePath}");
}
}
// Loads .bot configuration file and adds a singleton that your Bot can access through dependency injection.
// Loads .bot configuration file and adds a singleton that your Bot can access through dependency injection.
var botConfig = BotConfiguration.Load(botFilePath ?? @".\simple-prompt.bot", secretKey);
var botConfig = BotConfiguration.Load(botFilePath ?? @".\simple-prompt.bot", secretKey);
services.AddSingleton(sp => botConfig ?? throw new InvalidOperationException($"The .bot configuration file could not be loaded. botFilePath: {botFilePath}"));
services.AddSingleton(sp => botConfig ?? throw new InvalidOperationException($"The .bot configuration file could not be loaded. botFilePath: {botFilePath}"));
// Retrieve current endpoint.
// Retrieve current endpoint.
var environment = _isProduction ? "production" : "development";
var environment = _isProduction ? "production" : "development";
var service = botConfig.Services.FirstOrDefault(s => s.Type == "endpoint" && s.Name == environment);
var service = botConfig.Services.FirstOrDefault(s => s.Type == "endpoint" && s.Name == environment);
if (!(service is EndpointService endpointService))
if (!(service is EndpointService endpointService))
{
{
throw new InvalidOperationException($"The .bot file does not contain an endpoint with name '{environment}'.");
throw new InvalidOperationException($"The .bot file does not contain an endpoint with name '{environment}'.");
}
}
options.CredentialProvider = new SimpleCredentialProvider(endpointService.AppId, endpointService.AppPassword);
options.CredentialProvider = new SimpleCredentialProvider(endpointService.AppId, endpointService.AppPassword);