microsoft/teams.net

Public

mirrored fromhttps://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
feature/extended-markdown-text-format

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

Samples/Samples.FormattedMessaging/Program.cs

83lines · modecode

1using Microsoft.Teams.Api;
2using Microsoft.Teams.Apps.Activities;
3using Microsoft.Teams.Apps.Extensions;
4using Microsoft.Teams.Plugins.AspNetCore.Extensions;
5
6using MessageActivity = Microsoft.Teams.Api.Activities.MessageActivity;
7
8var builder = WebApplication.CreateBuilder(args);
9builder.AddTeams();
10var app = builder.Build();
11var teams = app.UseTeams();
12
13teams.OnMessage(async (context, cancellationToken) =>
14{
15 await context.Typing("processing your response", cancellationToken);
16 var text = context.Activity.Text?.ToLowerInvariant() ?? "";
17
18 if (text.Contains("extended"))
19 {
20 var reply = new MessageActivity("""
21# Extended Markdown Demo
22
23## Table
24| Feature | Status |
25|---------|--------|
26| Tables | Supported |
27| Math | Supported |
28
29## Math
30$$E = mc^2$$
31""")
32 {
33 TextFormat = TextFormat.ExtendedMarkdown
34 };
35 await context.Send(reply, cancellationToken);
36 }
37 else if (text.Contains("markdown"))
38 {
39 var reply = new MessageActivity("""
40# Markdown Demo
41
42**Bold**, *italic*, and ~~strikethrough~~
43
44- Item one
45- Item two
46- Item three
47
48> This is a blockquote
49
50`inline code` and [a link](https://www.microsoft.com)
51""")
52 {
53 TextFormat = TextFormat.Markdown
54 };
55 await context.Send(reply, cancellationToken);
56 }
57 else if (text.Contains("xml"))
58 {
59 var reply = new MessageActivity(
60 "<b>Bold</b>, <i>italic</i>, and <strike>strikethrough</strike><br/>" +
61 "<ul><li>Item one</li><li>Item two</li><li>Item three</li></ul>")
62 {
63 TextFormat = TextFormat.Xml
64 };
65 await context.Send(reply, cancellationToken);
66 }
67 else if (text.Contains("plain"))
68 {
69 var reply = new MessageActivity("This is plain text with no formatting applied.")
70 {
71 TextFormat = TextFormat.Plain
72 };
73 await context.Send(reply, cancellationToken);
74 }
75 else
76 {
77 await context.Send(
78 "Send **markdown**, **extended**, **xml**, or **plain** to see different text formats.",
79 cancellationToken);
80 }
81});
82
83app.Run();
84