【问题标题】:Sending proactive messages to ms teams from azure deployed bot从 azure 部署的机器人向 ms 团队发送主动消息
【发布时间】:2019-09-18 03:02:02
【问题描述】:

我已经将机器人部署到 azure,当连接到 azure 中的 ms 团队频道时,我能够 ping 机器人并接收消息,这很好。 我还在 bot 中添加了主动消息传递,其中将在频道中每分钟触发一条消息。

它在模拟器中工作,但在网络聊天和 MS 团队中不工作: 未触发通知控制器。

你能帮我解决这个问题吗? 我已经在 GITHUB 中上传了代码: https://github.com/nivinsunathree/Botv4.git

public override async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
{
    await base.OnTurnAsync(turnContext, cancellationToken);


    System.Timers.Timer checkForTime = new System.Timers.Timer(interval60Minutes);
    checkForTime.Elapsed += new ElapsedEventHandler(checkForTime_Elapsed);
    checkForTime.Enabled = true;


    // Save any state changes that might have occured during the turn.
    await _conversationState.SaveChangesAsync(turnContext, false, cancellationToken);
    await _userState.SaveChangesAsync(turnContext, false, cancellationToken);
}

void checkForTime_Elapsed(object sender, ElapsedEventArgs e)
{
    bool timeIsReady = true;
    if (timeIsReady == true)
    {
        var url = "http://localhost:3978/api/notify";

        try
        {
            Process.Start(url);
        }
        catch
        {
            // hack because of this: https://github.com/dotnet/corefx/issues/10361
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                url = url.Replace("&", "^&");
                Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = false });
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                Process.Start("xdg-open", url);
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                Process.Start("open", url);
            }
            else
            {
                throw;
            }
        }
    }
}

一分钟后,应该会在频道中触发以下消息:

await turnContext.SendActivityAsync(MessageFactory.Text($"Hello!" + Environment.NewLine + $"Trust you are well" + Environment.NewLine + $"Hope that you are having a good day" + Environment.NewLine + $"We are contacting you concerning lea access requests" + Environment.NewLine + $"Could you please review the following tasks if any and add the required information!"), cancellationToken);
//await turnContext.SendActivityAsync(MessageFactory.Text($"Please type ok to continue!"), cancellationToken);
await turnContext.SendActivityAsync(MessageFactory.Text("Could you please click on the below button to continue?"));

var card = new HeroCard
{
    //Text = "Could you please click on the below button to continue?",
    Buttons = new List<CardAction>
        {
            new CardAction(ActionTypes.ImBack, title: "lea access request", value: "lea access request"),
        },
};
var reply = MessageFactory.Attachment(card.ToAttachment());
await turnContext.SendActivityAsync(reply, cancellationToken);

【问题讨论】:

    标签: c# botframework microsoft-teams


    【解决方案1】:

    我通过电子邮件提到了这一点,但我会在这里转发给其他人:

    您的主动消息传递在 Emulator 中有效,但在 Teams 中无效,因为您只在 EchoBot.OnConversationUpdateActivityAsync 中添加了 ConversationReference

    正如here 解释的那样,Teams 仅在安装机器人或用户第一次与机器人交谈时发送 ConversationUpdate。 Here 是您可以测试它的一种方式。

    【讨论】:

    • 我已将对话引用添加到 onmessageasync。受保护的覆盖异步任务 OnMessageActivityAsync(ITurnContext turnContext, CancellationToken cancelToken) { AddConversationReference(turnContext.Activity as Activity); System.Timers.Timer checkForTime = new System.Timers.Timer(interval60Minutes); checkForTime.Elapsed += new ElapsedEventHandler(checkForTime_Elapsed); checkForTime.Enabled = true;是不是因为我的机器人不是第一次在团队中使用?
    • 是否可以为这些问题找人进行屏幕共享。你知道吗,我从上周开始就一直坚持下去?谢谢
    猜你喜欢
    • 1970-01-01
    • 2021-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-14
    相关资源
    最近更新 更多