8000 Invoke with expected replies by axelsrz · Pull Request #1427 · microsoft/botbuilder-python · GitHub
[go: up one dir, main page]

Skip to content

Invoke with expected replies #1427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8000
Merged
merged 1 commit into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions libraries/botbuilder-core/botbuilder/core/turn_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@


class TurnContext:

# Same constant as in the BF Adapter, duplicating here to avoid circular dependency
_INVOKE_RESPONSE_KEY = "BotFrameworkAdapter.InvokeResponse"

def __init__(self, adapter_or_context, request: Activity = None):
"""
Creates a new TurnContext instance.
Expand Down Expand Up @@ -202,6 +206,11 @@ async def logic():
responses = []
for activity in output:
self.buffered_reply_activities.append(activity)
# Ensure the TurnState has the InvokeResponseKey, since this activity
# is not being sent through the adapter, where it would be added to TurnState.
if activity.type == ActivityTypes.invoke_response:
self.turn_state[TurnContext._INVOKE_RESPONSE_KEY] = activity

responses.append(ResourceResponse())

if sent_non_trace_activity:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ async def _send_to_skill(
# Process replies in the response.Body.
response.body: List[Activity]
response.body = ExpectedReplies().deserialize(response.body).activities
# Track sent invoke responses, so more than one is not sent.
sent_invoke_response = False

for from_skill_activity in response.body:
if from_skill_activity.type == ActivityTypes.end_of_conversation:
Expand All @@ -254,12 +256,18 @@ async def _send_to_skill(
await self.dialog_options.conversation_id_factory.delete_conversation_reference(
skill_conversation_id
)
elif await self._intercept_oauth_cards(
elif not sent_invoke_response and await self._intercept_oauth_cards(
context, from_skill_activity, self.dialog_options.connection_name
):
# do nothing. Token exchange succeeded, so no oauthcard needs to be shown to the user
pass
# Token exchange succeeded, so no oauthcard needs to be shown to the user
sent_invoke_response = True
else:
# If an invoke response has already been sent we should ignore future invoke responses as this
# represents a bug in the skill.
if from_skill_activity.type == ActivityTypes.invoke_response:
if sent_invoke_response:
continue
sent_invoke_response = True
# Send the response back to the channel.
await context.send_activity(from_skill_activity)

Expand Down
0