From c3348750d9684ad13797eaf70055616c6523b2e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20H=C3=B6nig?= Date: Mon, 25 Dec 2017 19:14:38 +0100 Subject: [PATCH] zulip_bots: Supply bots with 'full_content' of message. This adds the 'full_message' field to the message dict passed to bots. Fixes #138. --- zulip_bots/zulip_bots/lib.py | 3 ++- zulip_bots/zulip_bots/lib_tests.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/zulip_bots/zulip_bots/lib.py b/zulip_bots/zulip_bots/lib.py index 0aab3f7..243b1ab 100644 --- a/zulip_bots/zulip_bots/lib.py +++ b/zulip_bots/zulip_bots/lib.py @@ -280,12 +280,13 @@ def run_message_handler_for_bot(lib_module, quiet, config_file, bot_config_file, def handle_message(message, flags): # type: (Dict[str, Any], List[str]) -> None logging.info('waiting for next message') - # `mentioned` will be in `flags` if the bot is mentioned at ANY position # (not necessarily the first @mention in the message). is_mentioned = 'mentioned' in flags is_private_message = is_private_message_from_another_user(message, restricted_client.user_id) + # Provide bots with a way to access the full, unstripped message + message['full_content'] = message['content'] # Strip at-mention botname from the message if is_mentioned: # message['content'] will be None when the bot's @-mention is not at the beginning. diff --git a/zulip_bots/zulip_bots/lib_tests.py b/zulip_bots/zulip_bots/lib_tests.py index bcd09f2..a4dfdc6 100644 --- a/zulip_bots/zulip_bots/lib_tests.py +++ b/zulip_bots/zulip_bots/lib_tests.py @@ -114,7 +114,8 @@ class LibTest(TestCase): original_message = {'content': '@**Alice** bar', 'type': 'stream'} expected_message = {'type': 'stream', - 'content': 'bar'} + 'content': 'bar', + 'full_content': '@**Alice** bar'} test_message(original_message, {'mentioned'}) mock_bot_handler.handle_message.assert_called_with( message=expected_message,