Skip to content
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

MentionRemoved fix #2216

Merged
merged 2 commits into from
Mar 21, 2025
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
6 changes: 5 additions & 1 deletion libraries/botbuilder-core/botbuilder/core/turn_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,13 @@ def remove_mention_text(activity: Activity, identifier: str) -> str:
mentions = TurnContext.get_mentions(activity)
for mention in mentions:
if mention.additional_properties["mentioned"]["id"] == identifier:
replace_text = (
mention.additional_properties.get("text")
or mention.additional_properties.get("mentioned")["name"]
)
mention_name_match = re.match(
r"<at(.*)>(.*?)<\/at>",
escape(mention.additional_properties["text"]),
escape(replace_text),
re.IGNORECASE,
)
if mention_name_match:
Expand Down
42 changes: 42 additions & 0 deletions libraries/botbuilder-core/tests/test_turn_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,48 @@ def test_should_remove_at_mention_with_regex_characters(self):
assert text == " test activity"
assert activity.text == " test activity"

def test_should_remove_custom_mention_from_activity(self):
activity = Activity(
text="Hallo",
text_format="plain",
type="message",
timestamp="2025-03-11T14:16:47.0093935Z",
id="1741702606984",
channel_id="msteams",
service_url="https://smba.trafficmanager.net/emea/REDACTED/",
from_property=ChannelAccount(
id="29:1J-K4xVh-sLpdwQ-R5GkOZ_TB0W3ec_37p710aH8qe8bITA0zxdgIGc9l-MdDdkdE_jasSfNOeWXyyL1nsrHtBQ",
name="",
aad_object_id="REDACTED",
),
conversation=ConversationAccount(
is_group=True,
conversation_type="groupChat",
tenant_id="REDACTED",
id="19:[email protected]",
),
recipient=ChannelAccount(
id="28:c5d5fb56-a1a4-4467-a7a3-1b37905498a0", name="Azure AI Agent"
),
entities=[
Entity().deserialize(
Mention(
type="mention",
mentioned=ChannelAccount(
id="28:c5d5fb56-a1a4-4467-a7a3-1b37905498a0",
name="Custom Agent",
),
).serialize()
)
],
channel_data={"tenant": {"id": "REDACTED"}, "productContext": "COPILOT"},
)

text = TurnContext.remove_mention_text(activity, activity.recipient.id)

assert text == "Hallo"
assert activity.text == "Hallo"

async def test_should_send_a_trace_activity(self):
context = TurnContext(SimpleAdapter(), ACTIVITY)
called = False
Expand Down