// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. using Microsoft.Teams.Api.Activities; using Microsoft.Teams.Apps.Routing; namespace Microsoft.Teams.Apps.Activities; public static partial class Message { [AttributeUsage(AttributeTargets.Method, Inherited = true)] public class UpdateAttribute() : ActivityAttribute(ActivityType.MessageUpdate, typeof(MessageUpdateActivity)) { public override object Coerce(IContext context) => context.ToActivityType(); } } public static partial class AppActivityExtensions { [Obsolete("Use the handler with the cancellation token")] public static App OnMessageUpdate(this App app, Func, Task> handler) { app.Router.Register(new Route() { Name = ActivityType.MessageUpdate, Type = app.Status is null ? RouteType.System : RouteType.User, Handler = async context => { await handler(context.ToActivityType()).ConfigureAwait(false); return null; }, Selector = activity => activity is MessageUpdateActivity }); return app; } public static App OnMessageUpdate(this App app, Func, CancellationToken, Task> handler) { app.Router.Register(new Route() { Name = ActivityType.MessageUpdate, Type = app.Status is null ? RouteType.System : RouteType.User, Handler = async context => { await handler(context.ToActivityType(), context.CancellationToken).ConfigureAwait(false); return null; }, Selector = activity => activity is MessageUpdateActivity }); return app; } }