Example #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton(_ => Configuration);
            services.AddBot <LitwareRoot>(options =>
            {
                options.CredentialProvider = new ConfigurationCredentialProvider(Configuration);

                var luisOptions = new LuisRequest {
                    Verbose = true
                };
                options.Middleware.Add(new LuisRecognizerMiddleware(
                                           new LuisModel(
                                               "653f443e-da2d-43ee-ae47-8da7a836fc25",
                                               "be30825b782843dcbbe520ac5338f567",
                                               new Uri("https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/")), luisOptions: luisOptions));

                var qnamakerEndpoint = new QnAMakerEndpoint
                {
                    EndpointKey     = "d534abd71a0d438d95d5a001025ee074",
                    Host            = "https://westus.api.cognitive.microsoft.com/qnamaker/v2.0",
                    KnowledgeBaseId = "40080f40-0200-482e-8e55-fae74d973490"
                };
                var qnamakerOptions = new QnAMakerMiddlewareOptions
                {
                    EndActivityRoutingOnAnswer = true
                };
                options.Middleware.Add(new QnAMakerMiddleware(qnamakerEndpoint, qnamakerOptions));
            });
        }
Example #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddBot <QnABot>(options =>
            {
                options.CredentialProvider = new ConfigurationCredentialProvider(Configuration);

                var qnaOptions = new QnAMakerMiddlewareOptions
                {
                    // add subscription key and knowledge base id
                    SubscriptionKey            = "56da5b3610a2480e9744cf01893dcd9a",
                    KnowledgeBaseId            = "52990674-78a4-4dac-a67d-3804aeb43fe0",
                    EndActivityRoutingOnAnswer = false
                };

                var middleware = options.Middleware;
                Dictionary <string, List <string> > patterns = new Dictionary <string, List <string> >();
                patterns.Add("fr", new List <string> {
                    "mon nom est (.+)"
                });                                                         //single pattern for fr language
                middleware.Add(new ConversationState <CurrentUserState>(new MemoryStorage()));
                middleware.Add(new TranslationMiddleware(new string[] { "en" }, "bd90529b71e9445286125ab853177c0b", patterns, TranslatorLocaleHelper.GetActiveLanguage, TranslatorLocaleHelper.CheckUserChangedLanguage, true));
                middleware.Add(new LocaleConverterMiddleware(TranslatorLocaleHelper.GetActiveLocale, TranslatorLocaleHelper.CheckUserChangedLocale, "en-us", LocaleConverter.Converter));
                middleware.Add(new QnAMakerMiddleware(qnaOptions));
            });
        }
Example #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddBot <QnAMakerBot>(options =>
            {
                options.CredentialProvider = new ConfigurationCredentialProvider(Configuration);

                var qnaOptions = new QnAMakerMiddlewareOptions
                {
                    // add subscription key and knowledge base id
                    SubscriptionKey            = "xxxxxx",
                    KnowledgeBaseId            = "xxxxxx",
                    EndActivityRoutingOnAnswer = false
                };

                var middleware = options.Middleware;
                Dictionary <string, List <string> > patterns = new Dictionary <string, List <string> >();
                patterns.Add("fr", new List <string> {
                    "mon nom est (.+)"
                });                                                         //single pattern for fr language
                middleware.Add(new ConversationState <CurrentUserState>(new MemoryStorage()));
                middleware.Add(new TranslationMiddleware(new string[] { "en" }, "<your translator key here>", patterns, TranslatorLocaleHelper.GetActiveLanguage, TranslatorLocaleHelper.CheckUserChangedLanguage, true));
                middleware.Add(new LocaleConverterMiddleware(TranslatorLocaleHelper.GetActiveLocale, TranslatorLocaleHelper.CheckUserChangedLocale, "en-us", LocaleConverter.Converter));
                middleware.Add(new QnAMakerMiddleware(qnaOptions));
            });
        }
Example #4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddBot <CafeBot>(options =>
            {
                options.CredentialProvider = new ConfigurationCredentialProvider(Configuration);

                // The CatchExceptionMiddleware provides a top-level exception handler for your bot.
                // Any exceptions thrown by other Middleware, or by your OnTurn method, will be
                // caught here. To facillitate debugging, the exception is sent out, via Trace,
                // to the emulator. Trace activities are NOT displayed to users, so in addition
                // an "Ooops" message is sent.
                options.Middleware.Add(new CatchExceptionMiddleware <Exception>(async(context, exception) =>
                {
                    await context.TraceActivity("EchoBot Exception", exception);
                    await context.SendActivity("Sorry, it looks like something went wrong!");
                }));

                // The Memory Storage used here is for local bot debugging only. When the bot
                // is restarted, anything stored in memory will be gone.
                IStorage conversationDataStore = new MemoryStorage();
                IStorage userDataStore         = new MemoryStorage();

                // The File data store, shown here, is suitable for bots that run on
                // a single machine and need durable state across application restarts.
                // IStorage dataStore = new FileStorage(System.IO.Path.GetTempPath());

                // For production bots use the Azure Table Store, Azure Blob, or
                // Azure CosmosDB storage provides, as seen below. To include any of
                // the Azure based storage providers, add the Microsoft.Bot.Builder.Azure
                // Nuget package to your solution. That package is found at:
                //      https://www.nuget.org/packages/Microsoft.Bot.Builder.Azure/

                // IStorage dataStore = new Microsoft.Bot.Builder.Azure.AzureTableStorage("AzureTablesConnectionString", "TableName");
                // IStorage dataStore = new Microsoft.Bot.Builder.Azure.AzureBlobStorage("AzureBlobConnectionString", "containerName");

                options.Middleware.Add(new ConversationState <CafeBotConvState>(conversationDataStore));
                options.Middleware.Add(new UserState <CafeBotUserState>(userDataStore));

                var qEndpoint = new QnAMakerEndpoint()
                {
                    Host            = "https://contosocafeqnamaker.azurewebsites.net/qnamaker",
                    EndpointKey     = "09e2d55b-a44c-41b6-a08a-76a7df9ddffe",
                    KnowledgeBaseId = "b5534d70-bded-45e1-998a-5945174d4ff3"
                };
                var qOptions = new QnAMakerMiddlewareOptions()
                {
                    ScoreThreshold = 0.4F,
                    Top            = 1
                };
                var qnamaker = new QnAMaker(qEndpoint, qOptions);
                options.Middleware.Add(new QnAMakerMiddleware(qEndpoint, qOptions));
            });
        }
Example #5
0
 public MessagesController(IConfiguration configuration)
 {
     if (adapter == null)
     {
         var qnaOptions = new QnAMakerMiddlewareOptions
         {
             // add subscription key and knowledge base id
             SubscriptionKey = "xxxxxx",
             KnowledgeBaseId = "xxxxxx"
         };
         adapter = new BotFrameworkAdapter(new ConfigurationCredentialProvider(configuration))
                   // add QnA middleware
                   .Use(new QnAMakerMiddleware(qnaOptions, _httpClient));
     }
 }
Example #6
0
        public MessagesController(IConfiguration configuration)
        {
            var qnaMiddlewareOptions = new QnAMakerMiddlewareOptions
            {
                // add subscription key and knowledge base id
                SubscriptionKey = "xxxxxx",
                KnowledgeBaseId = "xxxxxx"
            };
            var bot = new Builder.Bot(new BotFrameworkAdapter(configuration))
                      // add QnA middleware
                      .Use(new QnAMakerMiddleware(qnaMiddlewareOptions, _httpClient));

            bot.OnReceive(BotReceiveHandler);

            _adapter = (BotFrameworkAdapter)bot.Adapter;
        }
Example #7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddBot <QnAMakerBot>(options =>
            {
                options.CredentialProvider = new ConfigurationCredentialProvider(Configuration);

                var qnaOptions = new QnAMakerMiddlewareOptions
                {
                    // add subscription key and knowledge base id
                    SubscriptionKey = "xxxxxx",
                    KnowledgeBaseId = "xxxxxx"
                };

                var middleware = options.Middleware;
                middleware.Add(new QnAMakerMiddleware(qnaOptions));
            });
        }
Example #8
0
 public QnAMakerMiddleware(QnAMakerMiddlewareOptions options)
 {
     qaOptions = options ?? throw new ArgumentNullException(nameof(options));
     qnAMaker  = new QnAMaker(options);
 }