Skip to content

Commit

Permalink
Add Message extra for permanent URL
Browse files Browse the repository at this point in the history
Allow bots to easily refer to stream&topic that a message
was part of.

Closes zulip/errbot-backend-zulip#6
  • Loading branch information
zmlaimeew committed Apr 4, 2021
1 parent 7dd6d14 commit 48688b4
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions zulip.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from errbot.core import ErrBot
from errbot.rendering.ansiext import enable_format, TEXT_CHRS

from urllib.parse import quote

# Can't use __name__ because of Yapsy.
log = logging.getLogger('errbot.backends.zulip')
Expand Down Expand Up @@ -243,6 +244,14 @@ def _handle_message(self, message):
room=room
)
message_instance.to = room
message_instance.extras['url'] = (
'{site}/#narrow/stream/{stream}'
'/subject/{subject}/near/{mid}').format(
site=self.identity['site'],
stream=quote(room.title),
subject=quote(room.subject),
mid=message['id'],
)
else:
raise ValueError("Invalid message type `{}`.".format(message['type']))
self.callback_message(message_instance)
Expand Down

0 comments on commit 48688b4

Please sign in to comment.