microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
core/samples/MigrationBot/LegacyEchoBot.cs
48lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | using Microsoft.Bot.Builder; |
| 5 | using Microsoft.Bot.Builder.Teams; |
| 6 | using Microsoft.Bot.Schema; |
| 7 | |
| 8 | namespace MigrationBot; |
| 9 | |
| 10 | /// <summary> |
| 11 | /// Bot Framework–style echo bot — the "legacy" side of the migration. |
| 12 | /// |
| 13 | /// To migrate a handler to the Teams SDK: |
| 14 | /// 1. Move the logic to the corresponding Teams SDK handler in Program.cs |
| 15 | /// (e.g. teamsApp.OnMessage / teamsApp.OnMembersAdded). |
| 16 | /// 2. Delete the override from this class. |
| 17 | /// |
| 18 | /// Once this class has no overrides left, remove it, unregister the IBot, |
| 19 | /// and drop the CompatAdapter (see Program.cs for full migration steps). |
| 20 | /// </summary> |
| 21 | internal class LegacyEchoBot : TeamsActivityHandler |
| 22 | { |
| 23 | // ── Handler: message activity ───────────────────────────────────────────── |
| 24 | // Migrated Teams SDK equivalent in Program.cs: |
| 25 | // teamsApp.OnMessage(async (context, ct) => |
| 26 | // await context.SendActivityAsync($"Echo (Teams SDK): {context.Activity.Text}", ct)); |
| 27 | protected override async Task OnMessageActivityAsync( |
| 28 | ITurnContext<IMessageActivity> turnContext, |
| 29 | CancellationToken cancellationToken) |
| 30 | { |
| 31 | string replyText = $"Echo (Bot Framework): {turnContext.Activity.Text}"; |
| 32 | await turnContext.SendActivityAsync(MessageFactory.Text(replyText), cancellationToken); |
| 33 | } |
| 34 | |
| 35 | // ── Handler: members added ──────────────────────────────────────────────── |
| 36 | // Migrated Teams SDK equivalent in Program.cs: |
| 37 | // teamsApp.OnMembersAdded(async (context, ct) => |
| 38 | // await context.SendActivityAsync("Welcome! ...", ct)); |
| 39 | protected override async Task OnMembersAddedAsync( |
| 40 | IList<ChannelAccount> membersAdded, |
| 41 | ITurnContext<IConversationUpdateActivity> turnContext, |
| 42 | CancellationToken cancellationToken) |
| 43 | { |
| 44 | await turnContext.SendActivityAsync( |
| 45 | MessageFactory.Text("Welcome! This bot is powered by Bot Framework via CompatAdapter."), |
| 46 | cancellationToken); |
| 47 | } |
| 48 | } |
| 49 | |