How to Show the Next Web Page in a Teams Dialog in the Microsoft 365 Agents SDK in C#
A Teams dialog that shows a web page can lead on to a second page, and a third, for steps such as "read this" and then "confirm". Each page submits its step to your agent, and the agent answers with the next page's address. Teams loads it in the same dialog.
Syntax
On each page, the button that finishes the step:
microsoftTeams.dialog.url.submit({ task: "<step name>" }, "<app ID>");
In the agent, a route per step, answered with the next page:
TeamsExtension.TaskModules.OnSubmit("<step name>", handler);
// In the handler:
return new TaskModuleResponse
{
Task = new Response
{
Type = TaskModuleResponseTypes.Continue,
Value = new { title = "<title>", width = <width>, height = <height>, url = "<next page address>" },
},
};
| Part | What it does |
|---|---|
{ task: "<step name>" } | The page's result, named after the step it finishes |
"<app ID>" | Your Teams app's ID: the id at the top of its manifest.json |
OnSubmit("<step name>", handler) | Calls handler when that step's page submits |
Continue with url | Keeps the dialog open and loads the next page in it |
return null! | On the last step: no answer, so Teams closes the dialog |
Microsoft's Use dialogs with bots lists the answers a bot can give a task/submit. One of them is ContinueTask, which Allows you to chain sequences of Adaptive Cards together in a wizard or multi-step experience. The docs show it with cards. With a url instead of a card, it worked the same way for pages: Teams loaded the next page in the dialog.
The Example
The agent for this post welcomes new people to the office. Any message gets a card with a Read the house rules button. The dialog it opens has two pages: rules.html lists three rules and has a Next button, and accept.html asks do you accept the house rules? with an Accept button. After Accept, the dialog closes and the agent thanks the person in the chat.
Prerequisites
- An agent that already runs in Microsoft Teams, in a personal chat, with the Teams extension added.
- The agent serving its
wwwrootfolder withapp.MapStaticAssets(), at a public HTTPS address such as a dev tunnel's. - That address's host in your app's
validDomains, so Teams loads the pages in a dialog.
Step 1: Write the Two Pages
The first page, wwwroot/rules.html. Its Next button submits the step named next:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>House rules</title>
<style>
body { margin: 0; padding: 0 24px; font-family: "Segoe UI", system-ui, sans-serif; font-size: 14px; }
button { padding: 5px 20px; font: inherit; }
</style>
</head>
<body>
<p><strong>Step 1 of 2:</strong> the house rules.</p>
<ul>
<li>Book meeting rooms in Outlook.</li>
<li>Keep the second floor quiet.</li>
<li>Clean up the kitchen after lunch.</li>
</ul>
<button type="button" id="next">Next</button>
<script src="https://res.cdn.office.net/teams-js/2.60.0/js/MicrosoftTeams.min.js"
integrity="sha384-oM1pbPWSxyAWgEVI9GzHDR2xzdMMehbAdsl9cH5emcTxX9Qr/kE4IS/Ld5IdcLmy"
crossorigin="anonymous"></script>
<script>
// Your Teams app's ID, from its manifest.
const appId = "22222222-2222-2222-2222-222222222222";
async function start() {
await microsoftTeams.app.initialize();
document.getElementById("next").addEventListener("click", next);
}
function next() {
microsoftTeams.dialog.url.submit({ task: "next" }, appId);
}
start();
</script>
</body>
</html>
The second page, wwwroot/accept.html. Its Accept button submits the step named accept:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>House rules</title>
<style>
body { margin: 0; padding: 0 24px; font-family: "Segoe UI", system-ui, sans-serif; font-size: 14px; }
button { padding: 5px 20px; font: inherit; }
</style>
</head>
<body>
<p><strong>Step 2 of 2:</strong> do you accept the house rules?</p>
<button type="button" id="accept">Accept</button>
<script src="https://res.cdn.office.net/teams-js/2.60.0/js/MicrosoftTeams.min.js"
integrity="sha384-oM1pbPWSxyAWgEVI9GzHDR2xzdMMehbAdsl9cH5emcTxX9Qr/kE4IS/Ld5IdcLmy"
crossorigin="anonymous"></script>
<script>
// Your Teams app's ID, from its manifest.
const appId = "22222222-2222-2222-2222-222222222222";
async function start() {
await microsoftTeams.app.initialize();
document.getElementById("accept").addEventListener("click", accept);
}
function accept() {
microsoftTeams.dialog.url.submit({ task: "accept" }, appId);
}
start();
</script>
</body>
</html>
- Each page loads TeamsJS and connects with
await microsoftTeams.app.initialize()before its button gets a handler. How to Add the Teams JavaScript Library (TeamsJS) to a Web Page from the CDN explains the script tag. - Each button submits its own step name,
nextoraccept, so the agent can tell the steps apart. How to Submit a Web Page Dialog to Your Agent in the Microsoft 365 Agents SDK in C# explainsdialog.url.submit()and the app ID. appIdis your Teams app's ID. Copy theidfrom your app'smanifest.jsonin place of the placeholder, on both pages.
Step 2: Answer Each Step in the Agent
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.TaskModules;
namespace HouseRules;
[TeamsExtension]
public partial class HouseRulesAgent : AgentApplication
{
private readonly Uri _publicUrl;
public HouseRulesAgent(AgentApplicationOptions options, IConfiguration configuration)
: base(options)
{
// PublicUrl is the agent's public HTTPS address: the dev tunnel's. The pages are in wwwroot.
_publicUrl = new Uri(configuration["PublicUrl"]!);
OnActivity(ActivityTypes.Message, SendCardAsync);
TeamsExtension.TaskModules.OnFetch("rules", ShowRulesAsync);
TeamsExtension.TaskModules.OnSubmit("next", ShowAcceptPageAsync);
TeamsExtension.TaskModules.OnSubmit("accept", AcceptAsync);
}
// Any message gets a card whose button opens the dialog.
private Task SendCardAsync(ITurnContext turnContext, ITurnState turnState, CancellationToken cancellationToken)
{
JsonObject card = new()
{
["type"] = "AdaptiveCard",
["version"] = "1.5",
["body"] = new JsonArray
{
new JsonObject { ["type"] = "TextBlock", ["text"] = "Welcome to the office! Please read and accept the house rules.", ["wrap"] = true },
},
["actions"] = new JsonArray
{
new JsonObject
{
["type"] = "Action.Submit",
["title"] = "Read the house rules",
["data"] = new JsonObject { ["msteams"] = new JsonObject { ["type"] = "task/fetch" }, ["task"] = "rules" },
},
},
};
return turnContext.SendActivityAsync(MessageFactory.Attachment(new Attachment { ContentType = ContentTypes.AdaptiveCard, Content = card }), cancellationToken);
}
// task/fetch: step 1, the rules.
private Task<TaskModuleResponse> ShowRulesAsync(ITeamsTurnContext turnContext, ITurnState turnState, TaskModuleRequest request, CancellationToken cancellationToken)
{
return Task.FromResult(ShowPage("rules.html"));
}
// task/submit from step 1 ("task": "next"): another continue keeps the dialog open and loads step 2 in it.
private Task<TaskModuleResponse> ShowAcceptPageAsync(ITeamsTurnContext turnContext, ITurnState turnState, TaskModuleRequest request, CancellationToken cancellationToken)
{
return Task.FromResult(ShowPage("accept.html"));
}
// task/submit from step 2 ("task": "accept"): confirm in the chat, and no answer closes the dialog.
private async Task<TaskModuleResponse> AcceptAsync(ITeamsTurnContext turnContext, ITurnState turnState, TaskModuleRequest request, CancellationToken cancellationToken)
{
await turnContext.SendActivityAsync("Thanks for accepting the house rules.", cancellationToken: cancellationToken);
return null!;
}
// A continue answer that loads one of the pages in the dialog.
private TaskModuleResponse ShowPage(string page) => new()
{
Task = new Response
{
Type = TaskModuleResponseTypes.Continue,
Value = new { title = "House rules", width = 400, height = 230, url = new Uri(_publicUrl, page).ToString() },
},
};
}

ShowPage(string page)builds theContinueanswer for a page: the same title and size every time, and the page's address, made from the public address and the file name.OnFetch("rules", ShowRulesAsync)opens the dialog with step 1, from the card's button. How to Show a Web Page in a Teams Dialog in the Microsoft 365 Agents SDK in C# covers this first answer and thePublicUrlsetting.OnSubmit("next", ShowAcceptPageAsync)answers step 1's Next with step 2's page. This is the move to the next page: aContinueanswer to atask/submit.OnSubmit("accept", AcceptAsync)finishes: it thanks the person in the chat and returnsnull!, so Teams closes the dialog.
Step 3: Go Through the Steps in Teams
Replace the placeholder app ID on both pages, start the agent with dotnet run, and send it any message in Teams. Select Read the house rules on the card. The dialog opens with step 1:

Select Next. The dialog shows step 2:

Select Accept. The dialog closed, and the agent's message arrived in the chat:

What Each Button Sent
The agent's log showed three invokes. Their values, in order:
{ "data": { "task": "rules", "type": "task/fetch" }, "context": { "theme": "default" } }
{ "data": { "task": "next" }, "context": { "theme": "default" } }
{ "data": { "task": "accept" }, "context": { "theme": "default" } }
The first two answers were Continue responses, with https://cdzngt35-3980.inc1.devtunnels.ms/rules.html and then https://cdzngt35-3980.inc1.devtunnels.ms/accept.html as the url. The third was {"status":200}, with no body. With ASP.NET Core's request log on (the Microsoft.AspNetCore.Hosting.Diagnostics category at Information), the agent's output showed Teams asking for each page right after the answer that named it:
Request starting HTTP/1.1 POST http://localhost:3980/api/messages - application/json;+charset=utf-8 1421
Request finished HTTP/1.1 POST http://localhost:3980/api/messages - 200 - application/json;+charset=utf-8 36.4985ms
Request starting HTTP/1.1 GET http://localhost:3980/rules.html - - -
Request finished HTTP/1.1 GET http://localhost:3980/rules.html - 200 1197 text/html 6.3810ms
Request starting HTTP/1.1 POST http://localhost:3980/api/messages - application/json;+charset=utf-8 1265
Request finished HTTP/1.1 POST http://localhost:3980/api/messages - 200 - application/json;+charset=utf-8 14.6511ms
Request starting HTTP/1.1 GET http://localhost:3980/accept.html - - -
Request finished HTTP/1.1 GET http://localhost:3980/accept.html - 200 1075 text/html 0.7379ms
Request starting HTTP/1.1 POST http://localhost:3980/api/messages - application/json;+charset=utf-8 1267
Request finished HTTP/1.1 POST http://localhost:3980/api/messages - 200 0 - 321.3111ms
The last POST answered with no body (200 0), and no page request followed it: the dialog was closed.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Returning null! for a step that isn't the last | Teams closes the dialog instead of showing the next page | Answer with Continue and the next page's url |
| The same step name on two pages | Both buttons reach the same route | Give each page's result its own task name |
A next page on a domain that isn't in validDomains | Teams loads pages only from listed domains | List every domain the dialog's pages come from |
| Leaving the placeholder app ID on one of the pages | That page doesn't name your app | Copy your manifest's id into every page |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| The dialog closes after Next | The handler for that step returned null! | Return ShowPage("<next page>") |
| Next does nothing | The page's script stopped before the button got its handler | Open the browser console and read the first error |
FAQ
Why go through the agent instead of linking the pages to each other?
A link would load the next page without a task/submit, so the agent's routes would never see the step. Through the agent, every step's result reaches your code first, and the agent decides what comes next, as it does for card dialogs.
How do I end the dialog with a message instead of closing it?
Answer the last step with a Message response: How to Close a Teams Dialog with a Message in the Microsoft 365 Agents SDK in C#.
Is this different from a multi-step card dialog?
Only in what each step shows. A card dialog answers each step with the next card; this one answers with the next page's url: How to Build a Multi-Step Teams Dialog in the Microsoft 365 Agents SDK in C# shows the card version.
Conclusion
To show the next web page in a Teams dialog, have each page submit its own step name with microsoftTeams.dialog.url.submit(), route each name with TeamsExtension.TaskModules.OnSubmit, and answer with a Continue response whose url is the next page. On the last step, return null! to close the dialog.
Additional Resources
- Use dialogs with bots: Handle dialog submit events, on Microsoft Learn.
- Invoke and dismiss dialogs, on Microsoft Learn.
- TaskModule.OnSubmit Method, on Microsoft Learn.
Related
- How to Show a Web Page in a Teams Dialog in the Microsoft 365 Agents SDK in C#
- How to Submit a Web Page Dialog to Your Agent in the Microsoft 365 Agents SDK in C#
- How to Build a Multi-Step Teams Dialog in the Microsoft 365 Agents SDK in C#
- Microsoft 365 Agents SDK Fundamentals in C# — Part 11: Show a Web Page in a Teams Dialog
