terminal: Extract message server from the handler.
This makes the user and the bot to share the message server when
sending messages. As a result, the message id can be shared. And history
messages sent by the user will be stored as well.
MODIFY
zulip_bots/zulip_bots/simple_lib.py
zulip_bots/zulip_bots/simple_lib.py
@@ -40,10 +40,10 @@ class SimpleMessageServer:
return dict(result='success', msg='', uri='https://server/user_uploads/{}'.format(uuid4()))
class TerminalBotHandler:
- def __init__(self, bot_config_file):
+ def __init__(self, bot_config_file, message_server):
self.bot_config_file = bot_config_file
self._storage = SimpleStorage()
- self.message_server = SimpleMessageServer()
+ self.message_server = message_server
@property
def storage(self):

MODIFY
zulip_bots/zulip_bots/terminal.py
zulip_bots/zulip_bots/terminal.py
@@ -4,7 +4,7 @@ import sys
import argparse
from zulip_bots.finder import import_module_from_source, resolve_bot_path
-from zulip_bots.simple_lib import TerminalBotHandler
+from zulip_bots.simple_lib import SimpleMessageServer, TerminalBotHandler
current_dir = os.path.dirname(os.path.abspath(__file__))
@@ -49,7 +49,8 @@ def main():
print("This module does not appear to have a bot handler_class specified.")
sys.exit(1)
- bot_handler = TerminalBotHandler(args.bot_config_file)
+ message_server = SimpleMessageServer()
+ bot_handler = TerminalBotHandler(args.bot_config_file, message_server)
if hasattr(message_handler, 'initialize') and callable(message_handler.initialize):
message_handler.initialize(bot_handler)
@@ -59,11 +60,12 @@ def main():
while True:
content = input('Enter your message: ')
- message = dict(
+ message = message_server.send(dict(
content=content,
sender_email=sender_email,
display_recipient=sender_email,
- )
+ ))
+
message_handler.handle_message(
message=message,
bot_handler=bot_handler,

terminal: Extract message server from the handler.

This makes the user and the bot to share the message server when
sending messages. As a result, the message id can be shared. And history
messages sent by the user will be stored as well.