bots: Support adding reactions to message for a bot.
It adds a react() function that allows a bot to react to a message in lib.py.
It adds an example of the use of react() function and its test.
The changes are in the following files:
- lib.py
- helloworld.py
- tests/test_lib.py
- test_lib.py
MODIFY
zulip_bots/zulip_bots/bots/helloworld/helloworld.py
zulip_bots/zulip_bots/bots/helloworld/helloworld.py
@@ -16,4 +16,8 @@ class HelloWorldHandler:
content = 'beep boop' # type: str
bot_handler.send_reply(message, content)
+ emoji_name = 'wave' # type: str
+ bot_handler.react(message, emoji_name)
+ return
+
handler_class = HelloWorldHandler

MODIFY
zulip_bots/zulip_bots/lib.py
zulip_bots/zulip_bots/lib.py
@@ -153,6 +153,11 @@ class ExternalBotHandler:
def identity(self) -> BotIdentity:
return BotIdentity(self.full_name, self.email)
+ def react(self, message: Dict[str, Any], emoji_name: str) -> Dict[str, Any]:
+ return self._client.add_reaction(dict(message_id=message['id'],
+ emoji_name=emoji_name,
+ reaction_type='unicode_emoji'))
+
def send_message(self, message: (Dict[str, Any])) -> Dict[str, Any]:
if not self._rate_limit.is_legal():
self._rate_limit.show_error_and_exit()

MODIFY
zulip_bots/zulip_bots/simple_lib.py
zulip_bots/zulip_bots/simple_lib.py
@@ -30,6 +30,9 @@ class SimpleMessageServer:
self.messages[self.message_id] = message
return message
+ def add_reaction(self, reaction_data):
+ return dict(result='success', msg='', uri='https://server/messages/{}/reactions'.format(uuid4()))
+
def update(self, message):
self.messages[message['message_id']] = message

MODIFY
zulip_bots/zulip_bots/test_lib.py
zulip_bots/zulip_bots/test_lib.py
@@ -50,6 +50,9 @@ class StubBotHandler:
self.transcript.append(('send_reply', response_message))
return self.message_server.send(response_message)
+ def react(self, message: Dict[str, Any], emoji_name: str) -> Dict[str, Any]:
+ return self.message_server.add_reaction(emoji_name)
+
def update_message(self, message: Dict[str, Any]) -> None:
self.message_server.update(message)

MODIFY
zulip_bots/zulip_bots/tests/test_lib.py
zulip_bots/zulip_bots/tests/test_lib.py
@@ -109,6 +109,21 @@ class LibTest(TestCase):
client.get_storage.assert_not_called()
self.assertEqual(val, [5])
+ def test_react(self):
+ client = FakeClient()
+ handler = ExternalBotHandler(
+ client = client,
+ root_dir=None,
+ bot_details=None,
+ bot_config_file=None
+ )
+ emoji_name = 'wave'
+ message = {'id': 10}
+ expected = {'message_id': message['id'], 'emoji_name': 'wave', 'reaction_type': 'unicode_emoji'}
+ client.add_reaction = MagicMock()
+ handler.react(message, emoji_name)
+ client.add_reaction.assert_called_once_with(dict(expected))
+
def test_send_reply(self):
client = FakeClient()
profile = client.get_profile()

bots: Support adding reactions to message for a bot.

It adds a react() function that allows a bot to react to a message in lib.py.
It adds an example of the use of react() function and its test.

The changes are in the following files:
  - lib.py
  - helloworld.py
  - tests/test_lib.py
  - test_lib.py