StreamingResponse class
A helper class for streaming responses to the client.
Remarks
This class is used to send a series of updates to the client in a single response. The expected sequence of calls is:
sendInformativeUpdate()
, sendTextChunk()
, sendTextChunk()
, ..., endStream()
.
Once endStream()
is called, the stream is considered ended and no further updates can be sent.
Constructors
Streaming |
Creates a new StreamingResponse instance. |
Properties
stream |
Gets the stream ID of the current response. |
updates |
Gets the number of updates sent for the stream. |
Methods
end |
Ends the stream by sending the final message to the client. |
get |
Returns the most recently streamed message. |
queue |
Queues an informative update to be sent to the client. |
queue |
Queues a chunk of partial message text to be sent to the client. |
set |
Sets the attachments to attach to the final chunk. |
wait |
Waits for the outgoing activity queue to be empty. |
Constructor Details
StreamingResponse(TurnContext)
Creates a new StreamingResponse instance.
new StreamingResponse(context: TurnContext)
Parameters
- context
-
TurnContext
Context for the current turn of conversation with the user.
Property Details
streamId
Gets the stream ID of the current response.
undefined | string streamId
Property Value
undefined | string
- The stream ID of the current response.
updatesSent
Gets the number of updates sent for the stream.
number updatesSent
Property Value
number
- The number of updates sent for the stream.
Method Details
endStream()
Ends the stream by sending the final message to the client.
function endStream(): Promise<void>
Returns
Promise<void>
- A promise representing the async operation
getMessage()
Returns the most recently streamed message.
function getMessage(): string
Returns
string
The streamed message.
queueInformativeUpdate(string)
Queues an informative update to be sent to the client.
function queueInformativeUpdate(text: string)
Parameters
- text
-
string
Text of the update to send.
queueTextChunk(string)
Queues a chunk of partial message text to be sent to the client.
function queueTextChunk(text: string)
Parameters
- text
-
string
Partial text of the message to send.
Remarks
The text we be sent as quickly as possible to the client. Chunks may be combined before delivery to the client.
setAttachments(Attachment[])
Sets the attachments to attach to the final chunk.
function setAttachments(attachments: Attachment[])
Parameters
- attachments
-
Attachment[]
List of attachments.
waitForQueue()
Waits for the outgoing activity queue to be empty.
function waitForQueue(): Promise<void>
Returns
Promise<void>
- A promise representing the async operation.