microsoft/teams.net

Public

mirrored from https://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
devtools-port-no-auth

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

core/src/Microsoft.Teams.Bot.Apps/Handlers/MessageDeleteHandler.cs

46lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4using Microsoft.Teams.Bot.Apps.Routing;
5using Microsoft.Teams.Bot.Apps.Schema;
6
7namespace Microsoft.Teams.Bot.Apps.Handlers;
8
9/// <summary>
10/// Delegate for handling message delete activities.
11/// </summary>
12/// <param name="context"></param>
13/// <param name="cancellationToken"></param>
14/// <returns></returns>
15public delegate Task MessageDeleteHandler(Context<MessageDeleteActivity> context, CancellationToken cancellationToken = default);
16
17/// <summary>
18/// Extension methods for registering message delete activity handlers.
19/// </summary>
20public static class MessageDeleteExtensions
21{
22 /// <summary>
23 /// Registers a handler for message delete activities.
24 /// </summary>
25 /// <remarks>
26 /// Breaking change: previously only the first matching handler was invoked. All matching handlers are now invoked sequentially.
27 /// </remarks>
28 /// <param name="app"></param>
29 /// <param name="handler"></param>
30 /// <returns></returns>
31 public static TeamsBotApplication OnMessageDelete(this TeamsBotApplication app, MessageDeleteHandler handler)
32 {
33 ArgumentNullException.ThrowIfNull(app, nameof(app));
34 app.Router.Register(new Route<MessageDeleteActivity>
35 {
36 Name = TeamsActivityType.MessageDelete,
37 Selector = _ => true,
38 Handler = async (ctx, cancellationToken) =>
39 {
40 await handler(ctx, cancellationToken).ConfigureAwait(false);
41 }
42 });
43
44 return app;
45 }
46}
47