Skip to content

Commit

Permalink
Add a Logging Table to keep track OWASP-BLT#13
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarthak5598 committed Mar 14, 2024
1 parent c06db0c commit 6aaf63c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
from flask import Flask, request
from flask import Flask, request,jsonify
from slack import WebClient
from slackeventsapi import SlackEventAdapter
from dotenv import load_dotenv
import logging
import os


load_dotenv() # Load environment variables from .env file

logging.basicConfig(filename='slack_messages.log', level=logging.INFO)
app = Flask(__name__)
slack_events_adapter = SlackEventAdapter(os.environ['SIGNING_SECRET'], "/slack/events", app)
client = WebClient(token=os.environ['SLACK_TOKEN'])

@slack_events_adapter.on("team_join")
def handle_team_join(event_data):
user_id = event_data["event"]["user"]["id"]
client.chat_postMessage(channel='#trying_bot', text=f"Welcome <@{user_id}> to the team!")
client.chat_postEphemeral(channel=user_id, text=f"Welcome <@{user_id}> to the team! This message is visible only to you.")

@slack_events_adapter.on("message")
def handle_message(event_data):
message = event_data["event"]
if message.get("subtype") is None and "contribut" in message.get("text", ""):
user = message["user"]
channel = message["channel"]
client.chat_postMessage(channel='#trying_bot', text=f"Hello <@{user}>! please go through our readme ")
def handle_message(payload):
message = payload.get("event",{})
if message.get("subtype") is None and not any(keyword in message.get("text", "").lower() for keyword in ["#contribute"]) and any(keyword in message.get("text", "").lower() for keyword in ["contribute", "contributing", "contributes"]):
user = message.get("user")
channel = message.get("channel")
channel_id="C04DH8HEPTR"
client.chat_postMessage(channel='#trying_bot', text=f"Hello <@{user}>! please check this channel <#{channel_id}>")

@app.route("/slack/events", methods=["POST"])
def slack_events():
# Verify the request came from Slack
if request.headers.get('X-Slack-Signature') and request.headers.get('X-Slack-Request-Timestamp'):
slack_events_adapter.handle(request.data.decode('utf-8'), request.headers.get('X-Slack-Signature'), request.headers.get('X-Slack-Request-Timestamp'))
return jsonify({"status": "ok"}), 200
else:
return jsonify({"error": "invalid request"}), 400

if __name__ == "__main__":
app.run(port=3000)
Empty file added slack_message.log
Empty file.

0 comments on commit 6aaf63c

Please sign in to comment.