簡體   English   中英

Azure Teams Bot 在幾分鍾后沒有響應

[英]Azure Teams Bot not responding after a few minuets

我們使用 Azure Bot Service 和 C# 為團隊開發了一個機器人。它在我的本地使用 Bot Framework Emulator 運行良好,但在 Teams 中,它已經工作了一段時間並停止響應。 假設我卸載並安裝它,它運行良好並重復同樣的問題。 我錯過了什么嗎?

我在 MainDialog.cs 一個對話框中編寫了所有代碼。

需要進行以下修改才能解決該問題。 由於未共享代碼,因此該解決方案包含可在測試中使用的示例代碼。

要執行的步驟:

  • 降級.Net版
  • 將 SDK 版本降級到 3.14,因為它在該版本之后出現問題

sealed class BotJwtRefreshWorker: IDisposable {

CancellationTokenSource _Cts = new CancellationTokenSource();

    public BotJwtRefreshWorker()
    {
        var appID = ConfigurationManager.AppSettings["MicrosoftAppId"];
        var appPassword = ConfigurationManager.AppSettings["MicrosoftAppPassword"];
        if (!string.IsNullOrEmpty(appID) && !string.IsNullOrEmpty(appPassword))
        {
            var credentials = new MicrosoftAppCredentials(appID, appPassword);
            Task.Factory.StartNew(
                async () =>
                {
                    var ct = _Cts.Token;
                    while (!ct.IsCancellationRequested)
                    {
                        try
                        {
                            // GetTokenAsync method internally calls RefreshAndStoreToken, meaning that the token will automatically be cached at this point and you don’t need to do anything else – the bot will always have a valid token.
                            await credentials.GetTokenAsync().ConfigureAwait(false);
                         }
                         catch (Exception ex)
                         {
                             Trace.TraceError(ex.ToString());
                         }
                         await Task.Delay(TimeSpan.FromMinutes(30), ct).ConfigureAwait(false);
                     }
                 },
                 TaskCreationOptions.LongRunning);
        }
    }

    public void Dispose()
    {
        _Cts.Cancel();
    }
}

根據提到的值,這使得等待時間更少或 null。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM