microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
Libraries/Microsoft.Teams.Apps/Activities/Conversations/ChannelSharedActivity.cs
75lines · modecode
| 1 | using Microsoft.Teams.Api.Activities; |
| 2 | using Microsoft.Teams.Apps.Routing; |
| 3 | |
| 4 | namespace Microsoft.Teams.Apps.Activities; |
| 5 | |
| 6 | public static partial class Conversation |
| 7 | { |
| 8 | [AttributeUsage(AttributeTargets.Method, Inherited = true)] |
| 9 | public class ChannelSharedAttribute() : UpdateAttribute(ConversationUpdateActivity.EventType.ChannelShared) |
| 10 | { |
| 11 | public override bool Select(IActivity activity) |
| 12 | { |
| 13 | if (activity is ConversationUpdateActivity update) |
| 14 | { |
| 15 | return update.ChannelData?.EventType == ConversationUpdateActivity.EventType.ChannelShared; |
| 16 | } |
| 17 | |
| 18 | return false; |
| 19 | } |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | public static partial class AppActivityExtensions |
| 24 | { |
| 25 | [Obsolete("Use the handler with the cancellation token")] |
| 26 | public static App OnChannelShared(this App app, Func<IContext<ConversationUpdateActivity>, Task> handler) |
| 27 | { |
| 28 | app.Router.Register(new Route() |
| 29 | { |
| 30 | Name = string.Join("/", [ActivityType.ConversationUpdate, ConversationUpdateActivity.EventType.ChannelShared]), |
| 31 | Type = app.Status is null ? RouteType.System : RouteType.User, |
| 32 | Handler = async context => |
| 33 | { |
| 34 | await handler(context.ToActivityType<ConversationUpdateActivity>()).ConfigureAwait(false); |
| 35 | return null; |
| 36 | }, |
| 37 | Selector = activity => |
| 38 | { |
| 39 | if (activity is ConversationUpdateActivity update) |
| 40 | { |
| 41 | return update.ChannelData?.EventType == ConversationUpdateActivity.EventType.ChannelShared; |
| 42 | } |
| 43 | |
| 44 | return false; |
| 45 | } |
| 46 | }); |
| 47 | |
| 48 | return app; |
| 49 | } |
| 50 | |
| 51 | public static App OnChannelShared(this App app, Func<IContext<ConversationUpdateActivity>, CancellationToken, Task> handler) |
| 52 | { |
| 53 | app.Router.Register(new Route() |
| 54 | { |
| 55 | Name = string.Join("/", [ActivityType.ConversationUpdate, ConversationUpdateActivity.EventType.ChannelShared]), |
| 56 | Type = app.Status is null ? RouteType.System : RouteType.User, |
| 57 | Handler = async context => |
| 58 | { |
| 59 | await handler(context.ToActivityType<ConversationUpdateActivity>(), context.CancellationToken).ConfigureAwait(false); |
| 60 | return null; |
| 61 | }, |
| 62 | Selector = activity => |
| 63 | { |
| 64 | if (activity is ConversationUpdateActivity update) |
| 65 | { |
| 66 | return update.ChannelData?.EventType == ConversationUpdateActivity.EventType.ChannelShared; |
| 67 | } |
| 68 | |
| 69 | return false; |
| 70 | } |
| 71 | }); |
| 72 | |
| 73 | return app; |
| 74 | } |
| 75 | } |