/// <summary> /// Initializes a new instance of the <see cref="SyntinelBot" /> class. /// </summary> /// <param name="accessors">A class containing <see cref="IStatePropertyAccessor{T}" /> used to manage state.</param> /// <param name="logger">A <see cref="ILogger" /> The logger.</param> /// <seealso /// cref="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-2.1#windows-eventlog-provider" /> /// <param name="config">A <see cref="IConfiguration" /> Application configuration.</param> /// TODO: WIP public SyntinelBot(BotAccessors accessors, ILogger <SyntinelBot> logger, IConfiguration config) { try { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _config = config ?? throw new ArgumentNullException(nameof(config)); _accessors = accessors ?? throw new ArgumentNullException(nameof(accessors)); _appId = _config.GetSection("MicrosoftAppId")?.Value; _password = _config.GetSection("MicrosoftAppPassword")?.Value; _welcomeText = _config.GetSection("WelcomeText")?.Value; _msteamsMention = _config.GetSection("MsTeamsMention")?.Value ?? string.Empty; _slackMention = _config.GetSection("SlackMention")?.Value ?? string.Empty; _cardLocation = _config.GetSection("CardLocation")?.Value; _syntinelBaseUrl = _config.GetSection("SyntinelBaseUrl")?.Value; _syntinelSlackCueUrl = _config.GetSection("SyntinelSlackCueUrl")?.Value; _syntinelTeamsCueUrl = _config.GetSection("SyntinelTeamsCueUrl")?.Value; _awsRegion = _config.GetSection("AwsRegion")?.Value; _awsAccessKey = _config.GetSection("AwsAccessKey")?.Value; _awsSecretKey = _config.GetSection("AwsSecretKey")?.Value; if (_config.GetSection("UserRegistryInDatabase")?.Value != "true") { _logger.LogInformation("Loading user registry from appsettings.json..."); _registeredUsers = _config.Get <RegisteredUsers>(); } _logger.LogInformation("Syntinel turn starts."); // The DialogSet needs a DialogState accessor, it will call it when it has a turn context. _dialogs = new DialogSet(accessors.ConversationDialogState); // This array defines how the Waterfall will execute. var waterfallSteps = new WaterfallStep[] { ProcessMessagesAsync, }; _dialogs.Add(new WaterfallDialog("processMessages", waterfallSteps)); _dialogs.Add(new ConfirmPrompt("confirm")); } catch (Exception ex) { _logger.LogError(ex.Message); } }
private async Task LoadUserRegistryAsync(ITurnContext turnContext) { if (_registeredUsers == null) { if (_accessors == null) { _logger.LogError("Database cannot be accessed as accessor is null."); return; } _logger.LogInformation("Loading user registry from database..."); _registeredUsers = await _accessors.UserRegistryAccessor.GetAsync(turnContext, () => new RegisteredUsers()); _logger.LogInformation($"Registered User Count: {_registeredUsers?.Users?.Count}"); var state = _registeredUsers; // Set the property using the accessor. await _accessors.UserRegistryAccessor.SetAsync(turnContext, state); // Save the new turn count into the conversation state. await _accessors.ServiceState.SaveChangesAsync(turnContext); } }