zulip_bots: Supply bots with 'full_content' of message.

This adds the 'full_message' field to the message dict
passed to bots.

Fixes #138.
This commit is contained in:
Robert Hönig 2017-12-25 19:14:38 +01:00 committed by showell
parent 79627002d6
commit c3348750d9
2 changed files with 4 additions and 2 deletions

View file

@ -280,12 +280,13 @@ def run_message_handler_for_bot(lib_module, quiet, config_file, bot_config_file,
def handle_message(message, flags): def handle_message(message, flags):
# type: (Dict[str, Any], List[str]) -> None # type: (Dict[str, Any], List[str]) -> None
logging.info('waiting for next message') logging.info('waiting for next message')
# `mentioned` will be in `flags` if the bot is mentioned at ANY position # `mentioned` will be in `flags` if the bot is mentioned at ANY position
# (not necessarily the first @mention in the message). # (not necessarily the first @mention in the message).
is_mentioned = 'mentioned' in flags is_mentioned = 'mentioned' in flags
is_private_message = is_private_message_from_another_user(message, restricted_client.user_id) 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 # Strip at-mention botname from the message
if is_mentioned: if is_mentioned:
# message['content'] will be None when the bot's @-mention is not at the beginning. # message['content'] will be None when the bot's @-mention is not at the beginning.

View file

@ -114,7 +114,8 @@ class LibTest(TestCase):
original_message = {'content': '@**Alice** bar', original_message = {'content': '@**Alice** bar',
'type': 'stream'} 'type': 'stream'}
expected_message = {'type': 'stream', expected_message = {'type': 'stream',
'content': 'bar'} 'content': 'bar',
'full_content': '@**Alice** bar'}
test_message(original_message, {'mentioned'}) test_message(original_message, {'mentioned'})
mock_bot_handler.handle_message.assert_called_with( mock_bot_handler.handle_message.assert_called_with(
message=expected_message, message=expected_message,