microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
Libraries/Microsoft.Teams.Api/Clients/ConversationClient.cs
91lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | using System.Text.Json.Serialization; |
| 5 | |
| 6 | using Microsoft.Teams.Api.Activities; |
| 7 | using Microsoft.Teams.Common.Http; |
| 8 | |
| 9 | namespace Microsoft.Teams.Api.Clients; |
| 10 | |
| 11 | public class ConversationClient : Client |
| 12 | { |
| 13 | public readonly string ServiceUrl; |
| 14 | public readonly ActivityClient Activities; |
| 15 | public readonly MemberClient Members; |
| 16 | public readonly ReactionClient Reactions; |
| 17 | |
| 18 | public ConversationClient(string serviceUrl, CancellationToken cancellationToken = default) : base(cancellationToken) |
| 19 | { |
| 20 | ServiceUrl = serviceUrl; |
| 21 | Activities = new ActivityClient(serviceUrl, _http, cancellationToken); |
| 22 | Members = new MemberClient(serviceUrl, _http, cancellationToken); |
| 23 | Reactions = new ReactionClient(serviceUrl, _http, cancellationToken); |
| 24 | } |
| 25 | |
| 26 | public ConversationClient(string serviceUrl, IHttpClient client, CancellationToken cancellationToken = default) : base(client, cancellationToken) |
| 27 | { |
| 28 | ServiceUrl = serviceUrl; |
| 29 | Activities = new ActivityClient(serviceUrl, _http, cancellationToken); |
| 30 | Members = new MemberClient(serviceUrl, _http, cancellationToken); |
| 31 | Reactions = new ReactionClient(serviceUrl, _http, cancellationToken); |
| 32 | } |
| 33 | |
| 34 | public ConversationClient(string serviceUrl, IHttpClientOptions options, CancellationToken cancellationToken = default) : base(options, cancellationToken) |
| 35 | { |
| 36 | ServiceUrl = serviceUrl; |
| 37 | Activities = new ActivityClient(serviceUrl, _http, cancellationToken); |
| 38 | Members = new MemberClient(serviceUrl, _http, cancellationToken); |
| 39 | Reactions = new ReactionClient(serviceUrl, _http, cancellationToken); |
| 40 | } |
| 41 | |
| 42 | public ConversationClient(string serviceUrl, IHttpClientFactory factory, CancellationToken cancellationToken = default) : base(factory, cancellationToken) |
| 43 | { |
| 44 | ServiceUrl = serviceUrl; |
| 45 | Activities = new ActivityClient(serviceUrl, _http, cancellationToken); |
| 46 | Members = new MemberClient(serviceUrl, _http, cancellationToken); |
| 47 | Reactions = new ReactionClient(serviceUrl, _http, cancellationToken); |
| 48 | } |
| 49 | |
| 50 | public async Task<ConversationResource> CreateAsync(CreateRequest request, CancellationToken cancellationToken = default) |
| 51 | { |
| 52 | var token = cancellationToken != default ? cancellationToken : _cancellationToken; |
| 53 | var req = HttpRequest.Post($"{ServiceUrl}v3/conversations", body: request); |
| 54 | var res = await _http.SendAsync<ConversationResource>(req, token).ConfigureAwait(false); |
| 55 | return res.Body; |
| 56 | } |
| 57 | |
| 58 | public class CreateRequest |
| 59 | { |
| 60 | [JsonPropertyName("isGroup")] |
| 61 | [JsonPropertyOrder(0)] |
| 62 | [Obsolete("This will be removed by end of summer 2026.")] |
| 63 | public bool? IsGroup { get; set; } |
| 64 | |
| 65 | [JsonPropertyName("bot")] |
| 66 | [JsonPropertyOrder(1)] |
| 67 | [Obsolete("This will be removed by end of summer 2026.")] |
| 68 | public Account? Bot { get; set; } |
| 69 | |
| 70 | [JsonPropertyName("members")] |
| 71 | [JsonPropertyOrder(2)] |
| 72 | public IList<Account>? Members { get; set; } |
| 73 | |
| 74 | [JsonPropertyName("topicName")] |
| 75 | [JsonPropertyOrder(3)] |
| 76 | [Obsolete("This will be removed by end of summer 2026.")] |
| 77 | public string? TopicName { get; set; } |
| 78 | |
| 79 | [JsonPropertyName("tenantId")] |
| 80 | [JsonPropertyOrder(4)] |
| 81 | public string? TenantId { get; set; } |
| 82 | |
| 83 | [JsonPropertyName("activity")] |
| 84 | [JsonPropertyOrder(5)] |
| 85 | public IActivity? Activity { get; set; } |
| 86 | |
| 87 | [JsonPropertyName("channelData")] |
| 88 | [JsonPropertyOrder(6)] |
| 89 | public IDictionary<string, object>? ChannelData { get; set; } |
| 90 | } |
| 91 | } |