diff --git a/zulip_bots/zulip_bots/lib.py b/zulip_bots/zulip_bots/lib.py index d91a846..482bf4d 100644 --- a/zulip_bots/zulip_bots/lib.py +++ b/zulip_bots/zulip_bots/lib.py @@ -142,12 +142,13 @@ class ExternalBotHandler(object): self._rate_limit.show_error_and_exit() return self._client.send_message(message) - def send_reply(self, message: Dict[str, Any], response: str) -> Dict[str, Any]: + def send_reply(self, message: Dict[str, Any], response: str, widget_content: Optional[str]=None) -> Dict[str, Any]: if message['type'] == 'private': return self.send_message(dict( type='private', to=[x['email'] for x in message['display_recipient'] if self.email != x['email']], content=response, + widget_content=widget_content, )) else: return self.send_message(dict( @@ -155,6 +156,7 @@ class ExternalBotHandler(object): to=message['display_recipient'], subject=message['subject'], content=response, + widget_content=widget_content, )) def update_message(self, message: Dict[str, Any]) -> Dict[str, Any]: diff --git a/zulip_bots/zulip_bots/test_lib.py b/zulip_bots/zulip_bots/test_lib.py index 1cedea4..4a3b190 100755 --- a/zulip_bots/zulip_bots/test_lib.py +++ b/zulip_bots/zulip_bots/test_lib.py @@ -1,6 +1,6 @@ import unittest -from typing import List, Dict, Any, Tuple +from typing import List, Dict, Any, Tuple, Optional from zulip_bots.custom_exceptions import ( ConfigValidationError, @@ -41,9 +41,11 @@ class StubBotHandler: self.transcript.append(('send_message', message)) return self.message_server.send(message) - def send_reply(self, message: Dict[str, Any], response: str) -> Dict[str, Any]: + def send_reply(self, message: Dict[str, Any], response: str, + widget_content: Optional[str]=None) -> Dict[str, Any]: response_message = dict( - content=response + content=response, + widget_content=widget_content ) self.transcript.append(('send_reply', response_message)) return self.message_server.send(response_message) diff --git a/zulip_bots/zulip_bots/tests/test_lib.py b/zulip_bots/zulip_bots/tests/test_lib.py index a974845..63ec939 100644 --- a/zulip_bots/zulip_bots/tests/test_lib.py +++ b/zulip_bots/zulip_bots/tests/test_lib.py @@ -110,16 +110,17 @@ class LibTest(TestCase): ) to = {'email': 'Some@User'} expected = [({'type': 'private', 'display_recipient': [to]}, - {'type': 'private', 'to': [to['email']]}), + {'type': 'private', 'to': [to['email']]}, None), ({'type': 'private', 'display_recipient': [to, profile]}, - {'type': 'private', 'to': [to['email']]}), + {'type': 'private', 'to': [to['email']]}, 'widget_content'), ({'type': 'stream', 'display_recipient': 'Stream name', 'subject': 'Topic'}, - {'type': 'stream', 'to': 'Stream name', 'subject': 'Topic'})] + {'type': 'stream', 'to': 'Stream name', 'subject': 'Topic'}, 'test widget')] response_text = "Response" for test in expected: client.send_message = MagicMock() - handler.send_reply(test[0], response_text) - client.send_message.assert_called_once_with(dict(test[1], content=response_text)) + handler.send_reply(test[0], response_text, test[2]) + client.send_message.assert_called_once_with(dict( + test[1], content=response_text, widget_content=test[2])) def test_content_and_full_content(self): client = FakeClient()