Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using botbuilder in combination with a .NET Core Azure Function #467

Closed
devedse opened this issue Apr 19, 2018 · 15 comments
Closed

Using botbuilder in combination with a .NET Core Azure Function #467

devedse opened this issue Apr 19, 2018 · 15 comments
Labels
backlog The issue is out of scope for the current iteration but it will be evaluated in a future release. blocked Current progress is blocked on something else. on hold Progress is halted at the moment.
Milestone

Comments

@devedse
Copy link

devedse commented Apr 19, 2018

Introduction

I'm currently working on building a bot service using the latest .NET Core technology. I would like to set this up using Azure Functions as they are pay per use instead of having to pay for the complete month.

They way this worked within the bot builder framework is that I would create a .NET Standard project which contained all the bot logic. The .NET Framework Azure Function would then call into this code and it would work fine 😄. However when I created a .NET Function to talk against the .NET Standard project I ran into DLL issues and ultimately found out that the issue was that the bot framework does not support .NET Core.

Issue

I then started migrating the code to the .NET Core version (this github) of the bot framework but I quickly ran into the issue that the new version of the bot framework requires a Startup.cs class, services, etc. which is all not available in .NET Core Azure Funcions.

Could someone provide a sample on how to do this? Or at least some guidance to help me find out where to start 😄?

@drub0y
Copy link
Contributor

drub0y commented Apr 19, 2018

Good news: this is totally possible today!

We're aware that we need to whip together some official docs/samples on Azure Function hosting (and maybe even a first class experience), but, for now, let me point you to this sample from @brandonh-msft where he has replicated the EchoBot sample in Azure Functions. Please note that, at the time of this writing, the master branch is still using an (much) older version of the Bot Framework SDK, but I just so happen to have PR'd an upgrade to the latest M3.1 bits yesterday which is available here.

@brandonh-msft
Copy link
Contributor

brandonh-msft commented Apr 19, 2018

Also worth noting, the bot doesn't work live (at least on Skype) due to issues w/ the SDK. Or did you not observe the same problem, @drub0y?

@drub0y
Copy link
Contributor

drub0y commented Apr 19, 2018

@brandonh-msft That's a fair point, that needs looking into still. I think the main point here is your sample clearly demonstrates a working integration of the v4 Bot Framework within an Azure Function.

Right now the sample works great with the emulator for sure, so at least people can use the sample to start writing some code and we'll of course sort out whatever the internal issue is with integration with the actual Bot Service.

@devedse
Copy link
Author

devedse commented Apr 19, 2018

I just tried running the code with the bot emulator but ran into the following exception:
image

Also verified it on a colleagues computer and he ran into the same trouble. (We both use the latest pre-release version of Azure Functions CLI)

@drub0y
Copy link
Contributor

drub0y commented Apr 19, 2018

TL;DR - Bottom line for now: non-authenticated emulator requests SHOULD work, anything authenticated WILL NOT work.

Ok, just wanted to give you an update here....

First, I want you to see that it does work in an unauthenticated scenario. Point your bot emulator here at my deployed instance with no credentials and see it work for yourself: http://drmarsh-echobot-function.azurewebsites.net/api/messages

Second, there is an actual bug with the code that I didn't notice because when you hit it directly as a "plain old" Azure Function with the emulator it's not an issue. Specifically the problem is that the header name it's using is wrong. It should not be "Authentication" it should be "Authorization". This is a required fix and I'll PR to @brandonh-msft ASAP, but the fact is it's just going to move us forward to the next breaking problem.

So the real problem is, as soon as you start using real credentials against this thing you're going to run into an issue. The issue that I'm seeing when I debug is that the Azure Functions 2.0 runtime (which we know is beta... right?) is throwing a FileNotFoundException when looking for the System.IdentitityModel.Tokens.Jwt assembly which then results in an AssemblyLoadException. Now, the file is totally there and I believe this to be a 2.0 functions runtime error. The short of it is I think this is the assembly binding issue biting us because there's actually a version of System.IdentityModel.Tokens.Jwt (5.1.<something>) already loaded into the process, it's just not the 5.2.0.0 bot framework is looking for. I'm going to go talk to @brandonh-msft about it shortly because he might have some thoughts on this and will follow up here in a little bit.

@brandonh-msft
Copy link
Contributor

brandonh-msft commented Apr 19, 2018

Yes the header name wasn't right; that had been resolved in all my deployments to Azure and still wasn't able to chat w/ the bot.

The assembly resolution problems are well known by the fxns team and, due in part to these issues, a v1-based func isn't possible because they have a hard ref (==) to Newtonsoft.Json 9.0.1 whereas botbuilder wants 10.0.3+

I have an idea on something that might solve this which I'm giving a shot now.

@brandonh-msft
Copy link
Contributor

brandonh-msft commented Apr 19, 2018

No dice. Appears putting Bots on Azure Functions is blocked by Azure/azure-functions-host#992 as well.

IMO fine to close this issue but up to the team.

@jorupp
Copy link

jorupp commented Apr 19, 2018

re: doing something like assembly bindings on Azure functions, you can try hooking the AssemblyResolve event as described in Azure/azure-functions-host#992 (comment).

That approach has worked for the bot I have deployed as a v1 Azure Function.

@devedse
Copy link
Author

devedse commented Apr 20, 2018

So I just ran the bot local again without any AppId / password filled in (is this what you mean with no credentials?):
image

But I keep getting this error:
image

However when I deploy the application to Azure it does in fact work (using ngrok). Your bot also works fine when connecting to it (also using ngrok).

Also when I try to connect to the bot using a Bot project in Azure and test it using the Web Chat it keeps saying that it can't send the messages. Is this because of authentication that is enabled? And if so, can you disable it for the test web chat in azure?

image

@devedse
Copy link
Author

devedse commented May 17, 2018

@brandonh-msft is it still the case that the framework v4 does not support authentication? I saw that that the Microsoft/botbuilder pages were all updated with information about the botbuilder v4 preview?

@yochay yochay added blocked Current progress is blocked on something else. backlog The issue is out of scope for the current iteration but it will be evaluated in a future release. and removed question labels Jun 18, 2018
@vishwacsena vishwacsena added the on hold Progress is halted at the moment. label Jun 18, 2018
@brandonh-msft
Copy link
Contributor

@drub0y is closer to the work that would be necessary to fix this problem than I am. Any update we know of, Drew?

cc @cleemullins, @tomlm

@drub0y
Copy link
Contributor

drub0y commented Jun 25, 2018

All auth scenarios should work at this point using the latest framework bits from the repo. We just did some direct work on the security token validation path a week or so again in fact and validated several of these scenarios.

@devedse, I just want to make sure I'm on the same page here: this thread was originally about hosting in Azure Functions... is that still the scenario you're working with? If so, I believe that this is still going to be an issue due to Azure/azure-functions-host#992.

@devedse
Copy link
Author

devedse commented Jun 26, 2018

@drub0y ,

Good to hear that all Auth Scenario's should now work. Initially we were working on implementing the bot with Azure Functions, but have found on multiple places that Azure Functions are giving more issues then solutions when working with Bots. E.g. Skype Voice calling doesn't work, the binding redirects you're refering to, long startup times etc.

@brandonh-msft
Copy link
Contributor

brandonh-msft commented Jun 26, 2018

@devedse
it'd be great if you could post on the binding redirects issue in the Functions repo so we get another signal.

on the topic of long startup times, a couple of things:

  1. You can always deploy a Function to a proper App Service and set it to 'Always On'
  2. If going Functions to stay on Consumption billing, keep in mind if you run a Function 24/7 constantly, you may in fact be better off as an App Service from a cost perspective.
  3. More details on what you're seeing would be great for me to take to the product team and keep an eye on internally

@vishwacsena vishwacsena added this to the Future milestone Aug 8, 2018
@Kaiqb Kaiqb added the customer-reported Issue is created by anyone that is not a collaborator in the repository. label Jul 23, 2019
@sgellock sgellock removed the samples label Jul 24, 2019
@Kaiqb Kaiqb added the Bot Services Required for internal Azure reporting. Do not delete. Do not change color. label Jul 31, 2019
@sgellock sgellock removed Bot Services Required for internal Azure reporting. Do not delete. Do not change color. customer-reported Issue is created by anyone that is not a collaborator in the repository. labels Aug 8, 2019
@gabog
Copy link
Contributor

gabog commented May 18, 2020

Closing as part of R10 triage. This now works with composer

@gabog gabog closed this as completed May 18, 2020
ShYuPe pushed a commit to ShYuPe/botbuilder-dotnet that referenced this issue Aug 25, 2020
Unit tests & tightening up teams activity handler object types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog The issue is out of scope for the current iteration but it will be evaluated in a future release. blocked Current progress is blocked on something else. on hold Progress is halted at the moment.
Projects
None yet
Development

No branches or pull requests

9 participants