繁体   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