microsoft/teams.net
Publicmirrored from https://github.com/microsoft/teams.netAvailable
core/src/Microsoft.Bot.Core.Compat/CompatBotAdapter.cs
80lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | using Microsoft.Bot.Builder; |
| 5 | using Microsoft.Bot.Core.Schema; |
| 6 | using Microsoft.Bot.Schema; |
| 7 | using Microsoft.Extensions.Logging; |
| 8 | |
| 9 | |
| 10 | namespace Microsoft.Bot.Core.Compat; |
| 11 | |
| 12 | /// <summary> |
| 13 | /// Provides a Bot Framework adapter that enables compatibility between the Bot Framework SDK and a custom bot |
| 14 | /// application implementation. |
| 15 | /// </summary> |
| 16 | /// <remarks>Use this adapter to bridge Bot Framework turn contexts and activities with a custom bot application. |
| 17 | /// This class is intended for scenarios where integration with non-standard bot runtimes or legacy systems is |
| 18 | /// required.</remarks> |
| 19 | /// <param name="botApplication">The bot application instance used to process and send activities within the adapter.</param> |
| 20 | /// <param name="logger">The <paramref name="logger"/></param> |
| 21 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1848:Use the LoggerMessage delegates", Justification = "<Pending>")] |
| 22 | public class CompatBotAdapter(BotApplication botApplication, ILogger<CompatBotAdapter> logger = default!) : BotAdapter |
| 23 | { |
| 24 | /// <summary> |
| 25 | /// Deletes an activity from the conversation. |
| 26 | /// </summary> |
| 27 | /// <param name="turnContext"></param> |
| 28 | /// <param name="reference"></param> |
| 29 | /// <param name="cancellationToken"></param> |
| 30 | /// <returns></returns> |
| 31 | /// <exception cref="NotImplementedException"></exception> |
| 32 | public override Task DeleteActivityAsync(ITurnContext turnContext, ConversationReference reference, CancellationToken cancellationToken) |
| 33 | { |
| 34 | throw new NotImplementedException(); |
| 35 | } |
| 36 | |
| 37 | /// <summary> |
| 38 | /// Sends a set of activities to the conversation. |
| 39 | /// </summary> |
| 40 | /// <param name="turnContext"></param> |
| 41 | /// <param name="activities"></param> |
| 42 | /// <param name="cancellationToken"></param> |
| 43 | /// <returns></returns> |
| 44 | public override async Task<Microsoft.Bot.Schema.ResourceResponse[]> SendActivitiesAsync(ITurnContext turnContext, Activity[] activities, CancellationToken cancellationToken) |
| 45 | { |
| 46 | ArgumentNullException.ThrowIfNull(activities); |
| 47 | |
| 48 | Microsoft.Bot.Schema.ResourceResponse[] responses = new Microsoft.Bot.Schema.ResourceResponse[1]; |
| 49 | for (int i = 0; i < activities.Length; i++) |
| 50 | { |
| 51 | CoreActivity a = activities[i].FromCompatActivity(); |
| 52 | |
| 53 | ResourceResponse? resp = await botApplication.SendActivityAsync(a, cancellationToken).ConfigureAwait(false); |
| 54 | if (resp is not null) |
| 55 | { |
| 56 | responses[i] = new Microsoft.Bot.Schema.ResourceResponse() { Id = resp.Id }; |
| 57 | } |
| 58 | else |
| 59 | { |
| 60 | logger.LogWarning("Found null ResourceResponse after calling SendActivityAsync"); |
| 61 | } |
| 62 | } |
| 63 | return responses; |
| 64 | } |
| 65 | |
| 66 | /// <summary> |
| 67 | /// Updates an existing activity in the conversation. |
| 68 | /// </summary> |
| 69 | /// <param name="turnContext"></param> |
| 70 | /// <param name="activity"></param> |
| 71 | /// <param name="cancellationToken"></param> |
| 72 | /// <returns></returns> |
| 73 | /// <exception cref="NotImplementedException"></exception> |
| 74 | public override Task<Microsoft.Bot.Schema.ResourceResponse> UpdateActivityAsync(ITurnContext turnContext, Activity activity, CancellationToken cancellationToken) |
| 75 | { |
| 76 | throw new NotImplementedException(); |
| 77 | } |
| 78 | |
| 79 | |
| 80 | } |
| 81 | |