Skip to content

Commit d247303

Browse files
Kyle Delaneyaxelsrz
Kyle Delaney
authored andcommitted
Apply conversation reference in TurnContext.update_activity (#358)
* Create test_update_activity_should_apply_conversation_reference * Apply conversation reference in TurnContext.update_activity
1 parent 37c361d commit d247303

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,11 @@ async def update_activity(self, activity: Activity):
173173
:param activity:
174174
:return:
175175
"""
176+
reference = TurnContext.get_conversation_reference(self.activity)
177+
176178
return await self._emit(
177179
self._on_update_activity,
178-
activity,
180+
TurnContext.apply_conversation_reference(activity, reference),
179181
self.adapter.update_activity(self, activity),
180182
)
181183

@@ -240,7 +242,7 @@ async def next_handler():
240242
raise error
241243

242244
await emit_next(0)
243-
# This should be changed to `return await logic()`
245+
# logic does not use parentheses because it's a coroutine
244246
return await logic
245247

246248
@staticmethod

libraries/botbuilder-core/tests/test_turn_context.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Mention,
1111
ResourceResponse,
1212
)
13-
from botbuilder.core import BotAdapter, TurnContext
13+
from botbuilder.core import BotAdapter, MessageFactory, TurnContext
1414

1515
ACTIVITY = Activity(
1616
id="1234",
@@ -40,11 +40,12 @@ async def send_activities(self, context, activities):
4040
async def update_activity(self, context, activity):
4141
assert context is not None
4242
assert activity is not None
43+
return ResourceResponse(id=activity.id)
4344

4445
async def delete_activity(self, context, reference):
4546
assert context is not None
4647
assert reference is not None
47-
assert reference.activity_id == "1234"
48+
assert reference.activity_id == ACTIVITY.id
4849

4950

5051
class TestBotContext(aiounittest.AsyncTestCase):
@@ -225,6 +226,26 @@ async def update_handler(context, activity, next_handler_coroutine):
225226
await context.update_activity(ACTIVITY)
226227
assert called is True
227228

229+
async def test_update_activity_should_apply_conversation_reference(self):
230+
activity_id = "activity ID"
231+
context = TurnContext(SimpleAdapter(), ACTIVITY)
232+
called = False
233+
234+
async def update_handler(context, activity, next_handler_coroutine):
235+
nonlocal called
236+
called = True
237+
assert context is not None
238+
assert activity.id == activity_id
239+
assert activity.conversation.id == ACTIVITY.conversation.id
240+
await next_handler_coroutine()
241+
242+
context.on_update_activity(update_handler)
243+
new_activity = MessageFactory.text("test text")
244+
new_activity.id = activity_id
245+
update_result = await context.update_activity(new_activity)
246+
assert called is True
247+
assert update_result.id == activity_id
248+
228249
def test_get_conversation_reference_should_return_valid_reference(self):
229250
reference = TurnContext.get_conversation_reference(ACTIVITY)
230251

0 commit comments

Comments
 (0)