question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Alexa Adapter - MVC and middleware

See original GitHub issue

Hello BotBuilderCommunity!

I’m trying to use Alexa Adapter in .Net Core MVC. All works fine but I’m not able to use AlexaIntentRequestToMessageActivityMiddleware. It never transform Alexa Intent requests into MessageActivities.

My code looks like this:

public void ConfigureServices(IServiceCollection services)
{
	services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

	if (!string.IsNullOrEmpty(Configuration[BotOpenIdMetadataKey]))
		ChannelValidation.OpenIdMetadataUrl = Configuration[BotOpenIdMetadataKey];

	// Create the credential provider to be used with the Bot Framework Adapter.
	services.AddSingleton<ICredentialProvider, ConfigurationCredentialProvider>();

	services.AddSingleton<IChannelProvider, ConfigurationChannelProvider>();

	// Registering the AlexaHttpAdapter
	services.AddSingleton<IAlexaHttpAdapter>((sp) =>
	{
		var alexaHttpAdapter = new AlexaHttpAdapter(validateRequests: true)
		{
			OnTurnError = async (context, exception) =>
			{
				await context.SendActivityAsync("Sorry, something went wrong");
			},
			ShouldEndSessionByDefault = true,
			ConvertBotBuilderCardsToAlexaCards = false,
		};

		return alexaHttpAdapter;
	});

	services.AddSingleton<AlexaIntentRequestToMessageActivityMiddleware>();

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

Do you have any suggestion how to make it working?

Regards, Maciej

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mwnowickicommented, May 1, 2019

Hi Gary,

Thank for the clue. I update code and it works correctly now.

Code:

public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            if (!string.IsNullOrEmpty(Configuration[BotOpenIdMetadataKey]))
                ChannelValidation.OpenIdMetadataUrl = Configuration[BotOpenIdMetadataKey];

            // Create the credential provider to be used with the Bot Framework Adapter.
            services.AddSingleton<ICredentialProvider, ConfigurationCredentialProvider>();

            services.AddSingleton<IChannelProvider, ConfigurationChannelProvider>();

            // Registering the AlexaHttpAdapter
            services.AddSingleton<IAlexaHttpAdapter>((sp) =>
            {
                var alexaHttpAdapter = new AlexaHttpAdapter(validateRequests: true)
                {
                    OnTurnError = async (context, exception) =>
                    {
                        await context.SendActivityAsync("Sorry, something went wrong");
                    },
                    ShouldEndSessionByDefault = true,
                    ConvertBotBuilderCardsToAlexaCards = false,
                };
                alexaHttpAdapter.Use(new AlexaIntentRequestToMessageActivityMiddleware());
                return alexaHttpAdapter;
            });

            services.AddSingleton<AlexaIntentRequestToMessageActivityMiddleware>();

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

Cheers, Maciej

1reaction
garyprettycommented, Apr 30, 2019

Hi.

Before this line…

ShouldEndSessionByDefault = true

You can insert

Use(new AlexaIntentRequestToMessageActivity())

That adds the middleware to the pipeline.

Cheers

Gary

Get Outlook for Androidhttps://aka.ms/ghei36

From: mwnowicki Sent: Tuesday 30 April, 18:59 Subject: Re: [BotBuilderCommunity/botbuilder-community-dotnet] Alexa Adapter - MVC and middleware (#95) To: BotBuilderCommunity/botbuilder-community-dotnet Cc: Subscribed

Hi Arafat, Thank you for your response. I have checked Cortana Assistant Alexa Samplehttps://github.com/BotBuilderCommunity/botbuilder-community-dotnet/tree/develop/samples/Cortana Assistant Alexa Sample but it also doesn’t use MVC. I also checked Microsoft Sample Transcript Logger Middlewarehttps://github.com/Microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/17.multilingual-bot, it uses MVC and middleware. But I not able to find any clue why my code doesn’t work. Maciej — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/BotBuilderCommunity/botbuilder-community-dotnet/issues/95#issuecomment-488052496, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AA5YJ2PATJ5PHLKAWHYQYATPTCCG3ANCNFSM4HJNHK2Q. {“api_version”:“1.0”,“publisher”:{“api_key”:“05dde50f1d1a384dd78767c55493e4bb”,“name”:“GitHub”},“entity”:{“external_key”:“github/BotBuilderCommunity/botbuilder-community-dotnet”,“title”:“BotBuilderCommunity/botbuilder-community-dotnet”,“subtitle”:“GitHub repository”,“main_image_url”:“https://github.githubassets.com/images/email/message_cards/header.png",“avatar_image_url”:“https://github.githubassets.com/images/email/message_cards/avatar.png”,“action”:{“name”:"Open in GitHub”,“url”:“https://github.com/BotBuilderCommunity/botbuilder-community-dotnet"}},“updates”:{“snippets”:[{“icon”:“PERSON”,“message”:"@mwnowicki in #95: Hi Arafat,\r\n\r\nThank you for your response.\r\nI have checked Cortana Assistant Alexa Sample but it also doesn’t use MVC.\r\nI also checked Microsoft Sample Transcript Logger Middleware, it uses MVC and middleware. But I not able to find any clue why my code doesn’t work.\r\n\r\nMaciej”}],“action”:{“name”:“View Issue”,“url”:“https://github.com/BotBuilderCommunity/botbuilder-community-dotnet/issues/95#issuecomment-488052496”}}}[ { “@context”: “http://schema.org”, “@type”: “EmailMessage”, “potentialAction”: { “@type”: “ViewAction”, “target”: “https://github.com/BotBuilderCommunity/botbuilder-community-dotnet/issues/95#issuecomment-488052496”, “url”: “https://github.com/BotBuilderCommunity/botbuilder-community-dotnet/issues/95#issuecomment-488052496”, “name”: “View Issue” }, “description”: “View this Issue on GitHub”, “publisher”: { “@type”: “Organization”, “name”: “GitHub”, “url”: “https://github.com” } } ]

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bot.Builder.Community.Adapters.Alexa not working with ...
Adapters.Alexa.Integration.AspNet.Core; using Microsoft.AspNetCore.Mvc; using Microsoft.Bot.Builder; using System; using System.Collections.
Read more >
Bot Builder Community – Alexa Adapter Update Preview
The current implementation of the Alexa adapter provides middleware to perform this transformation for incoming intent requests (providing you ...
Read more >
Voxa Documentation
Voxa is an Alexa skill framework that provides a way to organize a skill into a state machine. Even the most complex voice...
Read more >
ASP.NET Core Middleware
By Rick Anderson and Steve Smith. Middleware is software that's assembled into an app pipeline to handle requests and responses.
Read more >
Bot.Builder.Community.Middleware.Typing 1.0.82 on NuGet
An adapter to allow for Alexa Skills to be built using the Bot Builder SDK. Includes broad support for Alexa Skills capabilities, including ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found