microsoft/teams.net

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
core/integration-test-au

Branches

Tags

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

Clone

HTTPS

Download ZIP

Libraries/Microsoft.Teams.Apps/AppEvents.cs

61lines · 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().ConfigureAwait(false);
26 Logger.Error(content);
27 }
28 }
29
30 foreach (var plugin in Plugins.Where(p => !ReferenceEquals(sender, p)))
31 {
32 await plugin.OnError(this, sender, @event, cancellationToken).ConfigureAwait(false);
33 }
34 }
35
36 protected Task<Response> OnActivityEvent(ISenderPlugin sender, ActivityEvent @event, CancellationToken cancellationToken = default)
37 {
38 Logger.Debug(EventType.Activity);
39 return Process(sender, @event, cancellationToken);
40 }
41
42 protected async Task OnActivitySentEvent(ISenderPlugin sender, ActivitySentEvent @event, CancellationToken cancellationToken = default)
43 {
44 Logger.Debug(EventType.ActivitySent);
45
46 foreach (var plugin in Plugins.Where(p => !ReferenceEquals(sender, p)))
47 {
48 await plugin.OnActivitySent(this, sender, @event, cancellationToken).ConfigureAwait(false);
49 }
50 }
51
52 protected async Task OnActivityResponseEvent(ISenderPlugin sender, ActivityResponseEvent @event, CancellationToken cancellationToken = default)
53 {
54 Logger.Debug(EventType.ActivityResponse);
55
56 foreach (var plugin in Plugins.Where(p => !ReferenceEquals(sender, p)))
57 {
58 await plugin.OnActivityResponse(this, sender, @event, cancellationToken).ConfigureAwait(false);
59 }
60 }
61}
62