microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
Libraries/Microsoft.Teams.Apps/Activities/Events/MeetingJoinActivity.cs
64lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | using Microsoft.Teams.Api.Activities; |
| 5 | using Microsoft.Teams.Api.Activities.Events; |
| 6 | using Microsoft.Teams.Apps.Routing; |
| 7 | |
| 8 | namespace Microsoft.Teams.Apps.Activities.Events; |
| 9 | |
| 10 | public static partial class Event |
| 11 | { |
| 12 | [AttributeUsage(AttributeTargets.Method, Inherited = true)] |
| 13 | public class MeetingJoinAttribute() : EventAttribute(Api.Activities.Events.Name.MeetingParticipantJoin) |
| 14 | { |
| 15 | public override object Coerce(IContext<IActivity> context) => context.ToActivityType<MeetingParticipantJoinActivity>(); |
| 16 | public override bool Select(IActivity activity) |
| 17 | { |
| 18 | if (activity is MeetingParticipantJoinActivity) |
| 19 | { |
| 20 | return true; |
| 21 | } |
| 22 | |
| 23 | return false; |
| 24 | } |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | public static partial class AppEventActivityExtensions |
| 29 | { |
| 30 | [Obsolete("Use the handler with the cancellation token")] |
| 31 | public static App OnMeetingJoin(this App app, Func<IContext<MeetingParticipantJoinActivity>, Task> handler) |
| 32 | { |
| 33 | app.Router.Register(new Route() |
| 34 | { |
| 35 | Name = string.Join("/", [ActivityType.Event, Name.MeetingParticipantJoin]), |
| 36 | Type = app.Status is null ? RouteType.System : RouteType.User, |
| 37 | Handler = async context => |
| 38 | { |
| 39 | await handler(context.ToActivityType<MeetingParticipantJoinActivity>()).ConfigureAwait(false); |
| 40 | return null; |
| 41 | }, |
| 42 | Selector = activity => activity is MeetingParticipantJoinActivity |
| 43 | }); |
| 44 | |
| 45 | return app; |
| 46 | } |
| 47 | |
| 48 | public static App OnMeetingJoin(this App app, Func<IContext<MeetingParticipantJoinActivity>, CancellationToken, Task> handler) |
| 49 | { |
| 50 | app.Router.Register(new Route() |
| 51 | { |
| 52 | Name = string.Join("/", [ActivityType.Event, Name.MeetingParticipantJoin]), |
| 53 | Type = app.Status is null ? RouteType.System : RouteType.User, |
| 54 | Handler = async context => |
| 55 | { |
| 56 | await handler(context.ToActivityType<MeetingParticipantJoinActivity>(), context.CancellationToken).ConfigureAwait(false); |
| 57 | return null; |
| 58 | }, |
| 59 | Selector = activity => activity is MeetingParticipantJoinActivity |
| 60 | }); |
| 61 | |
| 62 | return app; |
| 63 | } |
| 64 | } |