Exemple #1
0
        // In this example we will be using a static constructor on the Controller as these objects
        // should be singletons. Most likely a production application will be using one of the
        // Dependency Injection systems from NuGet such as Autofac, Unity, Ninject etc.
        static BotController()
        {
            _loggerFactory = new LoggerFactory();

            // create the User and ConversationState objects (in this case, for testing, both based on the same memory store)
            var storage = new MemoryStorage();

            _conversationState = new ConversationState(storage);
            _userState         = new UserState(storage);

            // create the BotAdapter we will be using
            var credentialProvider = new ConfigurationCredentialProvider();

            _adapter = new AdapterWithErrorHandler(credentialProvider, _loggerFactory.CreateLogger <BotFrameworkHttpAdapter>(), _conversationState);

            // read the old style Web.Config settings and construct a new style dot net core IConfiguration object
            var appsettings = ConfigurationManager.AppSettings.AllKeys.SelectMany(
                ConfigurationManager.AppSettings.GetValues,
                (k, v) => new KeyValuePair <string, string>(k, v));

            var configuration = new ConfigurationBuilder()
                                .AddInMemoryCollection(appsettings)
                                .Build();

            // create the Dialog this bot will run - we need configuration because this Dialog will call LUIS
            _dialog = new MainDialog(configuration, _loggerFactory.CreateLogger <MainDialog>());
        }
        public async Task <string> TipMessageAsync()
        {
            TipList = new List <Tip>();
            var tipList = await MainDialog.QueryTipsAsync();

            // Rules engine here
            // Load rules
            var repository = new RuleRepository();

            repository.Load(x => x.From(typeof(TipChooseRule).Assembly));

            // Compile rules
            var factory = repository.Compile();

            // Create a working session
            var session = factory.CreateSession();

            // Insert facts into rules engine's memory
            session.Insert(PersonalDetailsDialog.PersonalDetails);
            foreach (Tip obj in tipList)
            {
                session.Insert(obj);
            }

            // Start match/resolve/act cycle
            session.Fire();


            return(RandomiseList(TipList.Select(l => l.TipMessage).ToList()));
        }
 public ChildBot(IConfiguration configuration, MainDialog dialog, ConversationState conversationState, UserState userState)
 {
     _dialog            = dialog;
     _conversationState = conversationState;
     _userState         = userState;
     _connectionName    = configuration.GetSection("ConnectionName")?.Value;
 }
Exemple #4
0
 public ParentBot(BotFrameworkHttpClient client, IConfiguration configuration, MainDialog dialog, ConversationState conversationState, UserState userState)
 {
     _client            = client;
     _dialog            = dialog;
     _conversationState = conversationState;
     _userState         = userState;
     _fromBotId         = configuration.GetSection("MicrosoftAppId")?.Value;
     _toBotId           = configuration.GetSection("SkillMicrosoftAppId")?.Value;
     _connectionName    = configuration.GetSection("ConnectionName")?.Value;
 }