我正在尝试使用Microsoft.Azure.Management.BotServiceSDK在Facebook频道中使用Bot框架自动注册Bot。
所以,我发现这样的东西:
Microsoft.Azure.Management.BotService.ChannelsOperationsExtensions.Create()
但是第一个参数是:(IChannelOperations),带有说明(此扩展方法的操作组)。
我不确定如何使用该方法。 有人有什么想法吗?
答案 0 :(得分:1)
类似的事情应该起作用:
var cred = SdkContext.AzureCredentialsFactory.FromServicePrincipal(client, key, tenant, AzureEnvironment.AzureGlobalCloud);
var botClient = new AzureBotServiceClient(cred);
botClient.SubscriptionId = subscription;
var config = new BotChannel()
{
Location = "global",
Properties = new FacebookChannel(new FacebookChannelProperties(facebookAppId, facebookAppSecret, true))
};
await botClient.Channels.CreateAsync(resourceGroupName, connectorName, ChannelName.FacebookChannel, config);
编辑:
已经对此进行了测试,但我不相信该库是否具有完整的功能-读取似乎有效,但是创建资源似乎无效。我发现直接使用rest api会更好。像这样(使用RestSharp):
var request = new RestRequest($"resourceGroups/{resourceGroupName}/providers/Microsoft.BotService/botServices/{botServiceName}/channels/FacebookChannel?api-version=2018-07-12", Method.PUT);
request.AddJsonBody(new
{
location = "global",
properties = new
{
channelName = "FacebookChannel",
properties = new
{
isEnabled = true,
appId = facebookAppId,
appSecret = facebookAppSecret
}
}
});
await _azureClient.ExecuteTaskAsync(request);
其中_azureClient
注入到我的控制器中,如下所示:
azureRestClient.Authenticator = new MicrosoftAuthenticator(client, key, tenant, "https://management.azure.com");
services.AddSingleton<IRestClient>(azureRestClient);