我有一個自定義的WebApi控制器託管在我的正常的bot MessagesController旁邊。此自定義控制器經常接到呼叫,以便向用戶發送主動消息以發送通知。Botframework - 主動 - 冷撥打電話UnauthorizedAccessException
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功能做一些運算,但最終它調用一個對話框:當Web服務啓動並運行,並至少執行一次與https://login.microsoftonline.com/common/oauth2/v2.0/token登錄任何類型的後
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服務之間的閒聊。
但是,如果我重新啓動我的web服務並啓動前瞻性討論,我會得到UnauthorizedAccessException。
我試圖用BotAuthenticator執行手動驗證,或者添加了[BotAuthentication]和一個傳遞的令牌,但我總是以UnauthorizedAccessException結束。
所以我注意到,Beerer只存在於無冷啓動。我發現沒有辦法強制認證冷啓動... Image of Fiddler Web Service --> To Bot
任何類型的幫助將不勝感激。