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.DevTools/DevToolsConversationClient.cs

46lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4using Microsoft.Extensions.Logging;
5using Microsoft.Teams.Bot.Core;
6using Microsoft.Teams.Bot.Core.Schema;
7
8namespace Microsoft.Teams.Bot.DevTools;
9
10using CustomHeaders = Dictionary<string, string>;
11
12/// <summary>
13/// Decorator around <see cref="ConversationClient"/> that emits "sent" events to DevTools UI clients
14/// whenever an activity is sent.
15/// </summary>
16public class DevToolsConversationClient : ConversationClient
17{
18 private readonly DevToolsService _service;
19
20 /// <summary>
21 /// Creates a new DevToolsConversationClient.
22 /// </summary>
23 /// <param name="httpClient">The HTTP client for sending activities.</param>
24 /// <param name="logger">The logger.</param>
25 /// <param name="service">The shared DevTools service for emitting events.</param>
26 public DevToolsConversationClient(HttpClient httpClient, ILogger<ConversationClient> logger, DevToolsService service)
27 : base(httpClient, logger)
28 {
29 _service = service;
30 }
31
32 /// <inheritdoc/>
33 public override async Task<SendActivityResponse> SendActivityAsync(CoreActivity activity, CustomHeaders? customHeaders = null, CancellationToken cancellationToken = default)
34 {
35 ArgumentNullException.ThrowIfNull(activity);
36 var response = await base.SendActivityAsync(activity, customHeaders, cancellationToken).ConfigureAwait(false);
37
38 // Ensure activity has an ID so the DevTools UI can distinguish messages
39 activity.Id ??= response.Id ?? Guid.NewGuid().ToString();
40
41 // Emit sent event after successful send
42 await _service.EmitSent(activity, cancellationToken).ConfigureAwait(false);
43
44 return response;
45 }
46}
47