Search code examples
c#botframeworkskypeslack

Microsoft Bot Framework IDialogContext.Call() not working when using Slack


I have a simple child dialog call in my bot using IDialogContext.Call(). When user types "new project" the following code is called:

...
context.Call(new NewProjectDialog(), NewProjectConfirmed);
...

NewProjectDialog() just asks for a project name and then saves it before returning to NewProjectConfirmed()

[Serializable]
public class NewProjectDialog : IDialog<Project>
{
    public async Task StartAsync(IDialogContext context)
    {
        await context.PostAsync("What is the name of the project?");
        context.Wait(this.MessageReceivedAsync);
    }

    public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
    {
        var message = await result;
        Project p = new Project();        
        //Saving project here...

        await context.PostAsync($"OK. Your project '{message.Text}' was created.");
        context.Done(p);
    }
}

When the bot is called from emulator, Skype or Webchat everything works as expected. User asks for new project by typing "new project", bot asks for name, it WAITS and once project name entered by the user the bot confirms the new project creation.

enter image description here

But when I call the same from Slack, When the user ask for new project by typing "new project" the text "new project" is passed to the NewProjectDialog. it asks for the project name, but without waiting it passes "new project" further and saves it as the name for the project.

enter image description here

Not really sure what I am missing. Either iDialogContext.Wait() works differently with Slack or the Call() function seem to post the message to the child dialog like Forward() should.


Solution

  • Thanks to some Howdy developers I found the issue.

    It happens when the bot has already been authorized to the team, and then someone else comes in and authorizes the bot again. When that happens, it seems there are two bots running that then use the same RTM connection to post to the channel twice.

    I don't know how I got 2 bots in same Slack client. but once I removed and reinstalled my bot it started working as expected.

    Same issue is causing this other symptom: Microsoft Bot Framework Bot duplicate responses in Slack