Conversation Flow and Dialogs|Mastering Microsoft Teams Bots 3.3

3.3 Conversation Flow and Dialogs

A bot that responds to one message is useful. A bot that carries on a conversation — remembering, responding, guiding — becomes something more: a digital assistant.

In this section, we explore how to build conversation flow into your Teams bot using dialogs, a key feature of the Microsoft Bot Framework. Dialogs help your bot manage multi-turn conversations — remembering where the user is in the process, what they've already said, and what to do next.

3.3.1 What Is a Dialog?

A dialog is like a mini state machine. It keeps track of what step the user is on in a multi-step flow — like filling out a form, making a request, or confirming a choice.

Instead of handling each message as an isolated input, dialogs give you tools to:

  • Maintain conversation state across turns
  • Ask the user for specific inputs in a structured way
  • Branch logic depending on previous answers

In short: dialogs turn your bot from a command line into a conversational UI.

3.3.2 Using the Dialog System (Bot Framework)

The Microsoft Bot Framework provides a powerful Dialog library that supports prompts, waterfall dialogs, and component dialogs.

Common prompt types include:

  • TextPrompt
  • NumberPrompt
  • ChoicePrompt
  • ConfirmPrompt
  • DateTimePrompt

These are reusable input collectors that guide the user through a conversational form.

3.3.3 Waterfall Dialogs

A Waterfall Dialog is a sequence of steps — each one runs, gets input, and passes data to the next. Think of it as a linear form, where each field is collected through conversation.

C# Waterfall Example:


var steps = new WaterfallStep[]
{
    async (step, ct) => await step.PromptAsync("namePrompt", new PromptOptions { Prompt = MessageFactory.Text("What’s your name?") }, ct),
    async (step, ct) => {
        step.Values["name"] = step.Result;
        return await step.PromptAsync("confirmPrompt", new PromptOptions { Prompt = MessageFactory.Text($"Is '{step.Result}' correct?") }, ct);
    },
    async (step, ct) => {
        if ((bool)step.Result)
        {
            var name = step.Values["name"];
            await step.Context.SendActivityAsync($"Thanks, {name}!");
        }
        return await step.EndDialogAsync();
    }
};
  

3.3.4 State Management

Behind the scenes, dialogs use BotState to remember values between turns. You’ll often use:

  • ConversationState – short-term memory during the current conversation
  • UserState – long-term memory scoped to the user

You must explicitly save state at the end of each turn:

await _conversationState.SaveChangesAsync(turnContext);

3.3.5 Dialogs and Teams Context

In Microsoft Teams, you must consider the conversation type (1:1, group chat, or channel). Not all dialog flows make sense in a channel — where multiple users may be present.

In group contexts, keep dialogs short, stateless, or shift to Task Modules for structured input.

3.3.6 When to Use Dialogs vs Task Modules

While dialogs are great for chat-based flows, sometimes UI is the better tool. Teams supports Task Modules, which are modal webviews that collect form data.

Use dialogs when:

  • You want to stay within the chat experience
  • The interaction is conversational or sequential
  • You want to build fallback logic or re-prompts

Use Task Modules when:

  • You need complex input (multiple fields, validation)
  • You want full control over layout or branding
  • You’re integrating an existing web app or form

3.3.7 Summary

Conversations are where bots come to life. Dialogs give you the ability to guide users, remember what they say, and respond with relevance. They’re not just a coding pattern — they’re how your bot becomes helpful, usable, and human-like.

In the next section, we’ll explore advanced bot features — including Task Modules, proactive messages, and message extensions — to expand your bot beyond chat.

2025-04-10

Shohei Shimoda

I organized and output what I have learned and know here.