microsoft/teams.net

Public

mirrored fromhttps://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
samples/migration-bot

Branches

Tags

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

Clone

HTTPS

Download ZIP

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

50lines · 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 file consent invoke activities.
11/// </summary>
12/// <param name="context">The context for the invoke activity, providing access to the activity data and bot application.</param>
13/// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param>
14/// <returns>A task that represents the asynchronous operation. The task result contains the invoke response.</returns>
15public delegate Task<InvokeResponse<AdaptiveCardResponse>> FileConsentValueHandler(Context<InvokeActivity<FileConsentValue>> context, CancellationToken cancellationToken = default);
16
17/// <summary>
18/// Extension methods for registering file consent invoke handlers.
19/// </summary>
20public static class FileConsentExtensions
21{
22
23 /// <summary>
24 /// Registers a handler for file consent invoke activities.
25 /// Cannot be combined with <see cref="InvokeExtensions.OnInvoke"/>.
26 /// </summary>
27 /// <remarks>
28 /// Breaking change: previously a catch-all invoke handler could be registered alongside specific invoke handlers. This combination now throws at registration time.
29 /// </remarks>
30 /// <param name="app">The Teams bot application.</param>
31 /// <param name="handler">The handler to register.</param>
32 /// <returns>The updated Teams bot application.</returns>
33 public static TeamsBotApplication OnFileConsent(this TeamsBotApplication app, FileConsentValueHandler handler)
34 {
35 ArgumentNullException.ThrowIfNull(app, nameof(app));
36 app.Router.Register(new Route<InvokeActivity>
37 {
38 Name = string.Join("/", TeamsActivityType.Invoke, InvokeNames.FileConsent),
39 Selector = activity => activity.Name == InvokeNames.FileConsent,
40 HandlerWithReturn = async (ctx, cancellationToken) =>
41 {
42 InvokeActivity<FileConsentValue> typedActivity = new(ctx.Activity);
43 Context<InvokeActivity<FileConsentValue>> typedContext = new(ctx.TeamsBotApplication, typedActivity);
44 return await handler(typedContext, cancellationToken).ConfigureAwait(false);
45 }
46 });
47
48 return app;
49 }
50}
51