microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
Libraries/Microsoft.Teams.Apps/Plugins/Streamer.cs
72lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | using Microsoft.Teams.Api.Activities; |
| 5 | |
| 6 | namespace Microsoft.Teams.Apps.Plugins; |
| 7 | |
| 8 | /// <summary> |
| 9 | /// component that can send streamed chunks of an activity |
| 10 | /// </summary> |
| 11 | public interface IStreamer |
| 12 | { |
| 13 | /// <summary> |
| 14 | /// whether the final stream |
| 15 | /// message has been sent |
| 16 | /// </summary> |
| 17 | public bool Closed { get; } |
| 18 | |
| 19 | /// <summary> |
| 20 | /// the total number of chunks queued to be sent |
| 21 | /// </summary> |
| 22 | public int Count { get; } |
| 23 | |
| 24 | /// <summary> |
| 25 | /// the sequence number, representing the |
| 26 | /// number of stream activities sent |
| 27 | /// </summary> |
| 28 | /// <remarks> |
| 29 | /// several chunks can be aggregated into one |
| 30 | /// stream activity due to differences in Api rate limits |
| 31 | /// </remarks> |
| 32 | public int Sequence { get; } |
| 33 | |
| 34 | /// <summary> |
| 35 | /// event emitted on each chunk send |
| 36 | /// </summary> |
| 37 | public event OnChunkHandler OnChunk; |
| 38 | |
| 39 | /// <summary> |
| 40 | /// emit an activity |
| 41 | /// </summary> |
| 42 | /// <param name="activity">the activity</param> |
| 43 | public void Emit(MessageActivity activity); |
| 44 | |
| 45 | /// <summary> |
| 46 | /// emit an activity |
| 47 | /// </summary> |
| 48 | /// <param name="activity">the activity</param> |
| 49 | public void Emit(TypingActivity activity); |
| 50 | |
| 51 | /// <summary> |
| 52 | /// emit text chunk |
| 53 | /// </summary> |
| 54 | /// <param name="text">the text</param> |
| 55 | public void Emit(string text); |
| 56 | |
| 57 | /// <summary> |
| 58 | /// send status updates before emitting (ex. "Thinking...") |
| 59 | /// </summary> |
| 60 | /// <param name="text">the text</param> |
| 61 | public void Update(string text); |
| 62 | |
| 63 | /// <summary> |
| 64 | /// close the stream |
| 65 | /// </summary> |
| 66 | public Task<MessageActivity?> Close(); |
| 67 | |
| 68 | /// <summary> |
| 69 | /// handler called on each chunk send |
| 70 | /// </summary> |
| 71 | public delegate void OnChunkHandler(IActivity activity); |
| 72 | } |