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.
This commit is contained in:
derAnfaenger 2017-10-10 14:29:59 +02:00 committed by Tim Abbott
parent d0c0b148b3
commit 0473692abd
1 changed files with 5 additions and 4 deletions

View File

@ -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'],
))