microsoft/teams.net
Publicmirrored from https://github.com/microsoft/teams.netAvailable
Libraries/Microsoft.Teams.Apps/Activities/Conversations/ConversationEndActivity.cs
62lines · 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 | [Obsolete("This will be removed by end of summer 2026.")] |
| 13 | #pragma warning disable CS0618 |
| 14 | public class EndAttribute() : ActivityAttribute(ActivityType.EndOfConversation, typeof(EndOfConversationActivity)) |
| 15 | { |
| 16 | public override object Coerce(IContext<IActivity> context) => context.ToActivityType<EndOfConversationActivity>(); |
| 17 | } |
| 18 | #pragma warning restore CS0618 |
| 19 | } |
| 20 | |
| 21 | public static partial class AppActivityExtensions |
| 22 | { |
| 23 | [Obsolete("Use the handler with the cancellation token. This will be removed by end of summer 2026.")] |
| 24 | #pragma warning disable CS0618 |
| 25 | public static App OnConversationEnd(this App app, Func<IContext<EndOfConversationActivity>, Task> handler) |
| 26 | { |
| 27 | app.Router.Register(new Route() |
| 28 | { |
| 29 | Name = ActivityType.EndOfConversation, |
| 30 | Type = app.Status is null ? RouteType.System : RouteType.User, |
| 31 | Handler = async context => |
| 32 | { |
| 33 | await handler(context.ToActivityType<EndOfConversationActivity>()).ConfigureAwait(false); |
| 34 | return null; |
| 35 | }, |
| 36 | Selector = activity => activity is EndOfConversationActivity |
| 37 | }); |
| 38 | |
| 39 | return app; |
| 40 | } |
| 41 | #pragma warning restore CS0618 |
| 42 | |
| 43 | [Obsolete("This will be removed by end of summer 2026.")] |
| 44 | #pragma warning disable CS0618 |
| 45 | public static App OnConversationEnd(this App app, Func<IContext<EndOfConversationActivity>, CancellationToken, Task> handler) |
| 46 | { |
| 47 | app.Router.Register(new Route() |
| 48 | { |
| 49 | Name = ActivityType.EndOfConversation, |
| 50 | Type = app.Status is null ? RouteType.System : RouteType.User, |
| 51 | Handler = async context => |
| 52 | { |
| 53 | await handler(context.ToActivityType<EndOfConversationActivity>(), context.CancellationToken).ConfigureAwait(false); |
| 54 | return null; |
| 55 | }, |
| 56 | Selector = activity => activity is EndOfConversationActivity |
| 57 | }); |
| 58 | |
| 59 | return app; |
| 60 | } |
| 61 | #pragma warning restore CS0618 |
| 62 | } |