botframework-components
botframework-components copied to clipboard
Auto-compute the SkillHostEndpoint setting
Per Tom:
Setting the SkillHostEndpoint is an obscure thing you need to do for your bot to function correctly as a skillhost. With Azure Functions I was able to auto-compute the setting using environment vars for Azure Functions like this:
public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
{
// auto-detect SkillHostEndpoint
FunctionsHostBuilderContext context = builder.GetContext();
var hostname = builder.ConfigurationBuilder.Build().GetValue<string>("WEBSITE_HOSTNAME");
var protocol = hostname.StartsWith("localhost") ? "http" : "https";
builder.ConfigurationBuilder.AddInMemoryCollection(new[] { new KeyValuePair<string, string>("SkillHostEndpoint", $"{protocol}://{hostname}/api") });
}
Will need to only do this as a default if appsettings does NOT have something specified. Reason is, the bot could be behind a load balancer, or some other advanced config, and the above code will not work.
This is best solved IMHO by making a template change to the startup.cs for a function hosted bot, and not as part of an SDK modification. This is because since it is only possible for functions, and the SDK code is common for both web and function hosted code, there isn't a good way to do this as part of the SDK without it failing when the SDK code is running as a web app.