Skip to content

Commit

Permalink
GH#1737 Retain '@' when replacing usernames (#1985)
Browse files Browse the repository at this point in the history
* GH#1737 Retain '@' when replacing usernames

See issue #1737 for context.

Currently it's not possible from the skill code to distinguish between
`@botname message` and `botname message`. With this change, username mentions
retain the `@` character.

* Fix test

---------

Co-authored-by: Jacob Tomlinson <jacob@tomlinson.email>
  • Loading branch information
cosimo and jacobtomlinson committed Apr 25, 2024
1 parent e69b463 commit b1d41ac
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion opsdroid/connector/slack/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@ async def replace_usernames(self, message):
for userid in userids:
user_info = await self.lookup_username(userid)
message = message.replace(
"<@{userid}>".format(userid=userid), user_info["name"]
"<@{userid}>".format(userid=userid),
"@{username}".format(username=user_info["name"]),
)

return message
Expand Down
2 changes: 1 addition & 1 deletion opsdroid/connector/slack/tests/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ async def test_replace_usernames(connector):
connector.known_users = {"U01NK1K9L68": {"name": "Test User"}}
message = "hello <@U01NK1K9L68>"
replaced_message = await connector.replace_usernames(message)
assert replaced_message == "hello Test User"
assert replaced_message == "hello @Test User"


@pytest.mark.anyio
Expand Down

0 comments on commit b1d41ac

Please sign in to comment.