// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddBot <PersonalityChatBotCustomResponses>(options => { options.CredentialProvider = new ConfigurationCredentialProvider(Configuration); var middleware = options.Middleware; var scenarioResponses = File.ReadAllLines(@"./Resources/CustomResponses.txt"); var scenarioResponsesMapping = new Dictionary <string, List <string> >(); foreach (var scenarioResponse in scenarioResponses) { string scenario = scenarioResponse.Split('\t')[0]; string response = scenarioResponse.Split('\t')[1]; if (!scenarioResponsesMapping.ContainsKey(scenario)) { scenarioResponsesMapping[scenario] = new List <string>(); } scenarioResponsesMapping[scenario].Add(response); } var personalityChatOptions = new PersonalityChatMiddlewareOptions(scenarioResponsesMapping: scenarioResponsesMapping, endActivityRoutingOnResponse: false); middleware.Add(new PersonalityChatMiddleware(personalityChatOptions, new HttpClient())); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddBot <PersonalityChatBasicBot>(options => { options.CredentialProvider = new ConfigurationCredentialProvider(Configuration); var middleware = options.Middleware; var personalityChatOptions = new PersonalityChatMiddlewareOptions(botPersona: Core.PersonalityChatPersona.Humorous, respondOnlyIfChat: true, scoreThreshold: 0.5F); middleware.Add(new PersonalityChatMiddleware(personalityChatOptions)); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddBot <PersonalityChatWeatherBot>(options => { options.CredentialProvider = new ConfigurationCredentialProvider(Configuration); var middleware = options.Middleware; var personalityChatOptions = new PersonalityChatMiddlewareOptions(respondOnlyIfChat: true); middleware.Add(new PersonalityChatMiddleware(personalityChatOptions)); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddBot <BasicPersonalityChatBot>(options => { options.CredentialProvider = new ConfigurationCredentialProvider(Configuration); var middleware = options.Middleware; var personalityChatOptions = new PersonalityChatMiddlewareOptions(); middleware.Add(new PersonalityChatMiddleware(personalityChatOptions)); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddBot <BasicPersonalityChatBot>(options => { options.CredentialProvider = new ConfigurationCredentialProvider(Configuration); var middleware = options.Middleware; var personalityChatOptions = new PersonalityChatMiddlewareOptions(endActivityRoutingOnResponse: false); middleware.Add(new PersonalityChatMiddleware(personalityChatOptions, new HttpClient())); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.Configure <MySettings>(Configuration); services.AddBot <EchoBot>(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 dataStore = 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 <ReservationData>(dataStore)); options.Middleware.Add( new TranslatorSpeechMiddleware( Configuration["TranslatorSpeechSubscriptionKey"], Configuration["TranslatorTextSubscriptionKey"], Configuration["VoiceFontName"], Configuration["VoiceFontLanguage"] ) ); options.Middleware.Add( new LuisRecognizerMiddleware( new LuisModel( "xxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxx", new Uri("https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/") ) ) ); options.Middleware.Add( new QnAMakerMiddleware( new QnAMakerEndpoint { Host = "https://build-qna-xxxxx.azurewebsites.net/qnamaker", EndpointKey = "xxxxxxxxxxxxxxxxxxxxxxxxx", KnowledgeBaseId = "xxxxxxxxxxxxxxxxxxxxxxxxx" }, new QnAMakerMiddlewareOptions { EndActivityRoutingOnAnswer = true, ScoreThreshold = 0.9f } ) ); var personalityChatOptions = new PersonalityChatMiddlewareOptions( respondOnlyIfChat: true, scoreThreshold: 0.5F, botPersona: PersonalityChatPersona.Professional ); options.Middleware.Add(new PersonalityChatMiddleware(personalityChatOptions)); }); }
public PersonalityChatMiddleware(PersonalityChatMiddlewareOptions personalityChatMiddlewareOptions) { this.personalityChatMiddlewareOptions = personalityChatMiddlewareOptions ?? throw new ArgumentNullException(nameof(personalityChatMiddlewareOptions)); this.personalityChatService = new PersonalityChatService(personalityChatMiddlewareOptions); }
/// <summary> /// This method gets called by the runtime. Use this method to add services to the container. /// </summary> /// <param name="services">The <see cref="IServiceCollection"/> specifies the contract for a collection of service descriptors.</param> /// <seealso cref="IStatePropertyAccessor{T}"/> /// <seealso cref="https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/dependency-injection"/> /// <seealso cref="https://docs.microsoft.com/en-us/azure/bot-service/bot-service-manage-channels?view=azure-bot-service-4.0"/> public void ConfigureServices(IServiceCollection services) { services.Configure <MySettings>(Configuration); services.AddMvc(); //#if DEBUG // services.AddMvc(); //#else // services.AddMvc(mvcConfig => // { // mvcConfig.Filters.Add(new BasicAuthFilter(Configuration["BasicAuthUsername"], Configuration["BasicAuthPassword"])); // }); //#endif // create luis recognizer var luisApplication = new LuisApplication( Configuration["LuisAppId"], Configuration["LuisAPIKey"], "https://" + Configuration["LuisAPIHostName"]); services.AddSingleton(new LuisRecognizer(luisApplication)); // Create the credential provider to be used with the Bot Framework Adapter. services.AddSingleton <ICredentialProvider, ConfigurationCredentialProvider>(); // Create the Bot Framework Adapter with error handling enabled. services.AddSingleton <IBotFrameworkHttpAdapter, AdapterWithErrorHandler>(); // Create the storage we'll be using for User and Conversation state. (Memory is great for testing purposes.) services.AddSingleton <IStorage, MemoryStorage>(); // Create the User state. (Used in this bot's Dialog implementation.) services.AddSingleton <UserState>(); // Create the Conversation state. (Used by the Dialog system itself.) services.AddSingleton <ConversationState>(); // The Dialog that will be run by the bot. services.AddSingleton <ReservationDialog>(); // Memory Storage is for local bot debugging only. When the bot // is restarted, everything stored in memory will be gone. IStorage dataStore = new MemoryStorage(); // Create and add conversation state. var conversationState = new ConversationState(dataStore); services.AddSingleton(conversationState); var userState = new UserState(dataStore); services.AddSingleton(userState); // Add the personality chat middleware var personalityChatOptions = new PersonalityChatMiddlewareOptions( respondOnlyIfChat: true, scoreThreshold: 0.5F, botPersona: PersonalityChatPersona.Humorous); services.AddSingleton(new PersonalityChatMiddleware(personalityChatOptions)); // Add the translator speech middleware services.AddTransient <IBot, EchoBot>(); // Create and register state accessors. // Accessors created here are passed into the IBot-derived class on every turn. services.AddSingleton(sp => { // We need to grab the conversationState we added on the options in the previous step var options = sp.GetRequiredService <IOptions <BotFrameworkOptions> >().Value; if (options == null) { throw new InvalidOperationException("BotFrameworkOptions must be configured prior to setting up the State Accessors"); } // Create the custom state accessor. // State accessors enable other components to read and write individual properties of state. var accessors = new EchoBotAccessors(conversationState, userState) { // Initialize Dialog State ConversationDialogState = conversationState.CreateProperty <DialogState>("DialogState"), ReservationState = userState.CreateProperty <ReservationData>("ReservationState"), }; return(accessors); }); // Add QnA Maker here // We add the the QnA service to the connected services. // Create and register a QnA service and knowledgebase services.AddSingleton(sp => { return(new QnAMaker( new QnAMakerEndpoint { EndpointKey = Configuration["QnAEndpointKey"], Host = Configuration["QnAHostname"], KnowledgeBaseId = Configuration["QnAKbId"], }, new QnAMakerOptions { ScoreThreshold = 0.9f, Top = 1, })); }); }