public AdapterWithErrorHandler(ICredentialProvider credentialProvider, ILogger <BotFrameworkHttpAdapter> logger, ActiveConversationsStore activeConversationsStore, ConversationState conversationState = null) : base(credentialProvider) { _activeConversationsStore = activeConversationsStore; OnTurnError = async(turnContext, exception) => { logger.LogError($"Exception caught : {exception.Message}"); if (conversationState != null) { try { // Delete the conversationState for the current conversation to prevent the // bot from getting stuck in a error-loop caused by being in a bad state. // ConversationState should be thought of as similar to "cookie-state" in a Web pages. await conversationState.DeleteAsync(turnContext); var conversationId = turnContext.Activity.GetConversationReference().Conversation.Id; await _activeConversationsStore.RemoveConversationOnError(conversationId); } catch (Exception e) { logger.LogError($"Exception caught on attempting to Delete ConversationState : {e.Message}"); } } }; }
public FitnessBot(BotServices services, UserState userState, ConversationState conversationState, IEnumerable <IBotCommand> botCommands, ActiveConversationsStore activeConversationsStore, IDisplayAdvice advice, GreetingStateStore greetingStateStore) { _services = services ?? throw new ArgumentNullException(nameof(services)); _userState = userState ?? throw new ArgumentNullException(nameof(userState)); _conversationState = conversationState ?? throw new ArgumentNullException(nameof(conversationState)); _botCommands = botCommands; _activeConversationsStore = activeConversationsStore; _advice = advice; _greetingStateStore = greetingStateStore; _greetingStateAccessor = _userState.CreateProperty <GreetingState>(nameof(GreetingState)); _answersStateAccessor = _userState.CreateProperty <AnswerState>(nameof(AnswerState)); _targetSetupStateAccessor = _userState.CreateProperty <TargetSetupState>(nameof(TargetSetupState)); _dialogStateAccessor = _conversationState.CreateProperty <DialogState>(nameof(DialogState)); if (!_services.LuisServices.ContainsKey(LuisConfiguration)) { throw new InvalidOperationException($"The bot configuration does not contain a service type of `luis` with the id `{LuisConfiguration}`."); } Dialogs = new DialogSet(_dialogStateAccessor); Dialogs.Add(new GreetingDialog(_greetingStateAccessor)); Dialogs.Add(new AnswerDialog(_answersStateAccessor)); Dialogs.Add(new TargetSetupDialog(_targetSetupStateAccessor)); Dialogs.Add(new AdviceDialog(_services.LuisServices[LuisConfiguration], _advice, _greetingStateAccessor)); }
public TriggerController(IBotFrameworkHttpAdapter adapter, ICredentialProvider credentials, ActiveConversationsStore activeConversationsStore, ConversationState conversationState, UserState userState) { _adapter = adapter; _activeConversationsStore = activeConversationsStore; _conversationState = conversationState; _userState = userState; _appId = ((SimpleCredentialProvider)credentials).AppId; }