Example #1
0
    def slack_event(self):
        if request.method == 'GET':
            return helper.skeleton(template="api-error.html", title="API error")

        event_data = json.loads(request.data.decode('utf-8'))
        if event_data['token'] == self.config.verification_token:
            print('authorized')
            if "challenge" in event_data:
                return make_response(event_data.get("challenge"), 200, {"content_type": "application/json"})

            # got:
            # {'token': '****', 'team_id': 'TFFAC0JNA', 'api_app_id': 'ATPCVD9JN', 'event': {'client_msg_id': 'b874556d-3bda-408f-93a8-2b3ac5a41780', 'type': 'app_mention', 'text': '<@UTQNR2V6X> deploy', 'user': '******', 'ts': '1582823443.002000', 'team': 'TFFAC0JNA', 'blocks': [{'type': 'rich_text', 'block_id': '+6La', 'elements': [{'type': 'rich_text_section', 'elements': [{'type': 'user', 'user_id': 'UTQNR2V6X'}, {'type': 'text', 'text': ' deploy'}]}]}], 'channel': 'CFD67NJ64', 'event_ts': '1582823443.002000'}, 'type': 'event_callback', 'event_id': 'EvULDG0JBX', 'event_time': 1582823443, 'authed_users': ['UTQNR2V6X']}
            if "event" in event_data:
                if event_data["event"]["type"] == "app_mention":
                    # and "type" in event_data["event"] and event_data["event"]["type"] == "app_mention"
                    my_command = event_data["event"]["text"]
                    my_channel = event_data["event"]["channel"]
                    my_user = event_data["event"]["user"]
                    print("mention:" + my_command)
                    # self.client.chat_postEphemeral(
                    #     channel=my_channel,
                    #     text="OK, so you wanted `" + my_command + "`? Give me a second or two",
                    #     user=my_user
                    # )
                    # print("slack_event process")
                    self.client.chat_postEphemeral(
                        channel=my_channel,
                        text=self.ai(my_command),
                        user=my_user
                    )
                    print("slack_event done")
        return make_response(jsonify({'success': True}), 200, {"content_type": "application/json"})
Example #2
0
    def slack_command(self, command):
        if request.method == 'GET':
            return helper.skeleton(template="api-error.html", title="API error")

        if request.form['token'] == self.config.verification_token:
            if command == "instances":
                # ImmutableMultiDict([('token', '****'), ('team_id', 'TFFAC0JNA'), ('team_domain', 'jardalhotak'), ('channel_id', 'CFD67NJ64'), ('channel_name', 'general'), ('user_id', 'UFFAC0K62'), ('user_name', 'jarda'), ('command', '/my-instances'), ('text', 'my'), ('response_url', 'https://hooks.slack.com/commands/**'), ('trigger_id', '***')])
                payload = {'text': 'What instance dude? type `/instances my` or `/instances all`'}
                if request.form['text'] == "my":
                    payload = {
                        'text': 'Hey dude, this is a list of *your* instances (@' + request.form['user_name'] + '):'}
                if request.form['text'] == "all":
                    payload = {'text': 'Hey dude, this is a list of *all* instances:'}
                return jsonify(payload)
Example #3
0
    def do_admin_login():
        if request.form and 'password' in request.form and 'username' in request.form:
            if request.form['password'] == 'password' and request.form['username'] == 'admin':

                config = Configuration.Configuration()

                session['logged_in'] = True
                session['username'] = request.form['username']
                session['full_name'] = "Antonius Blbus"

                welcome_role = ""
                session['admin'] = False

                if session['username'] in config.admin_users:
                    session['admin'] = True
                    welcome_role = " administrator "

                flash(message=f'Welcome {welcome_role}{session["full_name"]}, you have been successfully logged in',
                      category='success')

            else:
                flash(message='Invalid credentials! Make sure you use your OAAD account in format AB123',
                      category='danger')
        return helper.skeleton(template="login.html", title="login")
Example #4
0
 def logout():
     session['logged_in'] = False
     session['username'] = None
     return helper.skeleton(template="logout.html", title="logout")
Example #5
0
 def root():
     return helper.skeleton(template="overview.html", title="Overview")
Example #6
0
 def how_to():
     return helper.skeleton(template="how-to.html", title="how to")
Example #7
0
 def monitoring():
     return helper.skeleton(template="monitoring.html", title="monitoring")
Example #8
0
 def my_instances():
     return helper.skeleton(template="my-instances.html", title="my instances")