TurnContext Class
Constructor
TurnContext()
Parameters
| Name | Description |
|---|---|
|
adapter_or_context
Required
|
|
|
request
|
Default value: None
|
|
identity
|
Default value: None
|
Methods
| __init__ |
Creates a new TurnContext instance. :param adapter_or_context: The adapter instance or an existing TurnContext. :param request: The incoming Activity. :param identity: The ClaimsIdentity associated with the request. |
| __new__ | |
| apply_conversation_reference |
Updates an activity with the delivery information from a conversation reference. Calling this after get_conversation_reference on an incoming activity will properly address the reply to a received activity. :param activity: :param reference: :param is_incoming: :return: |
| copy_to |
Called when this TurnContext instance is passed into the constructor of a new TurnContext instance. Can be overridden in derived classes. :param context: :return: |
| delete_activity |
Deletes an existing activity. :param id_or_reference: :return: |
| get_mentions |
Returns all the mentions in the activity. |
| get_reply_conversation_reference | |
| on_delete_activity |
Registers a handler to be notified of and potentially intercept an activity being deleted. :param handler: the handler to register :type handler: OnDeleteActivityHandler :return: |
| on_send_activities |
Registers a handler to be notified of and potentially intercept the sending of activities. :param handler: the handler to register :type handler: OnSendActivitiesHandler :return: |
| on_update_activity |
Registers a handler to be notified of and potentially intercept an activity being updated. :param handler: the handler to register :type handler: OnUpdateActivityHandler :return: |
| remove_mention_text |
Removes the mention text for the given account id from the activity's text. |
| remove_recipient_mention |
Removes the recipient's mention text from the activity's text. |
| send_activities | |
| send_activity |
Sends a single activity or message to the user. :param activity_or_text: :return: |
| send_trace_activity | |
| update_activity |
Replaces an existing activity. :param activity: :return: |
__init__
Creates a new TurnContext instance. :param adapter_or_context: The adapter instance or an existing TurnContext. :param request: The incoming Activity. :param identity: The ClaimsIdentity associated with the request.
__init__(adapter_or_context, request: Activity | None = None, identity: ClaimsIdentity | None = None)
Parameters
| Name | Description |
|---|---|
|
request
|
Default value: None
|
|
identity
|
Default value: None
|
|
adapter_or_context
Required
|
|
__new__
__new__(**kwargs)
apply_conversation_reference
Updates an activity with the delivery information from a conversation reference. Calling this after get_conversation_reference on an incoming activity will properly address the reply to a received activity. :param activity: :param reference: :param is_incoming: :return:
static apply_conversation_reference(activity: Activity, reference: ConversationReference, is_incoming: bool = False) -> Activity
Parameters
| Name | Description |
|---|---|
|
activity
Required
|
|
|
reference
Required
|
|
|
is_incoming
|
Default value: False
|
Returns
| Type | Description |
|---|---|
copy_to
Called when this TurnContext instance is passed into the constructor of a new TurnContext instance. Can be overridden in derived classes. :param context: :return:
copy_to(context: TurnContext) -> None
Parameters
| Name | Description |
|---|---|
|
context
Required
|
|
Returns
| Type | Description |
|---|---|
delete_activity
Deletes an existing activity. :param id_or_reference: :return:
async delete_activity(id_or_reference: str | ConversationReference)
Parameters
| Name | Description |
|---|---|
|
id_or_reference
Required
|
|
get_mentions
get_reply_conversation_reference
static get_reply_conversation_reference(activity: Activity, reply: ResourceResponse) -> ConversationReference
Parameters
| Name | Description |
|---|---|
|
activity
Required
|
|
|
reply
Required
|
|
Returns
| Type | Description |
|---|---|
on_delete_activity
Registers a handler to be notified of and potentially intercept an activity being deleted. :param handler: the handler to register :type handler: OnDeleteActivityHandler :return:
on_delete_activity(handler: Callable[[TurnContext, ConversationReference, Callable[[], Awaitable[None]]], Awaitable[None]]) -> TurnContext
Parameters
| Name | Description |
|---|---|
|
handler
Required
|
|
Returns
| Type | Description |
|---|---|
on_send_activities
Registers a handler to be notified of and potentially intercept the sending of activities. :param handler: the handler to register :type handler: OnSendActivitiesHandler :return:
on_send_activities(handler: Callable[[TurnContext, list[Activity], Callable[[], Awaitable[list[ResourceResponse]]]], Awaitable[list[ResourceResponse]]]) -> TurnContext
Parameters
| Name | Description |
|---|---|
|
handler
Required
|
Callable[[TurnContext, list[Activity], Callable[[], Awaitable[list[ResourceResponse]]]], Awaitable[list[ResourceResponse]]]
|
Returns
| Type | Description |
|---|---|
on_update_activity
Registers a handler to be notified of and potentially intercept an activity being updated. :param handler: the handler to register :type handler: OnUpdateActivityHandler :return:
on_update_activity(handler: Callable[[TurnContext, Activity, Callable[[], Awaitable[ResourceResponse]]], Awaitable[ResourceResponse]]) -> TurnContext
Parameters
| Name | Description |
|---|---|
|
handler
Required
|
Callable[[TurnContext, Activity, Callable[[], Awaitable[ResourceResponse]]], Awaitable[ResourceResponse]]
|
Returns
| Type | Description |
|---|---|
remove_mention_text
Removes the mention text for the given account id from the activity's text.
static remove_mention_text(activity: Activity, identifier: str) -> str
Parameters
| Name | Description |
|---|---|
|
activity
Required
|
The activity to remove the mention text from. |
|
identifier
Required
|
The id of the account whose mention text should be removed. |
Returns
| Type | Description |
|---|---|
|
The updated activity text. |
remove_recipient_mention
send_activities
async send_activities(activities: list[Activity]) -> list[ResourceResponse]
Parameters
| Name | Description |
|---|---|
|
activities
Required
|
|
Returns
| Type | Description |
|---|---|
send_activity
Sends a single activity or message to the user. :param activity_or_text: :return:
async send_activity(activity_or_text: Activity | str, speak: str | None = None, input_hint: str | None = None) -> ResourceResponse
Parameters
| Name | Description |
|---|---|
|
activity_or_text
Required
|
|
|
speak
|
Default value: None
|
|
input_hint
|
Default value: None
|
Returns
| Type | Description |
|---|---|
send_trace_activity
async send_trace_activity(name: str, value: object = None, value_type: str | None = None, label: str | None = None) -> ResourceResponse
Parameters
| Name | Description |
|---|---|
|
name
Required
|
|
|
value
|
Default value: None
|
|
value_type
|
Default value: None
|
|
label
|
Default value: None
|
Returns
| Type | Description |
|---|---|
update_activity
Replaces an existing activity. :param activity: :return:
async update_activity(activity: Activity)
Parameters
| Name | Description |
|---|---|
|
activity
Required
|
|
Attributes
activity
The received activity. :return:
identity
responded
If true at least one response has been sent for the current turn of conversation. :return:
services
Map of services and other values cached for the lifetime of the turn. :return:
streaming_response
Gets a StreamingResponse instance for this turn context. This allows for streaming partial responses to the client.
turn_state
adapter
adapter: ChannelAdapterProtocol