creating and referencing channels properly now

master
Faelix Incident Handler 7 years ago
parent fe1961dfc6
commit b7fa001c8f

@ -25,29 +25,38 @@ def mattermost_incident():
# token: XXXXXXXXXXXXXXXXXXXXXXXXXX
if request.form[ 'token' ] in app.config[ 'MATTERMOST_COMMAND_TOKENS' ]:
fi_number = incident.generate_incident_number()
channel_name = fi_number.lower()
incident_number = incident.generate_incident_number()
fi_number = "FI#" + incident_number
channel_name = "incident" + incident_number
purpose = request.form[ 'text' ]
channel = app.mm.channels.create_channel( options = { "team_id": request.form[ 'team_id' ],
"name": channel_name,
"purpose": "Incident " + fi_number + ( purpose and " " + purpose or "" ),
"header": "", ## Incident #" + fi_number,
"type": "P",
"display_name": fi_number,
"purpose": "Internal discussion about incident " + fi_number,
"header": purpose,
"type": "O",
} )
# add user to the channel we just created
app.mm.client.make_request( 'post', '/channels/' + channel[ 'id' ] + '/members', options = { 'user_id': request.form[ 'user_id' ],
} )
app.mm.posts.create_post( options = { 'channel_id': channel[ 'id' ],
'message': "Incident Channel for #%s created by @%s" % ( fi_number, request.form[ 'user_name' ] ),
'message': "Incident Channel for %s created by @%s" % ( fi_number, request.form[ 'user_name' ] ),
} )
app.mm.posts.create_post( options = { 'channel_id': request.form[ 'channel_id' ],
'message': 'Starting incident %s with discussion tagged as #%s' % ( fi_number, fi_number, ),
'message': 'Starting incident %s with discussion in channel ~%s' % ( fi_number, channel_name, ),
} )
return "" # "Starting incident %s in channel #%s." % ( fi_number, channel_name )
return ""
else:
return "Invalid command token."
@app.route( '/mattermost/fih', methods = [ 'POST' ] )
def mattermost_fig():
print( repr( request.form ) )
return "Whaaat?"
@app.route( '/' )
def hello_world():

@ -7,7 +7,7 @@ import mattermostdriver
random.seed( os.urandom( 8 ) )
def generate_incident_number():
return "FI" + datetime.datetime.now().strftime( "%Y%m%d" ) + ( "%4d" % int( random.random() * 10000 ) )
return datetime.datetime.now().strftime( "%Y%m%d" ) + ( "%4d" % int( random.random() * 10000 ) )
class Mattermost( object ):
def __init__( self, *args, **kwargs ):

Loading…
Cancel
Save