8000 Invoke with expected replies (#1427) · microsoft/botbuilder-python@6919340 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6919340

Browse files
committed
Invoke with expected replies (#1427)
1 parent c491636 commit 6919340

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

libraries/botbuilder-core/botbuilder/core/turn_context.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919

2020
class TurnContext:
21+
22+
# Same constant as in the BF Adapter, duplicating here to avoid circular dependency
23+
_INVOKE_RESPONSE_KEY = "BotFrameworkAdapter.InvokeResponse"
24+
2125
def __init__(self, adapter_or_context, request: Activity = None):
2226
"""
2327
Creates a new TurnContext instance.
@@ -202,6 +206,11 @@ async def logic():
202206
responses = []
203207
for activity in output:
204208
self.buffered_reply_activities.append(activity)
209+
# Ensure the TurnState has the InvokeResponseKey, since this activity
210+
# is not being sent through the adapter, where it would be added to TurnState.
211+
if activity.type == ActivityTypes.invoke_response:
212+
self.turn_state[TurnContext._INVOKE_RESPONSE_KEY] = activity
213+
205214
responses.append(ResourceResponse())
206215

207216
if sent_non_trace_activity:

libraries/botbuilder-dialogs/botbuilder/dialogs/skills/skill_dialog.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ async def _send_to_skill(
244244
# Process replies in the response.Body.
245245
response.body: List[Activity]
246246
response.body = ExpectedReplies().deserialize(response.body).activities
247+
# Track sent invoke responses, so more than one is not sent.
248+
sent_invoke_response = False
247249

248250
for from_skill_activity in response.body:
249251
if from_skill_activity.type == ActivityTypes.end_of_conversation:
@@ -254,12 +256,18 @@ async def _send_to_skill(
254256
await self.dialog_options.conversation_id_factory.delete_conversation_reference(
255257
skill_conversation_id
256258
)
257-
elif await self._intercept_oauth_cards(
259+
elif not sent_invoke_response and await self._intercept_oauth_cards(
258260
context, from_skill_activity, self.dialog_options.connection_name
259261
):
260-
# do nothing. Token exchange succeeded, so no oauthcard needs to be shown to the user
261-
pass
262+
# Token exchange succeeded, so no oauthcard needs to be shown to the user
263+
sent_invoke_response = True
262264
else:
265+
# If an invoke response has already been sent we should ignore future invoke responses as this
266+
# represents a bug in the skill.
267+
if from_skill_activity.type == ActivityTypes.invoke_response:
268+
if sent_invoke_response:
269+
continue
270+
sent_invoke_response = True
263271
# Send the response back to the channel.
264272
await context.send_activity(from_skill_activity)
265273

0 commit comments

Comments
 (0)
0