microsoft/teams.net

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v2.0.0-preview.13

Branches

Tags

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

Clone

HTTPS

Download ZIP

Libraries/Microsoft.Teams.Apps/AppEvents.cs

64lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License.
3
4using Microsoft.Teams.Apps.Events;
5using Microsoft.Teams.Apps.Plugins;
6using Microsoft.Teams.Common.Http;
7
8namespace Microsoft.Teams.Apps;
9
10public partial class App
11{
12 internal EventEmitter Events = new();
13
14 protected async Task OnErrorEvent(IPlugin sender, ErrorEvent @event, CancellationToken cancellationToken = default)
15 {
16 cancellationToken = @event.Context?.CancellationToken ?? cancellationToken;
17 Logger.Error(@event.Exception);
18
19 if (@event.Exception is HttpException ex)
20 {
21 Logger.Error(ex.Request?.RequestUri?.ToString());
22
23 if (ex.Request?.Content is not null)
24 {
25 var content = await ex.Request.Content.ReadAsStringAsync();
26 Logger.Error(content);
27 }
28 }
29
30 foreach (var plugin in Plugins)
31 {
32 if (sender.Equals(plugin)) continue;
33 await plugin.OnError(this, sender, @event, cancellationToken);
34 }
35 }
36
37 protected Task<Response> OnActivityEvent(ISenderPlugin sender, ActivityEvent @event, CancellationToken cancellationToken = default)
38 {
39 Logger.Debug(EventType.Activity);
40 return Process(sender, @event, cancellationToken);
41 }
42
43 protected async Task OnActivitySentEvent(ISenderPlugin sender, ActivitySentEvent @event, CancellationToken cancellationToken = default)
44 {
45 Logger.Debug(EventType.ActivitySent);
46
47 foreach (var plugin in Plugins)
48 {
49 if (sender.Equals(plugin)) continue;
50 await plugin.OnActivitySent(this, sender, @event, cancellationToken);
51 }
52 }
53
54 protected async Task OnActivityResponseEvent(ISenderPlugin sender, ActivityResponseEvent @event, CancellationToken cancellationToken = default)
55 {
56 Logger.Debug(EventType.ActivityResponse);
57
58 foreach (var plugin in Plugins)
59 {
60 if (sender.Equals(plugin)) continue;
61 await plugin.OnActivityResponse(this, sender, @event, cancellationToken);
62 }
63 }
64}