Don't escape <>& in me messages
Apparently chat.meMessage requires these characters unescaped, even
though it interpret links using these characters. There doesn't seem to
be any options for changing this behavior, so we have to linkify
nicks/channels while also leaving <>& unescaped.
Fixes closes
@@ -1615,11 +1615,12 @@ class SlackChannelCommon(object):
self.print_getting_history()
def send_message(self, message, subtype=None, request_dict_ext={}):
- message = linkify_text(message, self.team)
if subtype == 'me_message':
+ message = linkify_text(message, self.team, escape_characters=False)
s = SlackRequest(self.team, "chat.meMessage", {"channel": self.identifier, "text": message}, channel=self)
self.eventrouter.receive(s)
else:
+ message = linkify_text(message, self.team)
request = {"type": "message", "channel": self.identifier,
"text": message, "user": self.team.myidentifier}
request.update(request_dict_ext)
@@ -3643,13 +3644,14 @@ def render_formatting(text):
return text
-def linkify_text(message, team, only_users=False):
+def linkify_text(message, team, only_users=False, escape_characters=True):
# The get_username_map function is a bit heavy, but this whole
# function is only called on message send..
usernames = team.get_username_map()
channels = team.get_channel_map()
usergroups = team.generate_usergroup_map()
- message_escaped = (message
+ if escape_characters:
+ message = (message
# Replace IRC formatting chars with Slack formatting chars.
.replace('\x02', '*')
.replace('\x1D', '_')
@@ -3677,7 +3679,7 @@ def linkify_text(message, team, only_users=False):
return word
linkify_regex = r'(?:^|(?<=\s))([@#])([\w\(\)\'.-]+)'
- return re.sub(linkify_regex, linkify_word, message_escaped, flags=re.UNICODE)
+ return re.sub(linkify_regex, linkify_word, message, flags=re.UNICODE)
def unfurl_blocks(blocks):
