Bot Framework Composer 技能主机端点 401 未经授权
Bot Framework Composer Skill Host Endpoint 401 Unauthorized
我有一个用 C# 编写的 Bot Framework Skill,它将消息从后端服务中继到使用 Bot Framework Composer 制作的 Consumer Bot。技能机器人在单独的控制器 api/message/BackendMessage.
上接收来自后端服务的消息
[Route("api/message")]
[ApiController]
public class SkillBotBackendController : ControllerBase
{
...
当 Skill Bot 收到消息时,它会像这样将其发送到与 Consumer Bot 的对话中...
[HttpPost]
[Route("BackendMessage")]
public async Task PostAsync([FromBody] BackendMessage content)
{
...
await _botFrameworkAdapter.ContinueConversationAsync(
msAppId,
conversationRec.ConversationReference,
(ITurnContext turnContext, CancellationToken cancellationToken) =>
turnContext.SendActivityAsync(MessageFactory.Text(backendMessage),
cancellationToken), default(CancellationToken));
消费者机器人可以看到所有直接来自技能机器人的消息,但不能看到技能机器人从后端服务接收的消息。这里有一些 ngrok 条目显示...
POST /api/skills/v3/conversations/ba72ce2d-3a86-4d86-b640-9a4f3c4d5996/activities/e13d97b4-c715-4572-8d 200 OK
POST /api/skills/v3/conversations/ba72ce2d-3a86-4d86-b640-9a4f3c4d5996/activities/e13d97b4-c715-4572-8d 200 OK
POST /api/skills/v3/conversations/ba72ce2d-3a86-4d86-b640-9a4f3c4d5996/activities/52e6e511-8f72-4b55-97 401 Unauthorized
POST /api/skills/v3/conversations/ba72ce2d-3a86-4d86-b640-9a4f3c4d5996/activities/52e6e511-8f72-4b55-97 401 Unauthorized
POST /api/skills/v3/conversations/ba72ce2d-3a86-4d86-b640-9a4f3c4d5996/activities/52e6e511-8f72-4b55-97 401 Unauthorized
POST /api/skills/v3/conversations/ba72ce2d-3a86-4d86-b640-9a4f3c4d5996/activities/52e6e511-8f72-4b55-97 401 Unauthorized
POST /api/skills/v3/conversations/ba72ce2d-3a86-4d86-b640-9a4f3c4d5996/activities/52e6e511-8f72-4b55-97 200 OK
POST /api/skills/v3/conversations/ba72ce2d-3a86-4d86-b640-9a4f3c4d5996/activities/52e6e511-8f72-4b55-97 200 OK
POST /api/skills/v3/conversations/ba72ce2d-3a86-4d86-b640-9a4f3c4d5996/activities/52e6e511-8f72-4b55-97 200 OK
POST /api/skills/v3/conversations/ba72ce2d-3a86-4d86-b640-9a4f3c4d5996/activities/52e6e511-8f72-4b55-97 200 OK
被拒绝的消息具有与其他消息不同的 HttpContext.Request.Headers["Authorization"]
令牌,已接受令牌的受众具有作曲家机器人的应用程序 ID,被拒绝令牌的受众是 https://api.botframework.com.
希望有一个简单的解释和解决方案。
感谢微软的回答:
将此添加到对话框中:
private void AddOrUpdateContinuationParameters(ITurnContext turnContext)
{
var continuationParameters = new ContinuationParameters
{
ClaimsIdentity = turnContext.TurnState.Get<IIdentity>(BotAdapter.BotIdentityKey),
ConversationReference = turnContext.Activity.GetConversationReference(),
OAuthScope = turnContext.TurnState.Get<string>(BotAdapter.OAuthScopeKey)
};
_continuationParametersStore.AddOrUpdate(continuationParameters.ConversationReference.Conversation.Id, continuationParameters, (_, __) => continuationParameters);
}
更改对 ContinueConversationAsync 的调用以包含 continuationParameters:
await _botFrameworkAdapter.ContinueConversationAsync(
(ClaimsIdentity)continuationParameters.ClaimsIdentity,
conversationRec.ConversationReference,
continuationParameters.OAuthScope,
(ITurnContext turnContext, CancellationToken cancellationToken) => turnContext.SendActivityAsync(MessageFactory.Text(backendMessage), cancellationToken),
default);
我有一个用 C# 编写的 Bot Framework Skill,它将消息从后端服务中继到使用 Bot Framework Composer 制作的 Consumer Bot。技能机器人在单独的控制器 api/message/BackendMessage.
上接收来自后端服务的消息[Route("api/message")]
[ApiController]
public class SkillBotBackendController : ControllerBase
{
...
当 Skill Bot 收到消息时,它会像这样将其发送到与 Consumer Bot 的对话中...
[HttpPost]
[Route("BackendMessage")]
public async Task PostAsync([FromBody] BackendMessage content)
{
...
await _botFrameworkAdapter.ContinueConversationAsync(
msAppId,
conversationRec.ConversationReference,
(ITurnContext turnContext, CancellationToken cancellationToken) =>
turnContext.SendActivityAsync(MessageFactory.Text(backendMessage),
cancellationToken), default(CancellationToken));
消费者机器人可以看到所有直接来自技能机器人的消息,但不能看到技能机器人从后端服务接收的消息。这里有一些 ngrok 条目显示...
POST /api/skills/v3/conversations/ba72ce2d-3a86-4d86-b640-9a4f3c4d5996/activities/e13d97b4-c715-4572-8d 200 OK
POST /api/skills/v3/conversations/ba72ce2d-3a86-4d86-b640-9a4f3c4d5996/activities/e13d97b4-c715-4572-8d 200 OK
POST /api/skills/v3/conversations/ba72ce2d-3a86-4d86-b640-9a4f3c4d5996/activities/52e6e511-8f72-4b55-97 401 Unauthorized
POST /api/skills/v3/conversations/ba72ce2d-3a86-4d86-b640-9a4f3c4d5996/activities/52e6e511-8f72-4b55-97 401 Unauthorized
POST /api/skills/v3/conversations/ba72ce2d-3a86-4d86-b640-9a4f3c4d5996/activities/52e6e511-8f72-4b55-97 401 Unauthorized
POST /api/skills/v3/conversations/ba72ce2d-3a86-4d86-b640-9a4f3c4d5996/activities/52e6e511-8f72-4b55-97 401 Unauthorized
POST /api/skills/v3/conversations/ba72ce2d-3a86-4d86-b640-9a4f3c4d5996/activities/52e6e511-8f72-4b55-97 200 OK
POST /api/skills/v3/conversations/ba72ce2d-3a86-4d86-b640-9a4f3c4d5996/activities/52e6e511-8f72-4b55-97 200 OK
POST /api/skills/v3/conversations/ba72ce2d-3a86-4d86-b640-9a4f3c4d5996/activities/52e6e511-8f72-4b55-97 200 OK
POST /api/skills/v3/conversations/ba72ce2d-3a86-4d86-b640-9a4f3c4d5996/activities/52e6e511-8f72-4b55-97 200 OK
被拒绝的消息具有与其他消息不同的 HttpContext.Request.Headers["Authorization"]
令牌,已接受令牌的受众具有作曲家机器人的应用程序 ID,被拒绝令牌的受众是 https://api.botframework.com.
希望有一个简单的解释和解决方案。
感谢微软的回答:
将此添加到对话框中:
private void AddOrUpdateContinuationParameters(ITurnContext turnContext)
{
var continuationParameters = new ContinuationParameters
{
ClaimsIdentity = turnContext.TurnState.Get<IIdentity>(BotAdapter.BotIdentityKey),
ConversationReference = turnContext.Activity.GetConversationReference(),
OAuthScope = turnContext.TurnState.Get<string>(BotAdapter.OAuthScopeKey)
};
_continuationParametersStore.AddOrUpdate(continuationParameters.ConversationReference.Conversation.Id, continuationParameters, (_, __) => continuationParameters);
}
更改对 ContinueConversationAsync 的调用以包含 continuationParameters:
await _botFrameworkAdapter.ContinueConversationAsync(
(ClaimsIdentity)continuationParameters.ClaimsIdentity,
conversationRec.ConversationReference,
continuationParameters.OAuthScope,
(ITurnContext turnContext, CancellationToken cancellationToken) => turnContext.SendActivityAsync(MessageFactory.Text(backendMessage), cancellationToken),
default);