bots: Add example bots for "followup" and "help".
This commit also starts to build out the infrastructure for helping Zulip contributors to more easily author bots in a way that sets up for running some bots on the server itself.
This commit is contained in:
parent
8d75662c7c
commit
38c7b611b6
5 changed files with 263 additions and 0 deletions
53
contrib_bots/lib/followup.py
Normal file
53
contrib_bots/lib/followup.py
Normal file
|
@ -0,0 +1,53 @@
|
|||
# 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
|
||||
looks for messages starting with '@followup'.
|
||||
|
||||
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
|
||||
messages with "@followup".
|
||||
|
||||
Before running this, make sure to create a stream
|
||||
called "followup" that your API user can send to.
|
||||
'''
|
||||
|
||||
def triage_message(self, message):
|
||||
# return True iff we want to (possibly) response to this message
|
||||
|
||||
original_content = message['content']
|
||||
|
||||
# This next line of code is defensive, as we
|
||||
# never want to get into an infinite loop of posting follow
|
||||
# ups for own follow ups!
|
||||
if message['display_recipient'] == 'followup':
|
||||
return False
|
||||
is_follow_up = (original_content.startswith('@followup') or
|
||||
original_content.startswith('@follow-up'))
|
||||
|
||||
return is_follow_up
|
||||
|
||||
def handle_message(self, message, client):
|
||||
original_content = message['content']
|
||||
original_sender = message['sender_email']
|
||||
new_content = original_content.replace('@followup',
|
||||
'from %s:' % (original_sender,))
|
||||
|
||||
client.send_message(dict(
|
||||
type='stream',
|
||||
to='followup',
|
||||
subject=message['sender_email'],
|
||||
content=new_content,
|
||||
))
|
||||
|
||||
handler_class = FollowupHandler
|
Loading…
Add table
Add a link
Reference in a new issue