尝试将我的机器人部署到Azure时遇到问题。当我尝试创建Azure资源时,出现以下错误:error: InvalidBotData, message: Version: Bot Version has an invalid value.
我稍微摸了一下,发现我的机器人是4.3版,而现在您需要4.4版来部署…
我发现Mircosoft已经有解决此问题的方法:https://docs.microsoft.com/bs-latn-ba/azure/bot-service/bot-file-basics?view=azure-bot-service-4.0&tabs=csharp我遵循了步骤,还更改了QnAmaker和Luis的调用方式。但是,当我运行该应用程序时,出现以下错误:System.InvalidOperationException: Unable to resolve service for type 'VacancyBot.VacancyBot.Services.BotServices' while attempting to activate 'VacancyBot.VacancyBotBot'.
我意识到该机器人不再被添加到任何地方,因此我尝试使用services.AddSingleton<VacancyBotBot>()
添加该机器人,但这没有用。将其添加为瞬态也不起作用。
通常添加机器人的部分是这样的:
var secretKey = Configuration.GetSection("botFileSecret")?.Value;
var botFilePath = Configuration.GetSection("botFilePath")?.Value;
var botConfig = BotConfiguration.Load(botFilePath ?? @".\nlp-with-luis.bot", secretKey);
services.AddSingleton(sp => botConfig ?? throw new InvalidOperationException($"The .bot config file could not be loaded. ({botConfig})"));
var connectedServices = new BotServices(botConfig);
services.AddSingleton(sp => connectedServices);
但是,这不再起作用了,因为从某些方面来说,找不到。\ nlp-with-luis.bot。 (我还没有真正删除.bot文件,但是我猜现在不再使用它了。)。
我想知道是否有人碰巧知道如何添加bot或以再次起作用的方式更改
BotConfiguration
。我真的希望这是可能的!如果有人需要查看更多代码,请这样说,我将尝试提供它(:我忘了补充说,我曾尝试将
"botFilePath": "VacancyBot.bot", "botFileSecret": "",
放回appsettings文件中,但是却导致再次在Azure中收到相同的错误... 最佳答案
.bot文件仍然可以使用,但是您似乎正在尝试结合使用.bot文件和appsettings.json。让我们理直气壮。
从appsettings.json开始:您不再需要botFilePath
或botFileSecret
。而是按如下所示构造您的appsettings.json:
{
"MicrosoftAppId": "",
"MicrosoftAppPassword": "",
"LuisAppId": "",
"LuisAPIKey": "",
"LuisAPIHostName": ""
}
MicrosoftAppId
和MicrosoftAppPassword
现在通过ConfigurationCredentialProvider.cs文件插入,以后将作为单例添加到Startup.cs中。 ConfigurationCredentialProvider应该如下所示:using Microsoft.Bot.Connector.Authentication;
using Microsoft.Extensions.Configuration;
namespace CoreBot1
{
public class ConfigurationCredentialProvider : SimpleCredentialProvider
{
public ConfigurationCredentialProvider(IConfiguration configuration)
: base(configuration["MicrosoftAppId"], configuration["MicrosoftAppPassword"])
{
}
}
}
简短,甜美而切入点。最后,如下构建您的startup.cs,以添加bot和ICredentialProvider:
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Extensions.DependencyInjection;
using CoreBot1.Bots;
using CoreBot1.Dialogs;
namespace CoreBot1
{
public class Startup
{
public Startup()
{
}
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
// 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>();
// The Dialog that will be run by the bot.
services.AddSingleton<MainDialog>();
// Create the bot as a transient. In this case the ASP Controller is expecting an IBot.
services.AddTransient<IBot, DialogAndWelcomeBot<MainDialog>>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}
app.UseDefaultFiles();
app.UseStaticFiles();
//app.UseHttpsRedirection();
app.UseMvc();
}
}
}