Skip to content

Commit 0fb415f

Browse files
Virtual-JoshEric Dahlvang
authored andcommitted
Fixing mention stripping and tests (#488)
* updating turn context mention * updating tests based on new mention * black updates
1 parent c3d555d commit 0fb415f

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,11 @@ def remove_recipient_mention(activity: Activity) -> str:
359359
def remove_mention_text(activity: Activity, identifier: str) -> str:
360360
mentions = TurnContext.get_mentions(activity)
361361
for mention in mentions:
362-
if mention.mentioned.id == identifier:
362+
if mention.additional_properties["mentioned"]["id"] == identifier:
363363
mention_name_match = re.match(
364-
r"<at(.*)>(.*?)<\/at>", mention.text, re.IGNORECASE
364+
r"<at(.*)>(.*?)<\/at>",
365+
mention.additional_properties["text"],
366+
re.IGNORECASE,
365367
)
366368
if mention_name_match:
367369
activity.text = re.sub(

libraries/botbuilder-core/tests/test_inspection_middleware.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
)
1515
from botbuilder.core.adapters import TestAdapter
1616
from botbuilder.core.inspection import InspectionMiddleware, InspectionState
17-
from botbuilder.schema import Activity, ActivityTypes, ChannelAccount, Mention
17+
from botbuilder.schema import Activity, ActivityTypes, ChannelAccount, Entity, Mention
1818

1919

2020
class TestConversationState(aiounittest.AsyncTestCase):
@@ -249,10 +249,12 @@ async def exec_test2(turn_context):
249249
text=attach_command,
250250
recipient=ChannelAccount(id=recipient_id),
251251
entities=[
252-
Mention(
253-
type="mention",
254-
text=f"<at>{recipient_id}</at>",
255-
mentioned=ChannelAccount(name="Bot", id=recipient_id),
252+
Entity().deserialize(
253+
Mention(
254+
type="mention",
255+
text=f"<at>{recipient_id}</at>",
256+
mentioned=ChannelAccount(name="Bot", id=recipient_id),
257+
).serialize()
256258
)
257259
],
258260
)

libraries/botbuilder-core/tests/test_turn_context.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
ActivityTypes,
1010
ChannelAccount,
1111
ConversationAccount,
12+
Entity,
1213
Mention,
1314
ResourceResponse,
1415
)
@@ -309,10 +310,12 @@ def test_should_remove_at_mention_from_activity(self):
309310
text="<at>TestOAuth619</at> test activity",
310311
recipient=ChannelAccount(id="TestOAuth619"),
311312
entities=[
312-
Mention(
313-
type="mention",
314-
text="<at>TestOAuth619</at>",
315-
mentioned=ChannelAccount(name="Bot", id="TestOAuth619"),
313+
Entity().deserialize(
314+
Mention(
315+
type="mention",
316+
text="<at>TestOAuth619</at>",
317+
mentioned=ChannelAccount(name="Bot", id="TestOAuth619"),
318+
).serialize()
316319
)
317320
],
318321
)

0 commit comments

Comments
 (0)