microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
core/samples/MeetingsBot/Program.cs
68lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | using Microsoft.Teams.Apps; |
| 5 | using Microsoft.Teams.Apps.Handlers; |
| 6 | |
| 7 | WebApplicationBuilder webAppBuilder = WebApplication.CreateSlimBuilder(args); |
| 8 | webAppBuilder.Services.AddTeamsBotApplication(); |
| 9 | WebApplication webApp = webAppBuilder.Build(); |
| 10 | |
| 11 | TeamsBotApplication teamsApp = webApp.UseTeamsBotApplication(); |
| 12 | |
| 13 | // ==================== MEETING HANDLERS ==================== |
| 14 | |
| 15 | teamsApp.OnMeetingStart(async (context, cancellationToken) => |
| 16 | { |
| 17 | MeetingStartValue? meeting = context.Activity.Value; |
| 18 | Console.WriteLine($"[MeetingStart] Title: {meeting?.Title}"); |
| 19 | await context.SendActivityAsync($"Meeting started: **{meeting?.Title}**", cancellationToken); |
| 20 | }); |
| 21 | |
| 22 | teamsApp.OnMeetingEnd(async (context, cancellationToken) => |
| 23 | { |
| 24 | MeetingEndValue? meeting = context.Activity.Value; |
| 25 | Console.WriteLine($"[MeetingEnd] Title: {meeting?.Title}, EndTime: {meeting?.EndTime:u}"); |
| 26 | await context.SendActivityAsync($"Meeting ended: **{meeting?.Title}**\nEnd time: {meeting?.EndTime:u}", cancellationToken); |
| 27 | }); |
| 28 | |
| 29 | teamsApp.OnMeetingParticipantJoin(async (context, cancellationToken) => |
| 30 | { |
| 31 | IList<MeetingParticipantMember> members = context.Activity.Value?.Members ?? []; |
| 32 | string names = string.Join(", ", members.Select(m => m.User.Name ?? m.User.Id)); |
| 33 | Console.WriteLine($"[MeetingParticipantJoin] Members: {names}"); |
| 34 | await context.SendActivityAsync($"Participant(s) joined: {names}", cancellationToken); |
| 35 | }); |
| 36 | |
| 37 | teamsApp.OnMeetingParticipantLeave(async (context, cancellationToken) => |
| 38 | { |
| 39 | IList<MeetingParticipantMember> members = context.Activity.Value?.Members ?? []; |
| 40 | string names = string.Join(", ", members.Select(m => m.User.Name ?? m.User.Id)); |
| 41 | Console.WriteLine($"[MeetingParticipantLeave] Members: {names}"); |
| 42 | await context.SendActivityAsync($"Participant(s) left: {names}", cancellationToken); |
| 43 | }); |
| 44 | |
| 45 | //TODO : review if we can trigger these |
| 46 | // ==================== COMMAND HANDLERS ==================== |
| 47 | /* |
| 48 | |
| 49 | teamsApp.OnCommand(async (context, cancellationToken) => |
| 50 | { |
| 51 | var commandId = context.Activity.Value?.CommandId ?? "unknown"; |
| 52 | Console.WriteLine($"[Command] CommandId: {commandId}"); |
| 53 | await context.SendActivityAsync($"Received command: **{commandId}**", cancellationToken); |
| 54 | }); |
| 55 | |
| 56 | teamsApp.OnCommandResult(async (context, cancellationToken) => |
| 57 | { |
| 58 | var commandId = context.Activity.Value?.CommandId ?? "unknown"; |
| 59 | var error = context.Activity.Value?.Error; |
| 60 | Console.WriteLine($"[CommandResult] CommandId: {commandId}, HasError: {error is not null}"); |
| 61 | |
| 62 | if (error is not null) |
| 63 | await context.SendActivityAsync($"Command **{commandId}** failed: {error.Message}", cancellationToken); |
| 64 | else |
| 65 | await context.SendActivityAsync($"Command **{commandId}** completed successfully.", cancellationToken); |
| 66 | }); |
| 67 | */ |
| 68 | webApp.Run(); |
| 69 | |