microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
Libraries/Microsoft.Teams.Apps/AppEvents.cs
61lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | using Microsoft.Teams.Apps.Events; |
| 5 | using Microsoft.Teams.Apps.Plugins; |
| 6 | using Microsoft.Teams.Common.Http; |
| 7 | |
| 8 | namespace Microsoft.Teams.Apps; |
| 9 | |
| 10 | public 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.Where(p => !ReferenceEquals(sender, p))) |
| 31 | { |
| 32 | await plugin.OnError(this, sender, @event, cancellationToken); |
| 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); |
| 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); |
| 59 | } |
| 60 | } |
| 61 | } |