Botframework - 主动 - 冷呼叫时出现 UnauthorizedAccessException

Botframework - Proactive - UnauthorizedAccessException on cold call

我在我的普通机器人 MessagesController 旁边托管了一个自定义 WebApi 控制器。此自定义控制器经常收到调用以向用户执行主动消息传递以发送通知。

public bool Post([FromBody]SchedulerTrigger triggerInfo)
{
    try
    {                                                            
        //Initiate background processing of notifications
        Task.Run(() => NotificationTask.NotificationProcessing(triggerInfo));

    }
    catch (Exception ex)
    {

        throw ex;
    }

    return true;
}

控制器没有 [BotAuthentication] 属性并且不应该,因为它是从其他地方调用的。

NotificationProcessing 函数做了一些处理,但最后它调用了一个对话框:

public static async Task Resume(string resumptionCookie)
{
        //Deserialize reference to conversation
        ConversationReference conversationReference = JsonConvert.DeserializeObject<ConversationReference>(resumptionCookie);

        using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, message))
        {
            var botData = scope.Resolve<IBotData>();

            await botData.LoadAsync(CancellationToken.None);

            //This is our dialog stack
            var task = scope.Resolve<IDialogTask>();

            //interrupt the stack. This means that we're stopping whatever conversation that is currently happening with the user
            //Then adding this stack to run and once it's finished, we will be back to the original conversation
            var dialog = new MyProActiveDialog();

            try
            {
                task.Call(dialog.Void<object, IMessageActivity>(), null);
                await task.PollAsync(CancellationToken.None);
            }
            catch (Exception ex)
            {
                //TODO
            }
            finally
            {
                //flush dialog stack
                await botData.FlushAsync(CancellationToken.None);
            }

        }
}

当 Web 服务启动并且 运行 并且在 Microsoft bot 和我的 web 服务之间进行任何类型的聊天之后至少执行一次登录 https://login.microsoftonline.com/common/oauth2/v2.0/token 时一切正常。

但是,如果我重新启动我的网络服务并开始主动讨论,我会收到 UnauthorizedAccessException。

我尝试使用 BotAuthenticator 执行手动身份验证或使用传递的令牌添加 [BotAuthentication],但我总是以 UnauthorizedAccessException 结束。

所以我注意到 Beerer 仅在 none 冷启动时出现。我发现没有办法在冷启动时强制进行身份验证...... Image of Fiddler Web Service --> To Bot

如有任何帮助,我们将不胜感激。

我以前遇到过这个错误。本质上,消息来自的频道是 "trusted"。解决方法是信任该通道访问。

试试这个(第一个参数应该是服务 url):

MicrosoftAppCredentials.TrustServiceUrl(@"https://skype.botframework.com", DateTime.MaxValue);