-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
51 lines (39 loc) · 1.94 KB
/
Copy pathbot.py
File metadata and controls
51 lines (39 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os
import requests
from telegram import Update
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext
# Get API URL from Render environment
API_URL = os.getenv("API_URL", "https://phish-detector-api.onrender.com/predict")
def start(update: Update, context: CallbackContext):
update.message.reply_text(
"🛡️ *Phishing Detector Bot*\n\n"
"Send me a URL, and I'll check if it's phishing!\n\n"
"Example: `https://example.com`",
parse_mode="Markdown"
)
def analyze_url(update: Update, context: CallbackContext):
url = update.message.text.strip()
try:
response = requests.post(API_URL, json={"url": url}, timeout=5)
result = response.json()
reply = (
f"🔗 *URL*: `{result['url']}`\n\n"
f"🔄 *Consensus*: _{result['consensus'].upper()}_\n"
f"📊 *Avg Confidence*: {result['average_confidence']*100:.1f}%\n\n"
f"🤖 *Model Results*:\n"
f"- Logistic Regression: {result['predictions']['logistic_regression']['result']} ({result['predictions']['logistic_regression']['confidence']*100:.1f}%)\n"
f"- Random Forest: {result['predictions']['random_forest']['result']} ({result['predictions']['random_forest']['confidence']*100:.1f}%)\n"
f"- XGBoost: {result['predictions']['xgboost']['result']} ({result['predictions']['xgboost']['confidence']*100:.1f}%)"
)
update.message.reply_text(reply, parse_mode="Markdown")
except Exception as e:
update.message.reply_text(f"⚠️ Error: {str(e)}")
def main():
updater = Updater(os.getenv("BOT_TOKEN"), use_context=True)
dp = updater.dispatcher
dp.add_handler(CommandHandler("start", start))
dp.add_handler(MessageHandler(Filters.text & ~Filters.command, analyze_url))
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()