Beispiel #1
0
        public static void AddPsychologyBot(this IServiceCollection services, IConfiguration configuration, ILoggerFactory loggerFactory)
        {
            ILogger <Startup> logger = loggerFactory.CreateLogger <Startup>();

            IStorage          dataStore         = new MemoryStorage();
            ConversationState conversationState = new ConversationState(dataStore);
            UserState         userState         = new UserState(dataStore);
            ConfigurationCredentialProvider credentialProvider = new ConfigurationCredentialProvider(configuration);

            ConversationStateAccessors conversationStateAccessors = new ConversationStateAccessors(conversationState);

            services.AddSingleton(dataStore);
            services.AddSingleton(conversationState);
            services.AddSingleton(userState);
            services.AddSingleton(credentialProvider);
            services.AddSingleton(conversationStateAccessors);

            services.AddBot <Bot>(options =>
            {
                options.CredentialProvider = credentialProvider;

                options.OnTurnError = async(context, exception) =>
                {
                    logger.LogError(exception.Message, exception);
                    await context.SendActivityAsync("Sorry, it looks like something went wrong.");
                    await context.SendActivityAsync($"EXCEPTION: {exception.Message}");
                };

                options.Middleware.Add(new ShowTypingMiddleware());
                options.Middleware.Add(new AutoSaveStateMiddleware(userState, conversationState));
            });
        }
Beispiel #2
0
        public UserRegistrationDialog(
            ConversationStateAccessors conversationStateAccessors,
            IUserBotRepository userRepository,
            IHubContext <ChatHub> chatHub)
            : base(DialogId)
        {
            this.conversationStateAccessors = conversationStateAccessors;
            this.userRepository             = userRepository;
            this.chatHub = chatHub;

            this.userFaker = new Faker();

            WaterfallStep[] steps =
            {
                this.AskForRegistration,
                this.AskGender,
                this.ApplyGender,
                this.SuggestName,
                this.Register
            };

            this.AddDialog(new WaterfallDialog(WaterfallDialogId, steps));

            this.AddDialog(new ChoicePrompt(ChoicePromptId));

            this.AddDialog(new ConfirmPrompt(ConfirmPromptId));
        }
Beispiel #3
0
        public Bot(
            IUserBotRepository userRepository,
            ConversationStateAccessors conversationStateAccessors,
            UserRegistrationDialog userRegistrationDialog,
            IHubContext <ChatHub> chatHub,
            ILogger <Bot> logger)
        {
            this.userRepository             = userRepository;
            this.conversationStateAccessors = conversationStateAccessors;
            this.chatHub = chatHub;

            this.dialogs = new DialogSet(this.conversationStateAccessors.DialogStateAccessor);
            this.dialogs.Add(userRegistrationDialog);
        }