microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
core/samples/CoreBot/Program.cs
33lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | using Azure.Monitor.OpenTelemetry.AspNetCore; |
| 5 | using Microsoft.Bot.Core; |
| 6 | using Microsoft.Bot.Core.Hosting; |
| 7 | using Microsoft.Bot.Core.Schema; |
| 8 | |
| 9 | WebApplicationBuilder webAppBuilder = WebApplication.CreateSlimBuilder(args); |
| 10 | webAppBuilder.Services.AddOpenTelemetry().UseAzureMonitor(); |
| 11 | webAppBuilder.Services.AddBotApplication<BotApplication>(); |
| 12 | WebApplication webApp = webAppBuilder.Build(); |
| 13 | BotApplication botApp = webApp.UseBotApplication<BotApplication>(); |
| 14 | |
| 15 | webApp.MapGet("/", () => "CoreBot is running."); |
| 16 | |
| 17 | botApp.OnActivity = async (activity, cancellationToken) => |
| 18 | { |
| 19 | string replyText = $"CoreBot running on SDK {BotApplication.Version}."; |
| 20 | replyText += $"<br /> You sent: `{activity.Text}` in activity of type `{activity.Type}`."; |
| 21 | |
| 22 | string? conversationType = "unknown conversation type"; |
| 23 | if (activity.Conversation.Properties.TryGetValue("conversationType", out object? ctProp)) |
| 24 | { |
| 25 | conversationType = ctProp?.ToString(); |
| 26 | } |
| 27 | |
| 28 | replyText += $"<br /> To Conversation ID: `{activity.Conversation.Id}` conv type: `{conversationType}`"; |
| 29 | CoreActivity replyActivity = activity.CreateReplyMessageActivity(replyText); |
| 30 | await botApp.SendActivityAsync(replyActivity, cancellationToken); |
| 31 | }; |
| 32 | |
| 33 | webApp.Run(); |
| 34 | |