2016-08-17 12:34:11 -04:00
|
|
|
# See readme.md for instructions on running this code.
|
|
|
|
|
|
|
|
class FollowupHandler(object):
|
|
|
|
'''
|
|
|
|
This plugin facilitates creating follow-up tasks when
|
|
|
|
you are using Zulip to conduct a virtual meeting. It
|
2017-02-16 16:56:32 -05:00
|
|
|
looks for messages starting with '@mention-bot'.
|
2016-08-17 12:34:11 -04:00
|
|
|
|
|
|
|
In this example, we write follow up items to a special
|
|
|
|
Zulip stream called "followup," but this code could
|
|
|
|
be adapted to write follow up items to some kind of
|
|
|
|
external issue tracker as well.
|
|
|
|
'''
|
|
|
|
|
|
|
|
def usage(self):
|
|
|
|
return '''
|
|
|
|
This plugin will allow users to flag messages
|
|
|
|
as being follow-up items. Users should preface
|
2017-02-16 16:56:32 -05:00
|
|
|
messages with "@mention-bot".
|
2016-08-17 12:34:11 -04:00
|
|
|
|
|
|
|
Before running this, make sure to create a stream
|
|
|
|
called "followup" that your API user can send to.
|
|
|
|
'''
|
|
|
|
|
2017-06-11 09:03:39 -04:00
|
|
|
def handle_message(self, message, bot_handler, state_handler):
|
2017-05-23 20:56:51 -04:00
|
|
|
if message['content'] == '':
|
|
|
|
bot_response = "Please specify the message you want to send to followup stream after @mention-bot"
|
2017-06-11 09:03:39 -04:00
|
|
|
bot_handler.send_reply(message, bot_response)
|
2017-05-23 20:56:51 -04:00
|
|
|
else:
|
|
|
|
bot_response = self.get_bot_followup_response(message)
|
2017-06-11 09:03:39 -04:00
|
|
|
bot_handler.send_message(dict(
|
2017-05-23 20:56:51 -04:00
|
|
|
type='stream',
|
|
|
|
to='followup',
|
|
|
|
subject=message['sender_email'],
|
|
|
|
content=bot_response,
|
|
|
|
))
|
2016-08-17 12:34:11 -04:00
|
|
|
|
2017-03-05 13:58:18 -05:00
|
|
|
def get_bot_followup_response(self, message):
|
|
|
|
original_content = message['content']
|
|
|
|
original_sender = message['sender_email']
|
2017-05-23 20:56:51 -04:00
|
|
|
temp_content = 'from %s: ' % (original_sender,)
|
2017-03-05 13:58:18 -05:00
|
|
|
new_content = temp_content + original_content
|
|
|
|
|
|
|
|
return new_content
|
|
|
|
|
2016-08-17 12:34:11 -04:00
|
|
|
handler_class = FollowupHandler
|