.bot
files
! 您(正确地)向我们显示了通过应用程序设置正确配置您的机密的屏幕截图,但您的启动代码不依赖于应用程序设置。。。相反,它是在利用新技术
文件以加载终结点的凭据。
首先让我说这是一项全新的可选技术。我知道这些示例往往会把它推到你面前,但如果你已经有了DevOps实践,可以通过环境变量/应用程序设置等现有机制很好地维护和部署你的密钥/机密,那么你就不必采用它。
例如,您可以将
只需将您的机器人注册更改为以下内容,即可归档并更改启动以使用应用程序设置:
public class Startup
{
private readonly IConfiguration _configuration;
public Startup(IConfiguration configuration)
{
// Ask for the configuration service to be injected so you can access config values (standard .NET Core 101 stuff)
_configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
}
public void ConfigureServices(IServiceCollection services)
{
services.AddBot<IAssistantBot>(options =>
{
// Load the values right out of configuration
options.CredentialProvider = new SimpleCredentialProvider(
_configuration.GetSection("MicrosoftAppId").Value,
_configuration.GetSection("MicrosoftAppPassword").Value);
// Catches any errors that occur during a conversation turn and logs them.
options.OnTurnError = async (context, exception) =>
{
await context.SendActivityAsync("Sorry, it looks like something went wrong.");
};
});
}
}