microsoft/teams.net
Publicmirrored from https://github.com/microsoft/teams.netAvailable
core/samples/CoreBot/Program.cs
32lines · 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 | |
| 16 | botApp.OnActivity = async (activity, cancellationToken) => |
| 17 | { |
| 18 | string replyText = $"CoreBot running on SDK {BotApplication.Version}."; |
| 19 | replyText += $"\r\nYou sent: `{activity.Text}` in activity of type `{activity.Type}`."; |
| 20 | |
| 21 | string? conversationType = "unknown conversation type"; |
| 22 | if (activity.Conversation.Properties.TryGetValue("conversationType", out object? ctProp)) |
| 23 | { |
| 24 | conversationType = ctProp?.ToString(); |
| 25 | } |
| 26 | |
| 27 | replyText += $"\r\n to Conversation ID: `{activity.Conversation.Id}` conv type: `{conversationType}`"; |
| 28 | CoreActivity replyActivity = activity.CreateReplyMessageActivity(replyText); |
| 29 | await botApp.SendActivityAsync(replyActivity, cancellationToken); |
| 30 | }; |
| 31 | |
| 32 | webApp.Run(); |
| 33 | |