2

I've already deployed the bot to azure, when connecting to the ms team channel in azure, i'm able to ping the bot and receive messages which is good. I've also added a proactive messaging in the bot where a message will be triggered every one minute in the channel.

Connecting to MS Teams

Its working in the emulator, however its not working in webchat and MS teams: The notifier controller is not being triggered.

Could you please help me on that? I've uploaded the code in 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;
            }
        }
    }
}

After one minute, it should trigger below message in the channel:

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);
Kyle Delaney
  • 11,616
  • 6
  • 39
  • 66

1 Answers1

2

I mentioned this via email, but I'll repost it here for others:

Your proactive messaging works in Emulator but not in Teams because you only add a ConversationReference in EchoBot.OnConversationUpdateActivityAsync.

As explained here, Teams only sends a ConversationUpdate when the bot is installed or a user speaks with the bot the FIRST time EVER. Here is a way you can test it.

mdrichardson
  • 7,141
  • 1
  • 7
  • 21
  • i've added the conversation reference to the onmessageasync. protected override async Task OnMessageActivityAsync(ITurnContext turnContext, CancellationToken cancellationToken) { AddConversationReference(turnContext.Activity as Activity); System.Timers.Timer checkForTime = new System.Timers.Timer(interval60Minutes); checkForTime.Elapsed += new ElapsedEventHandler(checkForTime_Elapsed); checkForTime.Enabled = true; Is it because my bot is not being used for the first time on teams? – Nivin Sunathree Sep 18 '19 at 07:02
  • Is it possible to get someone for a screensharing for these issues. I'm stuck with it since the last one week as you know? Thank you – Nivin Sunathree Sep 18 '19 at 08:39