Skip to content

Commit

Permalink
Load bot credentials from an .env file (#138)
Browse files Browse the repository at this point in the history
* Added an Extensions module for the chatbot
  • Loading branch information
MrDave1999 authored Jan 15, 2023
1 parent 5111cd8 commit f8604f2
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 3 deletions.
10 changes: 9 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,12 @@ DENTAL_SERVICES_IMAGES_PATH=/home/DentalServices
REMINDER_TIME_IN_ADVANCE=1 # In days.
# Indicates the schedule at which the reminder will be sent.
# The schedule must be a cron expression.
REMINDER_CRON_EXPR=0 0 8 * * ? * # At 08:00:00am every day.
REMINDER_CRON_EXPR=0 0 8 * * ? * # At 08:00:00am every day.

#
# Bot credentials
#
MICROSOFT_APP_TYPE=
MICROSOFT_APP_ID=
MICROSOFT_APP_PASSWORD=
MICROSOFT_APP_TENANT_ID=
9 changes: 9 additions & 0 deletions src/Configuration/BotSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace DentallApp.Configuration;

public class BotSettings
{
public string MicrosoftAppType { get; set; }
public string MicrosoftAppId { get; set; }
public string MicrosoftAppPassword { get; set; }
public string MicrosoftAppTenantId { get; set; }
}
14 changes: 14 additions & 0 deletions src/Features/Chatbot/Extensions/ConfigurationExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace DentallApp.Features.Chatbot.Extensions;

public static class ConfigurationExtensions
{
public static IConfiguration SetBotCredentials(this IConfiguration configuration)
{
var botSettings = new EnvBinder().Bind<BotSettings>();
configuration[MicrosoftAppCredentials.MicrosoftAppTypeKey] = botSettings.MicrosoftAppType .Trim();
configuration[MicrosoftAppCredentials.MicrosoftAppIdKey] = botSettings.MicrosoftAppId .Trim();
configuration[MicrosoftAppCredentials.MicrosoftAppPasswordKey] = botSettings.MicrosoftAppPassword.Trim();
configuration[MicrosoftAppCredentials.MicrosoftAppTenantIdKey] = botSettings.MicrosoftAppTenantId.Trim();
return configuration;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace DentallApp.Features.Chatbot;
namespace DentallApp.Features.Chatbot.Extensions;

public static class ServiceCollectionExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace DentallApp.Features.Chatbot;
namespace DentallApp.Features.Chatbot.Extensions;

public static class WaterfallStepContextExtensions
{
Expand Down
1 change: 1 addition & 0 deletions src/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
global using DentallApp.Features.Chatbot.Helpers;
global using DentallApp.Features.Chatbot.Models;
global using DentallApp.Features.Chatbot.Handlers;
global using DentallApp.Features.Chatbot.Extensions;
global using DentallApp.Features.GeneralTreatments;
global using DentallApp.Features.GeneralTreatments.DTOs;
global using DentallApp.Features.SpecificTreatments;
Expand Down
1 change: 1 addition & 0 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
builder.Services.AddSendGrid(options => options.ApiKey = settings.SendGridApiKey);
builder.Services.AddSwagger();
builder.Services.AddAuthenticationJwtBearer(settings);
builder.Configuration.SetBotCredentials();
builder.Services.AddBotServices();
builder.Services.AddQuartzJobs(settings);

Expand Down

0 comments on commit f8604f2

Please sign in to comment.