Microsoft Botframework:与Bot频道进行直接对话 [英] Microsoft Botframework: Direct Conversation with Bot Channel
问题描述
我一直在努力将来自ac#控制台applicaton的直接消息发送到托管在Azure中的我的Skype机器人,但我不断收到错误消息:操作返回了无效的状态码未经授权",但是我提供了以下内容凭据:
I have been batteling to send a direct message from a c# console applicaton to my skype bot that is hosted in Azure, I keep on getting the error: Operation returned an invalid status code 'Unauthorized', but I have provided the following credentials:
Web.Config文件
Web.Config File
<appSettings>
<add key="BotId" value="myBotId" />
<add key="MicrosoftAppId" value="AppId" />
<add key="MicrosoftAppPassword" value="Password" />
</appSettings>
我确定以上几点!不可能是这样.
I made sure of the above! So can't be that.
我的控制台应用程序代码:
My console application code:
var userAccount = new ChannelAccount(name: "User", id: "default-user");
var botAccount = new ChannelAccount(name: "Bot", id: "id");
var connector = new ConnectorClient(new Uri("https://f2d92691.ngrok.io"));
IMessageActivity message = Activity.CreateMessageActivity();
if (!string.IsNullOrEmpty(conversationId) && !string.IsNullOrEmpty(channelId))
{
message.ChannelId = channelId;
}
else
{
conversationId = (await connector.Conversations.CreateDirectConversationAsync(botAccount, userAccount)).Id;
}
message.From = botAccount;
message.Recipient = userAccount;
message.Conversation = new ConversationAccount(id: conversationId);
message.Text = messageText;
message.Locale = "en-Us";
await connector.Conversations.SendToConversationAsync((Activity)message);
这是我用于机器人模拟器的代码.
This is the code that I used to work with the bot emulator.
Has anyone done this before and please note that I can send message using this example: https://docs.microsoft.com/en-us/azure/bot-service/dotnet/bot-builder-dotnet-proactive-messages
但这是机器人本身正在使用的代码,我不想在机器人外部使用它.
But this is code that is being used in the bot itself, I wan't to use it outside of the bot.
谢谢
推荐答案
找到了解决方案,如果您使用代码在bot外部发送消息,则只需添加此行.
MicrosoftAppCredentials.TrustServiceUrl(URL);
Found the solution, just add this line if you are using code to send message outside the bot.
MicrosoftAppCredentials.TrustServiceUrl(URL);
这篇关于Microsoft Botframework:与Bot频道进行直接对话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!