AlexaSkillsKit.NET icon indicating copy to clipboard operation
AlexaSkillsKit.NET copied to clipboard

.Net Core implementation that works with Lambda Serverless?

Open BenTMatthews opened this issue 8 years ago • 40 comments

One of the big selling points for the ease of Alexa dev is how easy (and cheap) it integrates with lambda. Also some orgs are moving to Core as it becomes more stable. Any future plans to have this work with .Net Core for those easy Lambda projects?

BenTMatthews avatar Jan 22 '17 06:01 BenTMatthews

+1 would be great to get this to work with the recently added C# support in Lambda

MaxHorstmann avatar Feb 11 '17 01:02 MaxHorstmann

Another +1. I've been using the Slight.Alexa version thats been ported to Core... but it's incomplete at the moment.

goldfishrock avatar Feb 15 '17 14:02 goldfishrock

I have a .Net core (netstandard) port of this in a fork that initially is working for me but I will test further before declaring success beyond It works on my machine ™️ - I will also verify it works in core on Azure and AWS Lambda

tonysurma avatar Mar 21 '17 02:03 tonysurma

verified it is working on azure just now, up next AWS Lambda verification (but if it works on .net core it should on another)

tonysurma avatar Mar 23 '17 16:03 tonysurma

@tonysurma I couldn't find any nuget feed with your version of this lib (for .net core) so I allowed myself to create one: https://www.myget.org/feed/ami/package/nuget/AlexaSkillsKit.Net (if any of you need it, you can reference it). Quite useful, because local dll can't be referenced in easy way in VSCode.

szymczakk avatar Apr 17 '17 21:04 szymczakk

@szymczakk Happy to amend the "official" NUGet package definition so it can be used from .NET Core if you can educate me a bit about what I need to do. (My head is still on .NET Framework 4.6 and I haven't had time to learn about porting stuff to .NET Core.) Is the package definition you published on MyGet available somewhere for me to look at?

stefann42 avatar Apr 18 '17 00:04 stefann42

@stefann42 yes it is! I moved the version to 1.6 (no reason other than it needed to be a different version. in .NET Core it comes from the csproj now so you can see the details here (I literally copied over what you had done from the nuspec to the csproj).

I also chose the right netstandard so it will work with .NET Core and the version of .NET Framework you had previously targeted so it is compatible and should work without change in existing .NET 4.6 deployments.

The changes are all in the fork I made and I strove to make each commit 'small' so it documented the porting. Happy to help however I can and if you would like it I can make a PR with these changes and anything else you would need to convert.

tonysurma avatar Apr 18 '17 00:04 tonysurma

thank you @szymczakk for posting that. I hadn't gotten to that step yet. I had been using a custom nuget feed entry that pointed to a local folder where I had the package (simple but it worked for me)

tonysurma avatar Apr 18 '17 00:04 tonysurma

@tonysurma How did you handle the request? When I create API project, and in controller get the Request it's type Microsoft.AspNetCore.Http.HttpRequest and Speechlet in method GetResponse require System.Net.Http.HttpRequestMessage and I don't know how to convert it. I was thinking about rewriting GetRespose method to use request from .net Core, what do you think?

szymczakk avatar Apr 19 '17 18:04 szymczakk

@szymczakk I made a SampleCore project here to demonstrate that and included commit(s) that showed each step to 'upgrade' the Sample to Core. The trick for that I recall is including WebApiCompatShim which allows you to inherit from ApiController and aligns to the types expected by the Speechlet API

I did that as it was the quickest/most direct port and figured most folks aren't putting Alexa into another controller so shouldn't be an issue.

I was also thinking of adding another GetResponse method/overload to adapt to the .net core approach but recall there were some items that the Speechlet wanted that would be a bit messy to get.

tonysurma avatar Apr 19 '17 18:04 tonysurma

@tonysurma sory for bothering you, but have another question, can you look here and see what do I do wrong? By wrong I mean

The remote endpoint could not be called, or the response it returned was invalid.

as an response from service simulator in Skill config console on AWS. I got request, but response that I send to Alexa is invalid 😢

szymczakk avatar Apr 19 '17 21:04 szymczakk

@szymczakk no worries, I will try to look at that a bit later. Can you see the response you are sending from your code and are you sure you got called? I ask only as I have gotten that error when tunneling or some other url issue was the cause.

tonysurma avatar Apr 19 '17 21:04 tonysurma

@tonysurma Yep, Im 100% sure that my server is called, because I'm attached with debugger to it, and see everything is happening. I will try to catch my whole response with Fiddler and show you ;)

szymczakk avatar Apr 20 '17 06:04 szymczakk

got it @szymczakk - just looked through the code and nothing stood out (looked at startup, controller, speechlet) and all looks good with no gotchas. I also reverified my deployment with this version is working as well as made a quick simple one and it worked for me. Curious what the response is that it doesn't like. Sorry I couldn't be more helpful (yet)

tonysurma avatar Apr 20 '17 15:04 tonysurma

@tonysurma Thats weird. I'm unable to capture my trafic with Fiddler, but I can stop execution by debugger (so my local server is called). How did you configure your server? Do you use IIS? How about certificate? Slefsigned or trusted? And do you have static IP address or you use some DynDNS (like no-ip etc) ?

szymczakk avatar Apr 20 '17 19:04 szymczakk

It's been a bit since I did the self hosting (I do updates now to deployed instances in Azure App Service websites) but I recall following this guide. I recall getting tripped up a couple of time and used this guide and another I can't find right now. Eventually I went to just using the site on azure and logging and other mechanisms as it was faster (especially since I tend to dev on combination of desk pc and a couple of laptops). Sorry I don't have any more insights there

tonysurma avatar Apr 20 '17 19:04 tonysurma

@tonysurma Ok, I found the response:

{"endpointRegion":"EU","text":"hello","applicationId":"<appId>","locale":"en_US","session":null}

I wanted to send hello as a response from this intent

PS. Dont know if its important: oryginal data are

%7B%22endpointRegion%22%3A%22EU%22%2C%22text%22%3A%22hello%22%2C%22applicationId%22%3A%22%22locale%22%3A%22en_US%22%2C%22session%22%3Anull%7D

and you have to decode it to make it readable.

szymczakk avatar Apr 20 '17 19:04 szymczakk

hmmm, let me look and compare - hopefully there is something there

tonysurma avatar Apr 20 '17 19:04 tonysurma

@tonysurma I compared it with amazon specification and it's problem with respone :/ Ehhh... have to figure it out somehow 😉

szymczakk avatar Apr 20 '17 19:04 szymczakk

gotcha - yeah.

My response from an app on the same build of the framework looks like this (removing a few specific bits)

{ "version": "1.0", "response": { "outputSpeech": { "type": "PlainText", "text": "My content" }, "shouldEndSession": true }, "sessionAttributes": { "intentSequence": "MyIntentId" } }

Definitely looks like stuff is missing in the response building.

tonysurma avatar Apr 20 '17 20:04 tonysurma

Hey @tonysurma ! Sory for taking it so long, but have some more info, maybe you will know how to handle it. When I debug the request it shows that the response that is generated by code is

{"response":{"card":{"type":"Simple","content":"SessionSpeechlet - Hello","title":"SessionSpeechlet - Title","subtitle":"SessionSpeechlet - Sub Title"},"outputSpeech":{"type":"PlainText","text":"Hello"},"shouldEndSession":true},"sessionAttributes":{"intentSequence":"HelloWorldIntent"},"version":"1.0"}

but when I finally cought the correct resposne that is sent by server it turns out that the body of response is

{ "version": { "major": 1, "minor": 1, "build": -1, "revision": -1, "majorRevision": -1, "minorRevision": -1 }, "content": { "headers": [ { "key": "Content-Type", "value": [ "application/json; charset=utf-8" ] } ] }, "statusCode": 200, "reasonPhrase": "OK", "headers": [], "requestMessage": null, "isSuccessStatusCode": true }

I run dotnet core in kestrel and then host it on IIS on windows 10. Do you have any idea why do I got such resposne?

szymczakk avatar Apr 23 '17 18:04 szymczakk

Sorry but unfortunately I do not. It looks to be like it's encoding the http response itself in json which is strange and i've never seen before myself.

tonysurma avatar Apr 24 '17 02:04 tonysurma

Hey @tonysurma, look what I found. And this link is explaining why it wasn't working. But funny case is that your code works for you, but you don't have this function in your source. After adding

.AddWebApiConventions();

after UseMvc it starts to work.

szymczakk avatar Apr 25 '17 05:04 szymczakk

Interesting, great find. I will take a look. Might be an omission from the sample project I had in my test and production projects... thanks

tonysurma avatar Apr 25 '17 11:04 tonysurma

Thanks again @szymczakk I had that edit in each of my projects and missed it in the SampleCore project as I never 'directly' ran the sample. I was using the SampleCore project as the basis for my projects to test and run and forgot to 'back port' that line into the sample. I pushed this now.

tonysurma avatar Apr 25 '17 14:04 tonysurma

Hey @tonysurma and @stefann42 any chance we could still get this merged and published to nuget? Now that we've got .net core 2.0, it'd be great to get .net core support.

JustMaier avatar Aug 16 '17 04:08 JustMaier

@JustMaier if @stefann42 is open to it, I can update/test my fork with netstandard 2 to ready it for merge

tonysurma avatar Aug 16 '17 16:08 tonysurma

@tonysurma By all means. I'm happy to accept the PR, just let me know if I need to be aware of any specifics. We don't yet use .NET Core in our production deployment so I don't have an environment to test myself.

stefann42 avatar Aug 16 '17 16:08 stefann42

Now, when interfaces support is merged, I believe .Net Core support is our major priority. @tonysurma changes in your fork looks great to me. Could you, please, create a PR with your changes, so that we can include .Net Core support to the nearest library release? Just tell if you need any help in preparing PR or merging with latest changes.

ElvenMonky avatar Dec 12 '17 14:12 ElvenMonky

One thing to note. Current library is compatible with VS2012 for both Speechlet authors and AlexaSkillsKit.Net contributors. .Net Standard version will require .Net Core1.x SDK and VS 2017 or VS Code for development. @stefann42 are you ready for these kind of changes in our development environment?

For Speechlet authors we can provide multitargeting NuGet package, ofcourse.

ElvenMonky avatar Dec 19 '17 06:12 ElvenMonky