From 0473692abdc771b3a1af9963265772870a861234 Mon Sep 17 00:00:00 2001 From: derAnfaenger Date: Tue, 10 Oct 2017 14:29:59 +0200 Subject: [PATCH] embedded bots: Properly reply to PMs and streams This fixes an exception occurring when engaging an embedded bot in a PM, makes it respond as itself instead of the sender, and makes it respond to the PM conversation it is engaded in. --- zerver/lib/bot_lib.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/zerver/lib/bot_lib.py b/zerver/lib/bot_lib.py index ac3c39b674..99866e141a 100644 --- a/zerver/lib/bot_lib.py +++ b/zerver/lib/bot_lib.py @@ -84,9 +84,10 @@ class EmbeddedBotHandler(object): def send_message(self, message): # type: (Dict[str, Any]) -> None if self._rate_limit.is_legal(): - internal_send_message(realm=self.user_profile.realm, sender_email=message['sender_email'], - recipient_type_name=message['type'], recipients=message['to'], - subject=message['subject'], content=message['content']) + recipients = message['to'] if message['type'] == 'stream' else ','.join(message['to']) + internal_send_message(realm=self.user_profile.realm, sender_email=self.user_profile.email, + recipient_type_name=message['type'], recipients=recipients, + subject=message.get('subject', None), content=message['content']) else: self._rate_limit.show_error_and_exit() @@ -95,7 +96,7 @@ class EmbeddedBotHandler(object): if message['type'] == 'private': self.send_message(dict( type='private', - to=[x['email'] for x in message['display_recipient'] if self.email != x['email']], + to=[x['email'] for x in message['display_recipient']], content=response, sender_email=message['sender_email'], ))