Skip to main content

How to Set the Size of a Teams Dialog in the Microsoft 365 Agents SDK in C#

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

A Teams dialog is as big as your agent says. A short message fits a small window, and a form with many fields needs a large one. The size goes in the same answer that opens the dialog, as a named size or in pixels.

Syntax​

C#
Value = new
{
title = "<title>",
width = <width>,
height = <height>,
card = <the dialog's card>,
},
PartWhat it does
width"small", "medium" or "large", or a number of pixels such as 400
heightThe same choices, for the height

Microsoft's Invoke and dismiss dialogs describes both kinds of values. Named sizes are a proportion of the available space, 20%, 50%, and 60% for width and 20%, 50%, and 66% for height. Pixels are exact, but Depending on the size of the Teams window and screen resolution, these values might be reduced proportionally while maintaining aspect ratio.

The value is an object, so it holds either a string or a number. The Teams package also has the names as constants, in TaskModuleSizes.

The Example​

The agent for this post sends a card with four buttons: small, medium, large and 400x300. Each opens the same one-line dialog in that size. Teams ran in a browser window 1600 pixels wide and 1000 high.

Prerequisites​

  • An agent that already runs in Microsoft Teams, in a personal chat, with the Teams extension added.

Step 1: Size the Dialog in the Answer​

SizeAgent.cs
using System.Text.Json.Nodes;
using Microsoft.Agents.Builder;
using Microsoft.Agents.Builder.App;
using Microsoft.Agents.Builder.State;
using Microsoft.Agents.Core.Models;
using Microsoft.Agents.Extensions.MSTeams;
using Microsoft.Teams.Apps.Schema;
using Microsoft.Teams.Apps.TaskModules;

namespace HoSize;

[TeamsExtension]
public partial class SizeAgent : AgentApplication
{
public SizeAgent(AgentApplicationOptions options) : base(options)
{
OnActivity(ActivityTypes.Message, SendCardAsync);
TeamsExtension.TaskModules.OnFetch("size", OpenAsync);
}

// One button per size. Each sends the size it asks for, next to "task": "size".
private Task SendCardAsync(ITurnContext turnContext, ITurnState turnState, CancellationToken cancellationToken)
{
JsonArray actions = new();

foreach (string size in new[] { "small", "medium", "large", "400x300" })
{
actions.Add(new JsonObject
{
["type"] = "Action.Submit",
["title"] = size,
["data"] = new JsonObject
{
["msteams"] = new JsonObject { ["type"] = "task/fetch" },
["task"] = "size",
["size"] = size,
},
});
}

JsonObject card = new()
{
["type"] = "AdaptiveCard",
["version"] = "1.5",
["body"] = new JsonArray
{
new JsonObject { ["type"] = "TextBlock", ["text"] = "Dialog sizes", ["size"] = "Large", ["weight"] = "Bolder" },
new JsonObject { ["type"] = "TextBlock", ["text"] = "Open the same dialog in each size.", ["wrap"] = true },
},
["actions"] = actions,
};

return turnContext.SendActivityAsync(
MessageFactory.Attachment(new Attachment { ContentType = ContentTypes.AdaptiveCard, Content = card }),
cancellationToken);
}

// The width and height are either "small", "medium" or "large", or a number of pixels.
private Task<TaskModuleResponse> OpenAsync(ITeamsTurnContext turnContext, ITurnState turnState, TaskModuleRequest request, CancellationToken cancellationToken)
{
string size = request.GetDataString("size");
object width = size;
object height = size;

if (size == "400x300")
{
width = 400;
height = 300;
}

JsonObject card = new()
{
["type"] = "AdaptiveCard",
["version"] = "1.5",
["body"] = new JsonArray
{
new JsonObject { ["type"] = "TextBlock", ["text"] = $"This dialog is {size}.", ["wrap"] = true },
},
};

TaskModuleResponse response = new()
{
Task = new Response
{
Type = TaskModuleResponseTypes.Continue,
Value = new
{
title = $"Size: {size}",
width,
height,
card = new TeamsAttachment { ContentType = AttachmentContentTypes.AdaptiveCard, Content = card },
},
},
};

return Task.FromResult(response);
}
}

SizeAgent.cs in a macOS-style editor window: OpenAsync reads size from the button's data, uses it as both width and height, switches to 400 and 300 for 400x300, and returns a continue answer with the title Size: and the size, width, height and a one-line card

  • Each button's data carries "task": "size" and the size it asks for.
  • OpenAsync reads that size with GetDataString, and uses it for width and height. For 400x300, it sets the numbers 400 and 300 instead.
  • width and height are objects, so one variable can hold a string or a number.

Step 2: Open Each Size​

Send the agent any message:

The Dialog sizes card in Teams: Open the same dialog in each size, with small, medium, large and 400x300 buttons

Each button opened the dialog at the center of the window. Their measured sizes, in a window 1600 pixels wide and 1000 high:

Buttonwidth / height sentDialog size on screen
small"small" / "small"320 × 297
medium"medium" / "medium"800 × 567
large"large" / "large"960 × 727
400x300400 / 300400 × 367

The small dialog: the Dialog Demo icon and name, the title Size: small, an X, and the line This dialog is small.

The medium dialog, much wider: Size: medium, and This dialog is medium.

The large dialog, wider and taller still: Size: large, and This dialog is large.

The 400 by 300 dialog: Size: 400x300, and This dialog is 400x300.

  • The widths were 20%, 50% and 60% of the 1600-pixel window, as Microsoft's page says.
  • The heights include the dialog's top part, with the app's name, the title and the X: the 300-pixel dialog came out 367 pixels high, 67 more than asked for.

Common Mistakes​

MistakeWhat happensDo this instead
Fixed pixels for every screenTeams may scale them down in smaller windows, as Microsoft's page saysPrefer the named sizes, which follow the window
Expecting the height to be the card's areaThe height includes the dialog's top partAllow for it, or use a named size

Troubleshooting​

SymptomLikely causeFix
The dialog is taller than the pixels you setThe height includes the dialog's top partAllow about 67 pixels for it
The dialog is smaller than you setThe Teams window is smallerUse named sizes, or smaller numbers

FAQ​

Can width and height differ?​

Yes: they're separate values. Mixing them, such as a medium width with a small height, suits short dialogs with long lines.

Conclusion​

Set a Teams dialog's size with width and height in the Continue answer that opens it: small, medium or large for a share of the Teams window, or pixels for an exact size, which Teams may scale down. Named widths came out at 20%, 50% and 60% of the window.

Additional Resources​