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