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