Exemplo n.º 1
0
        public static IServiceCollection AddAlexa(this IServiceCollection services)
        {
            // The Dialog that will be run by the bot.
            services.TryAddTransient <HeroDialog>();

            // Create the Alexa bot as a transient. In this case the ASP Controller is expecting an IBot.
            services.TryAddTransient <AlexaHeroBot <HeroDialog> >();

            services.TryAddSingleton <IAlexaHttpAdapter>(_ =>
            {
                var alexaHttpAdapter = new AlexaHttpAdapter(validateRequests: true)
                {
                    OnTurnError = async(context, exception) =>
                    {
                        await context.SendActivityAsync("<say-as interpret-as=\"interjection\">boom</say-as>, explotó.");
                    },
                    ShouldEndSessionByDefault          = false,
                    ConvertBotBuilderCardsToAlexaCards = false,
                };
                alexaHttpAdapter.Use(new AlexaIntentRequestToMessageActivityMiddleware(transformPattern: RequestTransformPatterns.MessageActivityTextFromSinglePhraseSlotValue));
                return(alexaHttpAdapter);
            });

            return(services);
        }
Exemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            // 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 Conversation state. (Used by the Dialog system itself.)
            services.AddSingleton <ConversationState>();

            // Create the bot as a transient. In this case the ASP Controller is expecting an IBot.
            services.AddTransient <IBot, Bots.StoryBot <QnAStoryDialog> >();

            // Add all Dialogs we are gonna use
            services.AddDialogs();

            // Add Luis Service
            services.AddLuisService(_configuration.GetSection("LuisService").Get <LuisService>());

            // Add Multiturn QnA Service
            services.AddQnAService();

            // Add Alexa Adapter
            services.AddSingleton <IAlexaHttpAdapter>(_ =>
            {
                var alexaHttpAdapter = new AlexaHttpAdapter(validateRequests: true)
                {
                    OnTurnError = async(context, exception) =>
                    {
                        await context.SendActivityAsync("<say-as interpret-as=\"interjection\">boom</say-as>, explotó.");
                    },
                    ShouldEndSessionByDefault          = false,
                    ConvertBotBuilderCardsToAlexaCards = true,
                };
                alexaHttpAdapter.Use(new AlexaIntentRequestToMessageActivityMiddleware(transformPattern: RequestTransformPatterns.MessageActivityTextFromSinglePhraseSlotValue));
                return(alexaHttpAdapter);
            });
        }