forked from OWASP-BLT/BLT-Lettuce
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a Logging Table to keep track OWASP-BLT#13
- Loading branch information
1 parent
c06db0c
commit 6aaf63c
Showing
2 changed files
with
20 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.