microsoft/teams.net
Publicmirrored from https://github.com/microsoft/teams.netAvailable
Libraries/Microsoft.Teams.Apps/Activities/Invokes/Configs/SubmitActivity.cs
110lines · 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.Invokes; |
| 6 | using Microsoft.Teams.Api.Config; |
| 7 | using Microsoft.Teams.Apps.Routing; |
| 8 | |
| 9 | namespace Microsoft.Teams.Apps.Activities.Invokes; |
| 10 | |
| 11 | public static partial class Config |
| 12 | { |
| 13 | [AttributeUsage(AttributeTargets.Method, Inherited = true)] |
| 14 | public class SubmitAttribute() : InvokeAttribute(Api.Activities.Invokes.Name.Configs.Submit, typeof(Configs.SubmitActivity)) |
| 15 | { |
| 16 | public override object Coerce(IContext<IActivity> context) => context.ToActivityType<Configs.SubmitActivity>(); |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | public static partial class AppInvokeActivityExtensions |
| 21 | { |
| 22 | [Obsolete("Use the handler with the cancellation token")] |
| 23 | public static App OnConfigSubmit(this App app, Func<IContext<Configs.SubmitActivity>, Task> handler) |
| 24 | { |
| 25 | app.Router.Register(new Route() |
| 26 | { |
| 27 | Name = string.Join("/", [ActivityType.Invoke, Name.Configs.Submit]), |
| 28 | Type = app.Status is null ? RouteType.System : RouteType.User, |
| 29 | Handler = async context => |
| 30 | { |
| 31 | await handler(context.ToActivityType<Configs.SubmitActivity>()).ConfigureAwait(false); |
| 32 | return null; |
| 33 | }, |
| 34 | Selector = activity => activity is Configs.SubmitActivity |
| 35 | }); |
| 36 | |
| 37 | return app; |
| 38 | } |
| 39 | |
| 40 | [Obsolete("Use the handler with the cancellation token")] |
| 41 | public static App OnConfigSubmit(this App app, Func<IContext<Configs.SubmitActivity>, Task<Response<ConfigResponse>>> handler) |
| 42 | { |
| 43 | app.Router.Register(new Route() |
| 44 | { |
| 45 | Name = string.Join("/", [ActivityType.Invoke, Name.Configs.Submit]), |
| 46 | Type = app.Status is null ? RouteType.System : RouteType.User, |
| 47 | Handler = async context => await handler(context.ToActivityType<Configs.SubmitActivity>()).ConfigureAwait(false), |
| 48 | Selector = activity => activity is Configs.SubmitActivity |
| 49 | }); |
| 50 | |
| 51 | return app; |
| 52 | } |
| 53 | |
| 54 | [Obsolete("Use the handler with the cancellation token")] |
| 55 | public static App OnConfigSubmit(this App app, Func<IContext<Configs.SubmitActivity>, Task<ConfigResponse>> handler) |
| 56 | { |
| 57 | app.Router.Register(new Route() |
| 58 | { |
| 59 | Name = string.Join("/", [ActivityType.Invoke, Name.Configs.Submit]), |
| 60 | Type = app.Status is null ? RouteType.System : RouteType.User, |
| 61 | Handler = async context => await handler(context.ToActivityType<Configs.SubmitActivity>()).ConfigureAwait(false), |
| 62 | Selector = activity => activity is Configs.SubmitActivity |
| 63 | }); |
| 64 | |
| 65 | return app; |
| 66 | } |
| 67 | |
| 68 | public static App OnConfigSubmit(this App app, Func<IContext<Configs.SubmitActivity>, CancellationToken, Task> handler) |
| 69 | { |
| 70 | app.Router.Register(new Route() |
| 71 | { |
| 72 | Name = string.Join("/", [ActivityType.Invoke, Name.Configs.Submit]), |
| 73 | Type = app.Status is null ? RouteType.System : RouteType.User, |
| 74 | Handler = async context => |
| 75 | { |
| 76 | await handler(context.ToActivityType<Configs.SubmitActivity>(), context.CancellationToken).ConfigureAwait(false); |
| 77 | return null; |
| 78 | }, |
| 79 | Selector = activity => activity is Configs.SubmitActivity |
| 80 | }); |
| 81 | |
| 82 | return app; |
| 83 | } |
| 84 | |
| 85 | public static App OnConfigSubmit(this App app, Func<IContext<Configs.SubmitActivity>, CancellationToken, Task<Response<ConfigResponse>>> handler) |
| 86 | { |
| 87 | app.Router.Register(new Route() |
| 88 | { |
| 89 | Name = string.Join("/", [ActivityType.Invoke, Name.Configs.Submit]), |
| 90 | Type = app.Status is null ? RouteType.System : RouteType.User, |
| 91 | Handler = async context => await handler(context.ToActivityType<Configs.SubmitActivity>(), context.CancellationToken).ConfigureAwait(false), |
| 92 | Selector = activity => activity is Configs.SubmitActivity |
| 93 | }); |
| 94 | |
| 95 | return app; |
| 96 | } |
| 97 | |
| 98 | public static App OnConfigSubmit(this App app, Func<IContext<Configs.SubmitActivity>, CancellationToken, Task<ConfigResponse>> handler) |
| 99 | { |
| 100 | app.Router.Register(new Route() |
| 101 | { |
| 102 | Name = string.Join("/", [ActivityType.Invoke, Name.Configs.Submit]), |
| 103 | Type = app.Status is null ? RouteType.System : RouteType.User, |
| 104 | Handler = async context => await handler(context.ToActivityType<Configs.SubmitActivity>(), context.CancellationToken).ConfigureAwait(false), |
| 105 | Selector = activity => activity is Configs.SubmitActivity |
| 106 | }); |
| 107 | |
| 108 | return app; |
| 109 | } |
| 110 | } |