Spaces:
Paused
Paused
CBV01 commited on
Commit ·
e767948
1
Parent(s): 6c2d0ad
feat: anti-ban delivery suite with 4-speed controls, post-campaign sweep, consecutive post shield, and permanent blacklist management
Browse files- backend/database.py +4 -1
- backend/main.py +136 -21
- backend/migrate.py +3 -0
- frontend/src/app/campaigns/page.tsx +445 -13
backend/database.py
CHANGED
|
@@ -248,7 +248,10 @@ def init_db():
|
|
| 248 |
failed_groups TEXT DEFAULT '[]',
|
| 249 |
exclude_groups TEXT DEFAULT '[]',
|
| 250 |
processed_groups TEXT DEFAULT '[]',
|
| 251 |
-
media_url TEXT
|
|
|
|
|
|
|
|
|
|
| 252 |
)""",
|
| 253 |
"""CREATE TABLE IF NOT EXISTS leads (
|
| 254 |
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
| 248 |
failed_groups TEXT DEFAULT '[]',
|
| 249 |
exclude_groups TEXT DEFAULT '[]',
|
| 250 |
processed_groups TEXT DEFAULT '[]',
|
| 251 |
+
media_url TEXT,
|
| 252 |
+
speed_mode TEXT DEFAULT 'balanced',
|
| 253 |
+
sweep_status TEXT DEFAULT 'idle',
|
| 254 |
+
deleted_groups TEXT DEFAULT '[]'
|
| 255 |
)""",
|
| 256 |
"""CREATE TABLE IF NOT EXISTS leads (
|
| 257 |
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
backend/main.py
CHANGED
|
@@ -1119,6 +1119,7 @@ class CampaignRequest(BaseModel):
|
|
| 1119 |
interval_hours: int = 0
|
| 1120 |
interval_minutes: int = 0
|
| 1121 |
media_url: Optional[str] = None
|
|
|
|
| 1122 |
|
| 1123 |
class AdminLoginRequest(BaseModel):
|
| 1124 |
password: str
|
|
@@ -4088,6 +4089,7 @@ class CampaignEditRequest(BaseModel):
|
|
| 4088 |
interval_minutes: Optional[int] = None
|
| 4089 |
phone_number: Optional[str] = None
|
| 4090 |
media_url: Optional[str] = None
|
|
|
|
| 4091 |
|
| 4092 |
@app.put("/api/telegram/campaigns/{task_id}")
|
| 4093 |
async def edit_campaign(task_id: int, req: CampaignEditRequest, user_id: str = Depends(get_current_user_id)):
|
|
@@ -4128,6 +4130,9 @@ async def edit_campaign(task_id: int, req: CampaignEditRequest, user_id: str = D
|
|
| 4128 |
if req.media_url is not None:
|
| 4129 |
updates.append("media_url = ?")
|
| 4130 |
params.append(req.media_url)
|
|
|
|
|
|
|
|
|
|
| 4131 |
|
| 4132 |
if updates:
|
| 4133 |
# Reset to pending on edit so it re-runs
|
|
@@ -4281,6 +4286,41 @@ async def update_permanent_excludes(req: PermanentExcludeRequest, user_id: str =
|
|
| 4281 |
if hasattr(conn, "close"): conn.close()
|
| 4282 |
return {"status": "success"}
|
| 4283 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4284 |
# Removed redundant get_accounts (already refactored earlier)
|
| 4285 |
|
| 4286 |
@app.post("/api/telegram/campaigns/{task_id}/toggle-pause")
|
|
@@ -4334,7 +4374,7 @@ async def get_campaigns(user_id: str = Depends(get_current_user_id)):
|
|
| 4334 |
conn = get_db_connection()
|
| 4335 |
try:
|
| 4336 |
tasks = conn.execute(
|
| 4337 |
-
"SELECT id, phone_number, scheduled_time, message_text, target_groups, status, interval_hours, interval_minutes, total_targets, sent_count, batch_number, failed_groups, exclude_groups, media_url, name FROM tasks WHERE user_id = ? ORDER BY scheduled_time DESC",
|
| 4338 |
(user_id,)
|
| 4339 |
).fetchall()
|
| 4340 |
|
|
@@ -4352,6 +4392,13 @@ async def get_campaigns(user_id: str = Depends(get_current_user_id)):
|
|
| 4352 |
pass
|
| 4353 |
return default
|
| 4354 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4355 |
campaigns_list.append(dict(
|
| 4356 |
id=_val("id", 0),
|
| 4357 |
phone_number=_val("phone_number", 1, ""),
|
|
@@ -4368,7 +4415,10 @@ async def get_campaigns(user_id: str = Depends(get_current_user_id)):
|
|
| 4368 |
failed_groups=_val("failed_groups", 11, "[]"),
|
| 4369 |
exclude_groups=_val("exclude_groups", 12, "[]"),
|
| 4370 |
media_url=_val("media_url", 13, None),
|
| 4371 |
-
name=_val("name", 14) or "Broadcast Campaign"
|
|
|
|
|
|
|
|
|
|
| 4372 |
))
|
| 4373 |
return {"campaigns": campaigns_list}
|
| 4374 |
except Exception as e:
|
|
@@ -4407,7 +4457,8 @@ async def create_campaign(req: CampaignRequest, user_id: str = Depends(get_curre
|
|
| 4407 |
camp_name = req.name or "Broadcast Campaign"
|
| 4408 |
camp_groups = req.groups or []
|
| 4409 |
camp_exclude = req.exclude_groups or []
|
| 4410 |
-
|
|
|
|
| 4411 |
clean_time = req.schedule_time
|
| 4412 |
if 'T' in clean_time:
|
| 4413 |
parts = clean_time.split(':')
|
|
@@ -4415,11 +4466,11 @@ async def create_campaign(req: CampaignRequest, user_id: str = Depends(get_curre
|
|
| 4415 |
clean_time = f"{parts[0]}:{parts[1]}"
|
| 4416 |
|
| 4417 |
conn.execute(
|
| 4418 |
-
"INSERT INTO tasks (user_id, name, phone_number, scheduled_time, message_text, target_groups, status, interval_hours, interval_minutes, total_targets, sent_count, batch_number, failed_groups, exclude_groups, media_url) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
| 4419 |
-
(user_id, camp_name, req.phone_number, clean_time, req.message, str(camp_groups), "pending", req.interval_hours or 0, req.interval_minutes or 0, len(camp_groups), 0, 1, "[]", str(camp_exclude), req.media_url)
|
| 4420 |
)
|
| 4421 |
if hasattr(conn, "commit"): conn.commit()
|
| 4422 |
-
return {"status": "success", "message": f"Campaign scheduled for {req.schedule_time} UTC."}
|
| 4423 |
except Exception as e:
|
| 4424 |
print(f"CAMPAIGNS: Error in create_campaign: {e}")
|
| 4425 |
raise HTTPException(status_code=400, detail=str(e))
|
|
@@ -6483,8 +6534,17 @@ async def root():
|
|
| 6483 |
async def task_poller():
|
| 6484 |
active_tasks = set()
|
| 6485 |
|
| 6486 |
-
async def run_single_task(task_id, message, groups_str, phone_num, u_id, interval, scheduled_time, exclude_groups_str="[]", processed_groups_str="[]", sent_count_init=0, failed_groups_str="[]", media_url=None):
|
| 6487 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6488 |
# Update status to 'processing'
|
| 6489 |
conn = get_db_connection()
|
| 6490 |
conn.execute("UPDATE tasks SET status = 'processing' WHERE id = ?", (task_id,))
|
|
@@ -6662,19 +6722,29 @@ async def task_poller():
|
|
| 6662 |
# Final Spintax processing
|
| 6663 |
final_msg = recursive_spin(final_msg_base).strip()
|
| 6664 |
|
| 6665 |
-
# SPAM PREVENTION: Check last message
|
| 6666 |
try:
|
| 6667 |
last_msgs = await client.get_messages(entity, limit=1)
|
| 6668 |
first_msg = last_msgs[0] if isinstance(last_msgs, list) else last_msgs
|
| 6669 |
if first_msg and getattr(first_msg, 'sender_id', None) == me_id:
|
| 6670 |
-
log_debug(f"BKG_TASK[{task_id}]: Skipping {target_id} - Last message was from this account.")
|
|
|
|
| 6671 |
continue
|
| 6672 |
except Exception as e:
|
| 6673 |
log_debug(f"BKG_TASK[{task_id}]: Last message check failed for {target_id}: {e}")
|
| 6674 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6675 |
log_debug(f"BKG_TASK[{task_id}]: Sending to {target_id} via {sender_name}...")
|
| 6676 |
|
| 6677 |
try:
|
|
|
|
| 6678 |
if media_url:
|
| 6679 |
# Support multiple files (JSON array or comma-separated)
|
| 6680 |
files_to_send = []
|
|
@@ -6718,13 +6788,13 @@ async def task_poller():
|
|
| 6718 |
if resolved_files:
|
| 6719 |
try:
|
| 6720 |
if len(resolved_files) == 1:
|
| 6721 |
-
await client.send_file(entity, file=resolved_files[0], caption=final_msg, parse_mode='md')
|
| 6722 |
else:
|
| 6723 |
try:
|
| 6724 |
-
await client.send_file(entity, file=resolved_files, caption=final_msg, parse_mode='md')
|
| 6725 |
except Exception as album_err:
|
| 6726 |
log_debug(f"BKG_TASK[{task_id}]: Album send failed ({album_err}), falling back to single send with caption...")
|
| 6727 |
-
await client.send_file(entity, file=resolved_files[0], caption=final_msg, parse_mode='md')
|
| 6728 |
for extra_file in resolved_files[1:]:
|
| 6729 |
try:
|
| 6730 |
await asyncio.sleep(1)
|
|
@@ -6733,11 +6803,15 @@ async def task_poller():
|
|
| 6733 |
pass
|
| 6734 |
except Exception as media_err:
|
| 6735 |
log_debug(f"BKG_TASK[{task_id}]: send_file failed ({media_err}), falling back to text message...")
|
| 6736 |
-
await client.send_message(entity, final_msg, parse_mode='md')
|
| 6737 |
else:
|
| 6738 |
-
await client.send_message(entity, final_msg, parse_mode='md')
|
| 6739 |
else:
|
| 6740 |
-
await client.send_message(entity, final_msg, parse_mode='md')
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6741 |
log_debug(f"BKG_TASK[{task_id}]: TRANSMITTED successfully.")
|
| 6742 |
sent_ok_stats[0] += 1 # type: ignore
|
| 6743 |
|
|
@@ -6772,10 +6846,20 @@ async def task_poller():
|
|
| 6772 |
elif "UserIsBlocked" in err_str: reason = "User Blocked"
|
| 6773 |
elif "FloodWait" in err_str: reason = "Telegram Limit"
|
| 6774 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6775 |
failed_list.append({"id": group, "name": getattr(entity, 'title', group) if 'entity' in locals() else group, "reason": reason})
|
| 6776 |
|
| 6777 |
-
#
|
| 6778 |
-
await asyncio.sleep(random.randint(
|
| 6779 |
except Exception as group_err:
|
| 6780 |
log_debug(f"BKG_TASK[{task_id}]: Loop error on group {raw_group}: {str(group_err)}")
|
| 6781 |
if "FloodWaitError" in str(group_err):
|
|
@@ -6808,11 +6892,42 @@ async def task_poller():
|
|
| 6808 |
final_status = 'completed'
|
| 6809 |
log_debug(f"BKG_TASK[{task_id}]: Finalizing. Status={final_status}, Sent={sent_ok_stats[0]}, Failed={len(failed_list)}")
|
| 6810 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6811 |
conn.execute(
|
| 6812 |
-
"UPDATE tasks SET status = ?, sent_count = ?, failed_groups = ?, processed_groups = ? WHERE id = ?",
|
| 6813 |
-
(final_status, sent_ok_stats[0], json.dumps(failed_list), json.dumps(processed_list), task_id)
|
| 6814 |
)
|
| 6815 |
-
print(f"BKG: Task {task_id} marked {final_status.upper()} (Successful: {sent_ok_stats[0]})")
|
| 6816 |
else:
|
| 6817 |
log_debug(f"BKG: Task {task_id} already marked as {current_status}, skipping auto-complete.")
|
| 6818 |
# We still update the final stats so the UI is accurate
|
|
@@ -6838,7 +6953,7 @@ async def task_poller():
|
|
| 6838 |
|
| 6839 |
# 1. Fetch PENDING tasks
|
| 6840 |
tasks = conn.execute(
|
| 6841 |
-
"SELECT id, message_text, target_groups, phone_number, user_id, interval_hours, scheduled_time, exclude_groups, processed_groups, sent_count, failed_groups, media_url FROM tasks WHERE status = 'pending' AND scheduled_time <= ?",
|
| 6842 |
(now_str,)
|
| 6843 |
).fetchall()
|
| 6844 |
|
|
|
|
| 1119 |
interval_hours: int = 0
|
| 1120 |
interval_minutes: int = 0
|
| 1121 |
media_url: Optional[str] = None
|
| 1122 |
+
speed_mode: Optional[str] = "balanced"
|
| 1123 |
|
| 1124 |
class AdminLoginRequest(BaseModel):
|
| 1125 |
password: str
|
|
|
|
| 4089 |
interval_minutes: Optional[int] = None
|
| 4090 |
phone_number: Optional[str] = None
|
| 4091 |
media_url: Optional[str] = None
|
| 4092 |
+
speed_mode: Optional[str] = None
|
| 4093 |
|
| 4094 |
@app.put("/api/telegram/campaigns/{task_id}")
|
| 4095 |
async def edit_campaign(task_id: int, req: CampaignEditRequest, user_id: str = Depends(get_current_user_id)):
|
|
|
|
| 4130 |
if req.media_url is not None:
|
| 4131 |
updates.append("media_url = ?")
|
| 4132 |
params.append(req.media_url)
|
| 4133 |
+
if req.speed_mode is not None:
|
| 4134 |
+
updates.append("speed_mode = ?")
|
| 4135 |
+
params.append(req.speed_mode)
|
| 4136 |
|
| 4137 |
if updates:
|
| 4138 |
# Reset to pending on edit so it re-runs
|
|
|
|
| 4286 |
if hasattr(conn, "close"): conn.close()
|
| 4287 |
return {"status": "success"}
|
| 4288 |
|
| 4289 |
+
class AddExcludeRequest(BaseModel):
|
| 4290 |
+
ids: List[str]
|
| 4291 |
+
|
| 4292 |
+
class RemoveExcludeRequest(BaseModel):
|
| 4293 |
+
id: str
|
| 4294 |
+
|
| 4295 |
+
@app.post("/api/users/permanent-excludes/add")
|
| 4296 |
+
async def add_permanent_exclude(req: AddExcludeRequest, user_id: str = Depends(get_current_user_id)):
|
| 4297 |
+
conn = get_db_connection()
|
| 4298 |
+
try:
|
| 4299 |
+
row = conn.execute("SELECT permanent_excludes FROM users WHERE id = ?", (user_id,)).fetchone()
|
| 4300 |
+
current_ids = json.loads(row[0] or "[]") if row and row[0] else []
|
| 4301 |
+
for new_id in req.ids:
|
| 4302 |
+
clean = new_id.strip()
|
| 4303 |
+
if clean and clean not in current_ids:
|
| 4304 |
+
current_ids.append(clean)
|
| 4305 |
+
conn.execute("UPDATE users SET permanent_excludes = ? WHERE id = ?", (json.dumps(current_ids), user_id))
|
| 4306 |
+
if hasattr(conn, "commit"): conn.commit()
|
| 4307 |
+
return {"status": "success", "ids": current_ids}
|
| 4308 |
+
finally:
|
| 4309 |
+
if hasattr(conn, "close"): conn.close()
|
| 4310 |
+
|
| 4311 |
+
@app.post("/api/users/permanent-excludes/remove")
|
| 4312 |
+
async def remove_permanent_exclude(req: RemoveExcludeRequest, user_id: str = Depends(get_current_user_id)):
|
| 4313 |
+
conn = get_db_connection()
|
| 4314 |
+
try:
|
| 4315 |
+
row = conn.execute("SELECT permanent_excludes FROM users WHERE id = ?", (user_id,)).fetchone()
|
| 4316 |
+
current_ids = json.loads(row[0] or "[]") if row and row[0] else []
|
| 4317 |
+
new_ids = [i for i in current_ids if str(i).strip() != req.id.strip()]
|
| 4318 |
+
conn.execute("UPDATE users SET permanent_excludes = ? WHERE id = ?", (json.dumps(new_ids), user_id))
|
| 4319 |
+
if hasattr(conn, "commit"): conn.commit()
|
| 4320 |
+
return {"status": "success", "ids": new_ids}
|
| 4321 |
+
finally:
|
| 4322 |
+
if hasattr(conn, "close"): conn.close()
|
| 4323 |
+
|
| 4324 |
# Removed redundant get_accounts (already refactored earlier)
|
| 4325 |
|
| 4326 |
@app.post("/api/telegram/campaigns/{task_id}/toggle-pause")
|
|
|
|
| 4374 |
conn = get_db_connection()
|
| 4375 |
try:
|
| 4376 |
tasks = conn.execute(
|
| 4377 |
+
"SELECT id, phone_number, scheduled_time, message_text, target_groups, status, interval_hours, interval_minutes, total_targets, sent_count, batch_number, failed_groups, exclude_groups, media_url, name, speed_mode, sweep_status, deleted_groups FROM tasks WHERE user_id = ? ORDER BY scheduled_time DESC",
|
| 4378 |
(user_id,)
|
| 4379 |
).fetchall()
|
| 4380 |
|
|
|
|
| 4392 |
pass
|
| 4393 |
return default
|
| 4394 |
|
| 4395 |
+
del_groups_raw = _val("deleted_groups", 17, "[]")
|
| 4396 |
+
del_groups = []
|
| 4397 |
+
try:
|
| 4398 |
+
del_groups = json.loads(del_groups_raw) if isinstance(del_groups_raw, str) else (del_groups_raw or [])
|
| 4399 |
+
except Exception:
|
| 4400 |
+
del_groups = []
|
| 4401 |
+
|
| 4402 |
campaigns_list.append(dict(
|
| 4403 |
id=_val("id", 0),
|
| 4404 |
phone_number=_val("phone_number", 1, ""),
|
|
|
|
| 4415 |
failed_groups=_val("failed_groups", 11, "[]"),
|
| 4416 |
exclude_groups=_val("exclude_groups", 12, "[]"),
|
| 4417 |
media_url=_val("media_url", 13, None),
|
| 4418 |
+
name=_val("name", 14) or "Broadcast Campaign",
|
| 4419 |
+
speed_mode=_val("speed_mode", 15, "balanced") or "balanced",
|
| 4420 |
+
sweep_status=_val("sweep_status", 16, "idle") or "idle",
|
| 4421 |
+
deleted_groups=del_groups
|
| 4422 |
))
|
| 4423 |
return {"campaigns": campaigns_list}
|
| 4424 |
except Exception as e:
|
|
|
|
| 4457 |
camp_name = req.name or "Broadcast Campaign"
|
| 4458 |
camp_groups = req.groups or []
|
| 4459 |
camp_exclude = req.exclude_groups or []
|
| 4460 |
+
camp_speed = req.speed_mode or "balanced"
|
| 4461 |
+
print(f"CAMPAIGN: New campaign '{camp_name}' | Speed: {camp_speed} | Scheduled(UTC): {req.schedule_time} | Server UTC now: {now_utc}")
|
| 4462 |
clean_time = req.schedule_time
|
| 4463 |
if 'T' in clean_time:
|
| 4464 |
parts = clean_time.split(':')
|
|
|
|
| 4466 |
clean_time = f"{parts[0]}:{parts[1]}"
|
| 4467 |
|
| 4468 |
conn.execute(
|
| 4469 |
+
"INSERT INTO tasks (user_id, name, phone_number, scheduled_time, message_text, target_groups, status, interval_hours, interval_minutes, total_targets, sent_count, batch_number, failed_groups, exclude_groups, media_url, speed_mode, sweep_status, deleted_groups) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
| 4470 |
+
(user_id, camp_name, req.phone_number, clean_time, req.message, str(camp_groups), "pending", req.interval_hours or 0, req.interval_minutes or 0, len(camp_groups), 0, 1, "[]", str(camp_exclude), req.media_url, camp_speed, "idle", "[]")
|
| 4471 |
)
|
| 4472 |
if hasattr(conn, "commit"): conn.commit()
|
| 4473 |
+
return {"status": "success", "message": f"Campaign scheduled for {req.schedule_time} UTC with {camp_speed} speed."}
|
| 4474 |
except Exception as e:
|
| 4475 |
print(f"CAMPAIGNS: Error in create_campaign: {e}")
|
| 4476 |
raise HTTPException(status_code=400, detail=str(e))
|
|
|
|
| 6534 |
async def task_poller():
|
| 6535 |
active_tasks = set()
|
| 6536 |
|
| 6537 |
+
async def run_single_task(task_id, message, groups_str, phone_num, u_id, interval, scheduled_time, exclude_groups_str="[]", processed_groups_str="[]", sent_count_init=0, failed_groups_str="[]", media_url=None, speed_mode="balanced"):
|
| 6538 |
try:
|
| 6539 |
+
SPEED_CONFIGS = {
|
| 6540 |
+
"turbo": {"typing": 3, "min_delay": 17, "max_delay": 27},
|
| 6541 |
+
"balanced": {"typing": 5, "min_delay": 21, "max_delay": 35},
|
| 6542 |
+
"stealth": {"typing": 6, "min_delay": 40, "max_delay": 64},
|
| 6543 |
+
"ultra": {"typing": 7, "min_delay": 70, "max_delay": 115},
|
| 6544 |
+
}
|
| 6545 |
+
sp_cfg = SPEED_CONFIGS.get(speed_mode or "balanced", SPEED_CONFIGS["balanced"])
|
| 6546 |
+
sent_message_map: Dict[str, int] = {}
|
| 6547 |
+
|
| 6548 |
# Update status to 'processing'
|
| 6549 |
conn = get_db_connection()
|
| 6550 |
conn.execute("UPDATE tasks SET status = 'processing' WHERE id = ?", (task_id,))
|
|
|
|
| 6722 |
# Final Spintax processing
|
| 6723 |
final_msg = recursive_spin(final_msg_base).strip()
|
| 6724 |
|
| 6725 |
+
# SPAM PREVENTION: Check last message (Consecutive Post Shield)
|
| 6726 |
try:
|
| 6727 |
last_msgs = await client.get_messages(entity, limit=1)
|
| 6728 |
first_msg = last_msgs[0] if isinstance(last_msgs, list) else last_msgs
|
| 6729 |
if first_msg and getattr(first_msg, 'sender_id', None) == me_id:
|
| 6730 |
+
log_debug(f"BKG_TASK[{task_id}]: Skipping {target_id} - Last message was from this account (Consecutive Post Shield).")
|
| 6731 |
+
failed_list.append({"id": group, "name": getattr(entity, 'title', group) if 'entity' in locals() else group, "reason": "Skipped: Last message was yours (Consecutive Shield)"})
|
| 6732 |
continue
|
| 6733 |
except Exception as e:
|
| 6734 |
log_debug(f"BKG_TASK[{task_id}]: Last message check failed for {target_id}: {e}")
|
| 6735 |
|
| 6736 |
+
# Human Typing Simulation
|
| 6737 |
+
try:
|
| 6738 |
+
typing_action: Any = client.action(entity, 'typing')
|
| 6739 |
+
async with typing_action:
|
| 6740 |
+
await asyncio.sleep(sp_cfg["typing"])
|
| 6741 |
+
except Exception:
|
| 6742 |
+
await asyncio.sleep(sp_cfg["typing"])
|
| 6743 |
+
|
| 6744 |
log_debug(f"BKG_TASK[{task_id}]: Sending to {target_id} via {sender_name}...")
|
| 6745 |
|
| 6746 |
try:
|
| 6747 |
+
sent_msg = None
|
| 6748 |
if media_url:
|
| 6749 |
# Support multiple files (JSON array or comma-separated)
|
| 6750 |
files_to_send = []
|
|
|
|
| 6788 |
if resolved_files:
|
| 6789 |
try:
|
| 6790 |
if len(resolved_files) == 1:
|
| 6791 |
+
sent_msg = await client.send_file(entity, file=resolved_files[0], caption=final_msg, parse_mode='md')
|
| 6792 |
else:
|
| 6793 |
try:
|
| 6794 |
+
sent_msg = await client.send_file(entity, file=resolved_files, caption=final_msg, parse_mode='md')
|
| 6795 |
except Exception as album_err:
|
| 6796 |
log_debug(f"BKG_TASK[{task_id}]: Album send failed ({album_err}), falling back to single send with caption...")
|
| 6797 |
+
sent_msg = await client.send_file(entity, file=resolved_files[0], caption=final_msg, parse_mode='md')
|
| 6798 |
for extra_file in resolved_files[1:]:
|
| 6799 |
try:
|
| 6800 |
await asyncio.sleep(1)
|
|
|
|
| 6803 |
pass
|
| 6804 |
except Exception as media_err:
|
| 6805 |
log_debug(f"BKG_TASK[{task_id}]: send_file failed ({media_err}), falling back to text message...")
|
| 6806 |
+
sent_msg = await client.send_message(entity, final_msg, parse_mode='md')
|
| 6807 |
else:
|
| 6808 |
+
sent_msg = await client.send_message(entity, final_msg, parse_mode='md')
|
| 6809 |
else:
|
| 6810 |
+
sent_msg = await client.send_message(entity, final_msg, parse_mode='md')
|
| 6811 |
+
|
| 6812 |
+
if sent_msg and hasattr(sent_msg, 'id'):
|
| 6813 |
+
sent_message_map[group] = sent_msg.id
|
| 6814 |
+
|
| 6815 |
log_debug(f"BKG_TASK[{task_id}]: TRANSMITTED successfully.")
|
| 6816 |
sent_ok_stats[0] += 1 # type: ignore
|
| 6817 |
|
|
|
|
| 6846 |
elif "UserIsBlocked" in err_str: reason = "User Blocked"
|
| 6847 |
elif "FloodWait" in err_str: reason = "Telegram Limit"
|
| 6848 |
|
| 6849 |
+
if "banned from sending messages in supergroups" in err_str or "USER_BANNED_IN_CHANNEL" in err_str:
|
| 6850 |
+
reason = "Account Restricted by Telegram"
|
| 6851 |
+
failed_list.append({"id": group, "name": getattr(entity, 'title', group) if 'entity' in locals() else group, "reason": reason})
|
| 6852 |
+
log_debug(f"BKG_TASK[{task_id}]: CRITICAL - Account {phone_num} restricted by Telegram. Halting campaign to protect account.")
|
| 6853 |
+
u_conn = get_db_connection()
|
| 6854 |
+
u_conn.execute("UPDATE tasks SET status = 'paused', failed_groups = ?, processed_groups = ? WHERE id = ?", (json.dumps(failed_list), json.dumps(processed_list), task_id))
|
| 6855 |
+
if hasattr(u_conn, "commit"): u_conn.commit()
|
| 6856 |
+
if hasattr(u_conn, "close"): u_conn.close()
|
| 6857 |
+
break
|
| 6858 |
+
|
| 6859 |
failed_list.append({"id": group, "name": getattr(entity, 'title', group) if 'entity' in locals() else group, "reason": reason})
|
| 6860 |
|
| 6861 |
+
# Dynamic Anti-Spam Interval based on speed_mode
|
| 6862 |
+
await asyncio.sleep(random.randint(sp_cfg["min_delay"], sp_cfg["max_delay"]))
|
| 6863 |
except Exception as group_err:
|
| 6864 |
log_debug(f"BKG_TASK[{task_id}]: Loop error on group {raw_group}: {str(group_err)}")
|
| 6865 |
if "FloodWaitError" in str(group_err):
|
|
|
|
| 6892 |
final_status = 'completed'
|
| 6893 |
log_debug(f"BKG_TASK[{task_id}]: Finalizing. Status={final_status}, Sent={sent_ok_stats[0]}, Failed={len(failed_list)}")
|
| 6894 |
|
| 6895 |
+
deleted_groups_list = []
|
| 6896 |
+
# Run Delivery Sweep if any messages were transmitted
|
| 6897 |
+
if sent_message_map:
|
| 6898 |
+
try:
|
| 6899 |
+
log_debug(f"BKG_TASK[{task_id}]: Initiating Delivery Sweep on {len(sent_message_map)} groups...")
|
| 6900 |
+
conn.execute("UPDATE tasks SET sweep_status = 'sweeping' WHERE id = ?", (task_id,))
|
| 6901 |
+
if hasattr(conn, "commit"): conn.commit()
|
| 6902 |
+
|
| 6903 |
+
# Brief settling pause for group bots to trigger deletions
|
| 6904 |
+
await asyncio.sleep(8)
|
| 6905 |
+
|
| 6906 |
+
for g_id_str, m_id in sent_message_map.items():
|
| 6907 |
+
try:
|
| 6908 |
+
g_ent = await resolve_tg_entity(client, g_id_str)
|
| 6909 |
+
if not g_ent: continue
|
| 6910 |
+
check_msg = await client.get_messages(g_ent, ids=m_id)
|
| 6911 |
+
if check_msg is None or getattr(check_msg, 'message', None) is None:
|
| 6912 |
+
g_name = getattr(g_ent, 'title', g_id_str)
|
| 6913 |
+
log_debug(f"BKG_TASK[{task_id}]: SWEEP - Deleted message detected in {g_name} ({g_id_str})")
|
| 6914 |
+
deleted_groups_list.append({
|
| 6915 |
+
"id": g_id_str,
|
| 6916 |
+
"name": g_name,
|
| 6917 |
+
"reason": "Removed by group bot / admin"
|
| 6918 |
+
})
|
| 6919 |
+
await asyncio.sleep(0.5)
|
| 6920 |
+
except Exception as s_err:
|
| 6921 |
+
log_debug(f"BKG_TASK[{task_id}]: Sweep error for {g_id_str}: {s_err}")
|
| 6922 |
+
log_debug(f"BKG_TASK[{task_id}]: Sweep finished. Removed count: {len(deleted_groups_list)}")
|
| 6923 |
+
except Exception as sweep_fatal:
|
| 6924 |
+
log_debug(f"BKG_TASK[{task_id}]: Sweep fatal error: {sweep_fatal}")
|
| 6925 |
+
|
| 6926 |
conn.execute(
|
| 6927 |
+
"UPDATE tasks SET status = ?, sent_count = ?, failed_groups = ?, processed_groups = ?, sweep_status = 'completed', deleted_groups = ? WHERE id = ?",
|
| 6928 |
+
(final_status, sent_ok_stats[0], json.dumps(failed_list), json.dumps(processed_list), json.dumps(deleted_groups_list), task_id)
|
| 6929 |
)
|
| 6930 |
+
print(f"BKG: Task {task_id} marked {final_status.upper()} (Successful: {sent_ok_stats[0]}, Removed: {len(deleted_groups_list)})")
|
| 6931 |
else:
|
| 6932 |
log_debug(f"BKG: Task {task_id} already marked as {current_status}, skipping auto-complete.")
|
| 6933 |
# We still update the final stats so the UI is accurate
|
|
|
|
| 6953 |
|
| 6954 |
# 1. Fetch PENDING tasks
|
| 6955 |
tasks = conn.execute(
|
| 6956 |
+
"SELECT id, message_text, target_groups, phone_number, user_id, interval_hours, scheduled_time, exclude_groups, processed_groups, sent_count, failed_groups, media_url, speed_mode FROM tasks WHERE status = 'pending' AND scheduled_time <= ?",
|
| 6957 |
(now_str,)
|
| 6958 |
).fetchall()
|
| 6959 |
|
backend/migrate.py
CHANGED
|
@@ -17,6 +17,9 @@ def migrate():
|
|
| 17 |
("users", "passkey_verified", "INTEGER DEFAULT 0"),
|
| 18 |
("tasks", "interval_hours", "INTEGER DEFAULT 0"),
|
| 19 |
("tasks", "scheduled_time", "TEXT DEFAULT ''"), # In case it was missing
|
|
|
|
|
|
|
|
|
|
| 20 |
]
|
| 21 |
|
| 22 |
for table, column, definition in alter_queries:
|
|
|
|
| 17 |
("users", "passkey_verified", "INTEGER DEFAULT 0"),
|
| 18 |
("tasks", "interval_hours", "INTEGER DEFAULT 0"),
|
| 19 |
("tasks", "scheduled_time", "TEXT DEFAULT ''"), # In case it was missing
|
| 20 |
+
("tasks", "speed_mode", "TEXT DEFAULT 'balanced'"),
|
| 21 |
+
("tasks", "sweep_status", "TEXT DEFAULT 'idle'"),
|
| 22 |
+
("tasks", "deleted_groups", "TEXT DEFAULT '[]'"),
|
| 23 |
]
|
| 24 |
|
| 25 |
for table, column, definition in alter_queries:
|
frontend/src/app/campaigns/page.tsx
CHANGED
|
@@ -33,7 +33,10 @@ import {
|
|
| 33 |
Zap,
|
| 34 |
Filter,
|
| 35 |
Smartphone,
|
| 36 |
-
Eye
|
|
|
|
|
|
|
|
|
|
| 37 |
} from 'lucide-react';
|
| 38 |
import { apiFetch, getApiBase } from '@/lib/auth';
|
| 39 |
import { Preloader } from '@/components/Preloader';
|
|
@@ -109,7 +112,8 @@ export default function CampaignsPage() {
|
|
| 109 |
message: '',
|
| 110 |
interval_hours: '0',
|
| 111 |
interval_minutes: '0',
|
| 112 |
-
media_url: ''
|
|
|
|
| 113 |
});
|
| 114 |
const [mediaFiles, setMediaFiles] = useState<File[]>([]);
|
| 115 |
const [mediaPreviews, setMediaPreviews] = useState<string[]>([]);
|
|
@@ -122,7 +126,11 @@ export default function CampaignsPage() {
|
|
| 122 |
const [isSpintaxModalOpen, setIsSpintaxModalOpen] = useState(false);
|
| 123 |
const [isAiAssistantOpen, setIsAiAssistantOpen] = useState(false);
|
| 124 |
const [isAccountDropdownOpen, setIsAccountDropdownOpen] = useState(false);
|
| 125 |
-
const [groupPermissionFilter, setGroupPermissionFilter] = useState<'all' | 'sendable' | 'restricted'>('all');
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
// Live Cadence Countdown Clock & Media Preview Lightbox State
|
| 128 |
const [nowTime, setNowTime] = useState<number>(Date.now());
|
|
@@ -284,6 +292,49 @@ export default function CampaignsPage() {
|
|
| 284 |
} catch (e) { }
|
| 285 |
};
|
| 286 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
const fetchAccounts = async () => {
|
| 288 |
try {
|
| 289 |
const res = await apiFetch('/api/telegram/accounts');
|
|
@@ -438,7 +489,8 @@ export default function CampaignsPage() {
|
|
| 438 |
groups: selectedGroups,
|
| 439 |
target_groups: selectedGroups,
|
| 440 |
exclude_groups: excludedGroups,
|
| 441 |
-
media_url: finalMediaUrl || null
|
|
|
|
| 442 |
})
|
| 443 |
});
|
| 444 |
if (res.ok) {
|
|
@@ -449,7 +501,7 @@ export default function CampaignsPage() {
|
|
| 449 |
setSuccess(false);
|
| 450 |
setIsCreating(false);
|
| 451 |
setEditingId(null);
|
| 452 |
-
setCampaignData({ name: '', phone_number: '', schedule_time: '', message: '', interval_hours: '0', interval_minutes: '0', media_url: '' });
|
| 453 |
setMediaFiles([]);
|
| 454 |
setMediaPreviews([]);
|
| 455 |
setSelectedGroups([]);
|
|
@@ -480,7 +532,8 @@ export default function CampaignsPage() {
|
|
| 480 |
message: camp.message_text || camp.message || '',
|
| 481 |
interval_hours: (camp.interval_hours || 0).toString(),
|
| 482 |
interval_minutes: (camp.interval_minutes || 0).toString(),
|
| 483 |
-
media_url: camp.media_url || ''
|
|
|
|
| 484 |
});
|
| 485 |
|
| 486 |
// Parse multiple media URLs if stored as JSON list or comma separated
|
|
@@ -529,7 +582,7 @@ export default function CampaignsPage() {
|
|
| 529 |
|
| 530 |
const openNewCampaignModal = () => {
|
| 531 |
setEditingId(null);
|
| 532 |
-
setCampaignData({ name: '', phone_number: accounts[0]?.phone_number || '', schedule_time: '', message: '', interval_hours: '0', interval_minutes: '0', media_url: '' });
|
| 533 |
setMediaFiles([]);
|
| 534 |
setMediaPreviews([]);
|
| 535 |
setSelectedGroups([]);
|
|
@@ -585,6 +638,11 @@ export default function CampaignsPage() {
|
|
| 585 |
const matchesType = filterType === 'all' ||
|
| 586 |
(filterType === 'channels' && (d.is_channel || d.type === 'channel')) ||
|
| 587 |
(filterType === 'groups' && (!d.is_channel && d.type !== 'channel'));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 588 |
const matchesPermission = groupPermissionFilter === 'all' ||
|
| 589 |
(groupPermissionFilter === 'sendable' && d.can_send !== false) ||
|
| 590 |
(groupPermissionFilter === 'restricted' && d.can_send === false);
|
|
@@ -1069,17 +1127,55 @@ export default function CampaignsPage() {
|
|
| 1069 |
</div>
|
| 1070 |
</div>
|
| 1071 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1072 |
{/* Message Snippet */}
|
| 1073 |
<div className="mt-2 px-2.5 py-1 rounded-lg bg-white/[0.02] text-[10px] text-neutral-400 font-mono truncate leading-normal">
|
| 1074 |
"{camp.message_text || camp.message || '...'}"
|
| 1075 |
</div>
|
| 1076 |
</div>
|
| 1077 |
|
| 1078 |
-
{/* Footer: Target Entities */}
|
| 1079 |
<div className="mt-2 pt-2 border-t border-white/[0.04] flex items-center justify-between text-[11px] text-neutral-400 font-medium">
|
| 1080 |
-
<div className="flex items-center gap-
|
| 1081 |
-
<
|
| 1082 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1083 |
</div>
|
| 1084 |
{camp.batch_number && camp.batch_number > 1 && (
|
| 1085 |
<span className="text-[9px] font-mono text-neutral-500">Batch #{camp.batch_number}</span>
|
|
@@ -1161,6 +1257,38 @@ export default function CampaignsPage() {
|
|
| 1161 |
</span>
|
| 1162 |
</>
|
| 1163 |
)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1164 |
</div>
|
| 1165 |
</div>
|
| 1166 |
</div>
|
|
@@ -1481,6 +1609,129 @@ export default function CampaignsPage() {
|
|
| 1481 |
</div>
|
| 1482 |
</div>
|
| 1483 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1484 |
{/* Dual Column: Message/Media Payload (Left) & Target Audience (Right) */}
|
| 1485 |
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 pt-1">
|
| 1486 |
{/* Left Column: Media Attachment & Caption Payload */}
|
|
@@ -1797,6 +2048,16 @@ export default function CampaignsPage() {
|
|
| 1797 |
>
|
| 1798 |
<span>✕ Restricted</span>
|
| 1799 |
</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1800 |
</div>
|
| 1801 |
</div>
|
| 1802 |
<div className="flex items-center gap-1">
|
|
@@ -1851,8 +2112,20 @@ export default function CampaignsPage() {
|
|
| 1851 |
<p className="text-[9px] text-foreground/35">ID: {d.id}</p>
|
| 1852 |
</div>
|
| 1853 |
</div>
|
| 1854 |
-
<div className=
|
| 1855 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1856 |
</div>
|
| 1857 |
</div>
|
| 1858 |
))
|
|
@@ -1959,6 +2232,165 @@ export default function CampaignsPage() {
|
|
| 1959 |
</div>
|
| 1960 |
</div>
|
| 1961 |
)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1962 |
</div>
|
| 1963 |
);
|
| 1964 |
}
|
|
|
|
| 33 |
Zap,
|
| 34 |
Filter,
|
| 35 |
Smartphone,
|
| 36 |
+
Eye,
|
| 37 |
+
Info,
|
| 38 |
+
AlertTriangle,
|
| 39 |
+
Shield
|
| 40 |
} from 'lucide-react';
|
| 41 |
import { apiFetch, getApiBase } from '@/lib/auth';
|
| 42 |
import { Preloader } from '@/components/Preloader';
|
|
|
|
| 112 |
message: '',
|
| 113 |
interval_hours: '0',
|
| 114 |
interval_minutes: '0',
|
| 115 |
+
media_url: '',
|
| 116 |
+
speed_mode: 'balanced'
|
| 117 |
});
|
| 118 |
const [mediaFiles, setMediaFiles] = useState<File[]>([]);
|
| 119 |
const [mediaPreviews, setMediaPreviews] = useState<string[]>([]);
|
|
|
|
| 126 |
const [isSpintaxModalOpen, setIsSpintaxModalOpen] = useState(false);
|
| 127 |
const [isAiAssistantOpen, setIsAiAssistantOpen] = useState(false);
|
| 128 |
const [isAccountDropdownOpen, setIsAccountDropdownOpen] = useState(false);
|
| 129 |
+
const [groupPermissionFilter, setGroupPermissionFilter] = useState<'all' | 'sendable' | 'restricted' | 'blacklisted'>('all');
|
| 130 |
+
const [showSpeedInfo, setShowSpeedInfo] = useState(false);
|
| 131 |
+
const [reviewSweepModal, setReviewSweepModal] = useState<any | null>(null);
|
| 132 |
+
const [selectedDeletedToBlacklist, setSelectedDeletedToBlacklist] = useState<string[]>([]);
|
| 133 |
+
const [isBlacklisting, setIsBlacklisting] = useState(false);
|
| 134 |
|
| 135 |
// Live Cadence Countdown Clock & Media Preview Lightbox State
|
| 136 |
const [nowTime, setNowTime] = useState<number>(Date.now());
|
|
|
|
| 292 |
} catch (e) { }
|
| 293 |
};
|
| 294 |
|
| 295 |
+
const handleUnblacklist = async (groupId: string, e?: React.MouseEvent) => {
|
| 296 |
+
if (e) e.stopPropagation();
|
| 297 |
+
try {
|
| 298 |
+
const res = await apiFetch('/api/users/permanent-excludes/remove', {
|
| 299 |
+
method: 'POST',
|
| 300 |
+
headers: { 'Content-Type': 'application/json' },
|
| 301 |
+
body: JSON.stringify({ id: groupId })
|
| 302 |
+
});
|
| 303 |
+
if (res.ok) {
|
| 304 |
+
const data = await res.json();
|
| 305 |
+
const newIds = data.ids || permanentExcludes.filter(id => id !== groupId);
|
| 306 |
+
setPermanentExcludes(newIds);
|
| 307 |
+
setExcludedGroups(newIds);
|
| 308 |
+
}
|
| 309 |
+
} catch (err) {
|
| 310 |
+
console.error("Failed to unblacklist group:", err);
|
| 311 |
+
}
|
| 312 |
+
};
|
| 313 |
+
|
| 314 |
+
const handleBlacklistSweepGroups = async () => {
|
| 315 |
+
if (selectedDeletedToBlacklist.length === 0) return;
|
| 316 |
+
setIsBlacklisting(true);
|
| 317 |
+
try {
|
| 318 |
+
const res = await apiFetch('/api/users/permanent-excludes/add', {
|
| 319 |
+
method: 'POST',
|
| 320 |
+
headers: { 'Content-Type': 'application/json' },
|
| 321 |
+
body: JSON.stringify({ ids: selectedDeletedToBlacklist })
|
| 322 |
+
});
|
| 323 |
+
if (res.ok) {
|
| 324 |
+
const data = await res.json();
|
| 325 |
+
const newIds = data.ids || [...permanentExcludes, ...selectedDeletedToBlacklist];
|
| 326 |
+
setPermanentExcludes(newIds);
|
| 327 |
+
setExcludedGroups(newIds);
|
| 328 |
+
setReviewSweepModal(null);
|
| 329 |
+
setSelectedDeletedToBlacklist([]);
|
| 330 |
+
}
|
| 331 |
+
} catch (err) {
|
| 332 |
+
console.error("Failed to blacklist sweep groups:", err);
|
| 333 |
+
} finally {
|
| 334 |
+
setIsBlacklisting(false);
|
| 335 |
+
}
|
| 336 |
+
};
|
| 337 |
+
|
| 338 |
const fetchAccounts = async () => {
|
| 339 |
try {
|
| 340 |
const res = await apiFetch('/api/telegram/accounts');
|
|
|
|
| 489 |
groups: selectedGroups,
|
| 490 |
target_groups: selectedGroups,
|
| 491 |
exclude_groups: excludedGroups,
|
| 492 |
+
media_url: finalMediaUrl || null,
|
| 493 |
+
speed_mode: campaignData.speed_mode || 'balanced'
|
| 494 |
})
|
| 495 |
});
|
| 496 |
if (res.ok) {
|
|
|
|
| 501 |
setSuccess(false);
|
| 502 |
setIsCreating(false);
|
| 503 |
setEditingId(null);
|
| 504 |
+
setCampaignData({ name: '', phone_number: '', schedule_time: '', message: '', interval_hours: '0', interval_minutes: '0', media_url: '', speed_mode: 'balanced' });
|
| 505 |
setMediaFiles([]);
|
| 506 |
setMediaPreviews([]);
|
| 507 |
setSelectedGroups([]);
|
|
|
|
| 532 |
message: camp.message_text || camp.message || '',
|
| 533 |
interval_hours: (camp.interval_hours || 0).toString(),
|
| 534 |
interval_minutes: (camp.interval_minutes || 0).toString(),
|
| 535 |
+
media_url: camp.media_url || '',
|
| 536 |
+
speed_mode: camp.speed_mode || 'balanced'
|
| 537 |
});
|
| 538 |
|
| 539 |
// Parse multiple media URLs if stored as JSON list or comma separated
|
|
|
|
| 582 |
|
| 583 |
const openNewCampaignModal = () => {
|
| 584 |
setEditingId(null);
|
| 585 |
+
setCampaignData({ name: '', phone_number: accounts[0]?.phone_number || '', schedule_time: '', message: '', interval_hours: '0', interval_minutes: '0', media_url: '', speed_mode: 'balanced' });
|
| 586 |
setMediaFiles([]);
|
| 587 |
setMediaPreviews([]);
|
| 588 |
setSelectedGroups([]);
|
|
|
|
| 638 |
const matchesType = filterType === 'all' ||
|
| 639 |
(filterType === 'channels' && (d.is_channel || d.type === 'channel')) ||
|
| 640 |
(filterType === 'groups' && (!d.is_channel && d.type !== 'channel'));
|
| 641 |
+
|
| 642 |
+
if (groupPermissionFilter === 'blacklisted') {
|
| 643 |
+
return matchesSearch && isExcluded && matchesType;
|
| 644 |
+
}
|
| 645 |
+
|
| 646 |
const matchesPermission = groupPermissionFilter === 'all' ||
|
| 647 |
(groupPermissionFilter === 'sendable' && d.can_send !== false) ||
|
| 648 |
(groupPermissionFilter === 'restricted' && d.can_send === false);
|
|
|
|
| 1127 |
</div>
|
| 1128 |
</div>
|
| 1129 |
|
| 1130 |
+
{/* Delivery Sweep Audit Banner */}
|
| 1131 |
+
{camp.sweep_status === 'sweeping' && (
|
| 1132 |
+
<div className="mt-2 px-2.5 py-1.5 rounded-lg bg-sky-500/10 border border-sky-500/20 flex items-center justify-between text-[11px] text-sky-300">
|
| 1133 |
+
<div className="flex items-center gap-1.5 font-medium">
|
| 1134 |
+
<Loader2 size={12} className="animate-spin text-sky-400" />
|
| 1135 |
+
<span>Verifying delivery across groups...</span>
|
| 1136 |
+
</div>
|
| 1137 |
+
<span className="text-[9px] uppercase tracking-wider font-bold text-sky-400/80">Sweep Active</span>
|
| 1138 |
+
</div>
|
| 1139 |
+
)}
|
| 1140 |
+
{camp.deleted_groups && camp.deleted_groups.length > 0 && (
|
| 1141 |
+
<div className="mt-2 px-2.5 py-1.5 rounded-lg bg-rose-500/10 border border-rose-500/25 flex items-center justify-between text-[11px] text-rose-300">
|
| 1142 |
+
<div className="flex items-center gap-1.5 font-semibold">
|
| 1143 |
+
<AlertTriangle size={12} className="text-rose-400 shrink-0" />
|
| 1144 |
+
<span>{camp.deleted_groups.length} {camp.deleted_groups.length === 1 ? 'Message' : 'Messages'} Removed</span>
|
| 1145 |
+
</div>
|
| 1146 |
+
<button
|
| 1147 |
+
type="button"
|
| 1148 |
+
onClick={() => {
|
| 1149 |
+
setReviewSweepModal(camp);
|
| 1150 |
+
const allIds = (camp.deleted_groups || []).map((x: any) => typeof x === 'object' ? x.id : x);
|
| 1151 |
+
setSelectedDeletedToBlacklist(allIds);
|
| 1152 |
+
}}
|
| 1153 |
+
className="px-2 py-0.5 rounded-md bg-rose-500/20 hover:bg-rose-500/30 text-rose-300 text-[10px] font-bold border border-rose-500/40 transition-all cursor-pointer active:scale-95 flex items-center gap-1"
|
| 1154 |
+
>
|
| 1155 |
+
<span>Review & Blacklist</span>
|
| 1156 |
+
<ChevronRight size={10} />
|
| 1157 |
+
</button>
|
| 1158 |
+
</div>
|
| 1159 |
+
)}
|
| 1160 |
+
|
| 1161 |
{/* Message Snippet */}
|
| 1162 |
<div className="mt-2 px-2.5 py-1 rounded-lg bg-white/[0.02] text-[10px] text-neutral-400 font-mono truncate leading-normal">
|
| 1163 |
"{camp.message_text || camp.message || '...'}"
|
| 1164 |
</div>
|
| 1165 |
</div>
|
| 1166 |
|
| 1167 |
+
{/* Footer: Target Entities & Speed Mode */}
|
| 1168 |
<div className="mt-2 pt-2 border-t border-white/[0.04] flex items-center justify-between text-[11px] text-neutral-400 font-medium">
|
| 1169 |
+
<div className="flex items-center gap-2">
|
| 1170 |
+
<div className="flex items-center gap-1.5">
|
| 1171 |
+
<Users size={11} className="text-neutral-500" />
|
| 1172 |
+
<span>{parsedGroups.length} Telegram {parsedGroups.length === 1 ? 'Target' : 'Targets'}</span>
|
| 1173 |
+
</div>
|
| 1174 |
+
{camp.speed_mode && (
|
| 1175 |
+
<span className="text-[9px] font-mono px-1.5 py-0.2 rounded bg-white/5 text-amber-400 border border-white/5">
|
| 1176 |
+
{camp.speed_mode === 'turbo' ? '⚡ Turbo' : camp.speed_mode === 'stealth' ? '🛡️ Stealth' : camp.speed_mode === 'ultra' ? '🐢 Ultra-Safe' : '⚖️ Balanced'}
|
| 1177 |
+
</span>
|
| 1178 |
+
)}
|
| 1179 |
</div>
|
| 1180 |
{camp.batch_number && camp.batch_number > 1 && (
|
| 1181 |
<span className="text-[9px] font-mono text-neutral-500">Batch #{camp.batch_number}</span>
|
|
|
|
| 1257 |
</span>
|
| 1258 |
</>
|
| 1259 |
)}
|
| 1260 |
+
{camp.speed_mode && (
|
| 1261 |
+
<>
|
| 1262 |
+
<span>•</span>
|
| 1263 |
+
<span className="text-amber-400 font-mono text-[10px]">
|
| 1264 |
+
{camp.speed_mode === 'turbo' ? '⚡ Turbo' : camp.speed_mode === 'stealth' ? '🛡️ Stealth' : camp.speed_mode === 'ultra' ? '🐢 Ultra-Safe' : '⚖️ Balanced'}
|
| 1265 |
+
</span>
|
| 1266 |
+
</>
|
| 1267 |
+
)}
|
| 1268 |
+
{camp.sweep_status === 'sweeping' && (
|
| 1269 |
+
<>
|
| 1270 |
+
<span>•</span>
|
| 1271 |
+
<span className="text-sky-400 font-semibold flex items-center gap-1 animate-pulse">
|
| 1272 |
+
<Loader2 size={10} className="animate-spin" /> Verifying delivery...
|
| 1273 |
+
</span>
|
| 1274 |
+
</>
|
| 1275 |
+
)}
|
| 1276 |
+
{camp.deleted_groups && camp.deleted_groups.length > 0 && (
|
| 1277 |
+
<>
|
| 1278 |
+
<span>•</span>
|
| 1279 |
+
<button
|
| 1280 |
+
type="button"
|
| 1281 |
+
onClick={() => {
|
| 1282 |
+
setReviewSweepModal(camp);
|
| 1283 |
+
const allIds = (camp.deleted_groups || []).map((x: any) => typeof x === 'object' ? x.id : x);
|
| 1284 |
+
setSelectedDeletedToBlacklist(allIds);
|
| 1285 |
+
}}
|
| 1286 |
+
className="text-rose-400 hover:text-rose-300 font-bold flex items-center gap-1 bg-rose-500/10 hover:bg-rose-500/20 px-1.5 py-0.5 rounded border border-rose-500/30 transition-all cursor-pointer"
|
| 1287 |
+
>
|
| 1288 |
+
<AlertTriangle size={10} /> {camp.deleted_groups.length} Removed (Review)
|
| 1289 |
+
</button>
|
| 1290 |
+
</>
|
| 1291 |
+
)}
|
| 1292 |
</div>
|
| 1293 |
</div>
|
| 1294 |
</div>
|
|
|
|
| 1609 |
</div>
|
| 1610 |
</div>
|
| 1611 |
|
| 1612 |
+
{/* Anti-Ban Delivery Speed Selector with Clickable Info Popover */}
|
| 1613 |
+
<div className="p-3 bg-foreground/[0.02] border border-border/70 rounded-xl space-y-2">
|
| 1614 |
+
<div className="flex items-center justify-between">
|
| 1615 |
+
<div className="flex items-center gap-1.5">
|
| 1616 |
+
<Zap size={13} className="text-amber-400" />
|
| 1617 |
+
<label className="text-[11px] font-bold text-foreground/70 uppercase tracking-wider">
|
| 1618 |
+
Anti-Ban Delivery Speed
|
| 1619 |
+
</label>
|
| 1620 |
+
<span className="text-[10px] text-foreground/40 font-normal">
|
| 1621 |
+
(Delay between groups)
|
| 1622 |
+
</span>
|
| 1623 |
+
</div>
|
| 1624 |
+
<button
|
| 1625 |
+
type="button"
|
| 1626 |
+
onClick={() => setShowSpeedInfo(!showSpeedInfo)}
|
| 1627 |
+
className="flex items-center gap-1 text-[11px] font-semibold text-indigo-400 hover:text-indigo-300 bg-indigo-500/10 hover:bg-indigo-500/15 px-2 py-0.5 rounded-lg border border-indigo-500/20 transition-all cursor-pointer"
|
| 1628 |
+
>
|
| 1629 |
+
<Info size={12} />
|
| 1630 |
+
<span>{showSpeedInfo ? 'Hide Details' : 'What do these mean?'}</span>
|
| 1631 |
+
</button>
|
| 1632 |
+
</div>
|
| 1633 |
+
|
| 1634 |
+
{/* 4 Speed Mode Cards */}
|
| 1635 |
+
<div className="grid grid-cols-2 sm:grid-cols-4 gap-2">
|
| 1636 |
+
{[
|
| 1637 |
+
{ id: 'turbo', name: '⚡ Turbo', interval: '20s - 30s', tag: 'Fastest', border: 'border-amber-500/40', active: 'bg-amber-500/15 border-amber-500 text-amber-300' },
|
| 1638 |
+
{ id: 'balanced', name: '⚖️ Balanced', interval: '25s - 40s', tag: 'Recommended', border: 'border-indigo-500/40', active: 'bg-indigo-500/15 border-indigo-500 text-indigo-300' },
|
| 1639 |
+
{ id: 'stealth', name: '🛡️ Stealth', interval: '45s - 70s', tag: 'Safe Spacing', border: 'border-emerald-500/40', active: 'bg-emerald-500/15 border-emerald-500 text-emerald-300' },
|
| 1640 |
+
{ id: 'ultra', name: '🐢 Ultra-Safe', interval: '75s - 120s', tag: 'Max Guard', border: 'border-blue-500/40', active: 'bg-blue-500/15 border-blue-500 text-blue-300' }
|
| 1641 |
+
].map((s) => {
|
| 1642 |
+
const isSelected = (campaignData.speed_mode || 'balanced') === s.id;
|
| 1643 |
+
return (
|
| 1644 |
+
<button
|
| 1645 |
+
key={s.id}
|
| 1646 |
+
type="button"
|
| 1647 |
+
onClick={() => setCampaignData(prev => ({ ...prev, speed_mode: s.id }))}
|
| 1648 |
+
className={`p-2.5 rounded-xl border text-left transition-all cursor-pointer relative ${
|
| 1649 |
+
isSelected
|
| 1650 |
+
? `${s.active} shadow-sm ring-1 ring-white/10`
|
| 1651 |
+
: 'bg-card/40 border-border/60 hover:bg-foreground/[0.03]'
|
| 1652 |
+
}`}
|
| 1653 |
+
>
|
| 1654 |
+
<div className="flex items-center justify-between mb-1">
|
| 1655 |
+
<span className="text-xs font-bold text-foreground">{s.name}</span>
|
| 1656 |
+
{isSelected && <Check size={12} className="shrink-0" />}
|
| 1657 |
+
</div>
|
| 1658 |
+
<div className="text-[10px] text-foreground/70 font-mono font-semibold">{s.interval}</div>
|
| 1659 |
+
<span className="text-[9px] font-semibold opacity-60">{s.tag}</span>
|
| 1660 |
+
</button>
|
| 1661 |
+
);
|
| 1662 |
+
})}
|
| 1663 |
+
</div>
|
| 1664 |
+
|
| 1665 |
+
{/* Expandable Clickable Info Popover */}
|
| 1666 |
+
{showSpeedInfo && (
|
| 1667 |
+
<div className="p-3.5 bg-background/95 border border-indigo-500/30 rounded-xl space-y-2.5 mt-2 text-xs shadow-xl animate-in fade-in slide-in-from-top-1 duration-150">
|
| 1668 |
+
<div className="flex items-center justify-between border-b border-border/50 pb-1.5">
|
| 1669 |
+
<span className="font-bold text-foreground flex items-center gap-1.5">
|
| 1670 |
+
<Info size={13} className="text-indigo-400" />
|
| 1671 |
+
Speed Comparison & Anti-Ban Guide
|
| 1672 |
+
</span>
|
| 1673 |
+
<button
|
| 1674 |
+
type="button"
|
| 1675 |
+
onClick={() => setShowSpeedInfo(false)}
|
| 1676 |
+
className="text-[10px] text-foreground/40 hover:text-foreground cursor-pointer px-1 py-0.5 rounded hover:bg-foreground/5"
|
| 1677 |
+
>
|
| 1678 |
+
✕ Close
|
| 1679 |
+
</button>
|
| 1680 |
+
</div>
|
| 1681 |
+
<div className="grid grid-cols-1 sm:grid-cols-2 gap-2.5 pt-1 text-[11px]">
|
| 1682 |
+
<div className="p-2.5 rounded-lg bg-foreground/[0.02] border border-border/50 space-y-1">
|
| 1683 |
+
<div className="font-bold text-amber-400 flex items-center gap-1">
|
| 1684 |
+
⚡ Turbo (20s - 30s)
|
| 1685 |
+
</div>
|
| 1686 |
+
<p className="text-foreground/70 leading-relaxed">
|
| 1687 |
+
~50 groups in 20-25 mins. Best for urgent time-sensitive announcements on aged accounts.
|
| 1688 |
+
</p>
|
| 1689 |
+
<p className="text-[10px] text-amber-500/80 font-medium">
|
| 1690 |
+
⚠️ Caution: Elevated risk of Telegram flood limits if message lacks Spintax.
|
| 1691 |
+
</p>
|
| 1692 |
+
</div>
|
| 1693 |
+
<div className="p-2.5 rounded-lg bg-indigo-500/5 border border-indigo-500/25 space-y-1">
|
| 1694 |
+
<div className="font-bold text-indigo-400 flex items-center gap-1">
|
| 1695 |
+
⚖️ Balanced (25s - 40s) <span className="text-[9px] px-1 bg-indigo-500/20 rounded font-semibold">Recommended</span>
|
| 1696 |
+
</div>
|
| 1697 |
+
<p className="text-foreground/70 leading-relaxed">
|
| 1698 |
+
~50 groups in 25-30 mins. Optimal blend of rapid distribution and low Telegram spam footprint.
|
| 1699 |
+
</p>
|
| 1700 |
+
<p className="text-[10px] text-indigo-400/90 font-medium">
|
| 1701 |
+
✅ Recommended default for daily marketing.
|
| 1702 |
+
</p>
|
| 1703 |
+
</div>
|
| 1704 |
+
<div className="p-2.5 rounded-lg bg-foreground/[0.02] border border-border/50 space-y-1">
|
| 1705 |
+
<div className="font-bold text-emerald-400 flex items-center gap-1">
|
| 1706 |
+
🛡️ Stealth (45s - 70s)
|
| 1707 |
+
</div>
|
| 1708 |
+
<p className="text-foreground/70 leading-relaxed">
|
| 1709 |
+
~50 groups in ~45 mins. Mimics human spacing with randomized typing status.
|
| 1710 |
+
</p>
|
| 1711 |
+
<p className="text-[10px] text-emerald-500/80 font-medium">
|
| 1712 |
+
🛡️ Ideal for accounts recovering from previous restrictions.
|
| 1713 |
+
</p>
|
| 1714 |
+
</div>
|
| 1715 |
+
<div className="p-2.5 rounded-lg bg-foreground/[0.02] border border-border/50 space-y-1">
|
| 1716 |
+
<div className="font-bold text-blue-400 flex items-center gap-1">
|
| 1717 |
+
🐢 Ultra-Safe (75s - 120s)
|
| 1718 |
+
</div>
|
| 1719 |
+
<p className="text-foreground/70 leading-relaxed">
|
| 1720 |
+
~50 groups in ~1.5 hours. Maximum gap between posts with human typing simulation.
|
| 1721 |
+
</p>
|
| 1722 |
+
<p className="text-[10px] text-blue-400/80 font-medium">
|
| 1723 |
+
🔒 Highest account longevity. Best for groups with strict moderators.
|
| 1724 |
+
</p>
|
| 1725 |
+
</div>
|
| 1726 |
+
</div>
|
| 1727 |
+
<div className="text-[10px] text-foreground/50 italic pt-1.5 border-t border-border/40 flex items-center gap-1">
|
| 1728 |
+
<span>💡 Tip:</span>
|
| 1729 |
+
<span>Arkitel actively checks before posting and skips groups where your account was already the last sender (Consecutive Post Shield).</span>
|
| 1730 |
+
</div>
|
| 1731 |
+
</div>
|
| 1732 |
+
)}
|
| 1733 |
+
</div>
|
| 1734 |
+
|
| 1735 |
{/* Dual Column: Message/Media Payload (Left) & Target Audience (Right) */}
|
| 1736 |
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 pt-1">
|
| 1737 |
{/* Left Column: Media Attachment & Caption Payload */}
|
|
|
|
| 2048 |
>
|
| 2049 |
<span>✕ Restricted</span>
|
| 2050 |
</button>
|
| 2051 |
+
<button
|
| 2052 |
+
type="button"
|
| 2053 |
+
onClick={() => { setGroupPermissionFilter('blacklisted'); setCurrentPage(1); }}
|
| 2054 |
+
className={`px-1.5 py-0.5 rounded text-[9px] font-bold transition-all cursor-pointer flex items-center gap-0.5 ${
|
| 2055 |
+
groupPermissionFilter === 'blacklisted' ? 'bg-amber-600 text-white shadow-xs' : 'text-amber-400 hover:text-amber-300'
|
| 2056 |
+
}`}
|
| 2057 |
+
title="Groups on the permanent exclude blacklist"
|
| 2058 |
+
>
|
| 2059 |
+
<span>🚫 Blacklisted ({permanentExcludes.length})</span>
|
| 2060 |
+
</button>
|
| 2061 |
</div>
|
| 2062 |
</div>
|
| 2063 |
<div className="flex items-center gap-1">
|
|
|
|
| 2112 |
<p className="text-[9px] text-foreground/35">ID: {d.id}</p>
|
| 2113 |
</div>
|
| 2114 |
</div>
|
| 2115 |
+
<div className="flex items-center gap-1.5 shrink-0">
|
| 2116 |
+
{permanentExcludes.includes(d.id) && (
|
| 2117 |
+
<button
|
| 2118 |
+
type="button"
|
| 2119 |
+
onClick={(e) => handleUnblacklist(d.id, e)}
|
| 2120 |
+
className="px-2 py-0.5 text-[10px] font-bold rounded-lg bg-amber-500/15 hover:bg-amber-500/25 text-amber-300 border border-amber-500/30 transition-all cursor-pointer active:scale-95"
|
| 2121 |
+
title="Remove from permanent blacklist and restore to regular list"
|
| 2122 |
+
>
|
| 2123 |
+
Unblacklist
|
| 2124 |
+
</button>
|
| 2125 |
+
)}
|
| 2126 |
+
<div className={`w-3.5 h-3.5 rounded border shrink-0 flex items-center justify-center ${selectedGroups.includes(d.id) ? 'bg-indigo-500 border-indigo-500 text-white' : excludedGroups.includes(d.id) ? 'bg-red-500 border-red-500 text-white' : 'border-border/80'}`}>
|
| 2127 |
+
{(selectedGroups.includes(d.id) || excludedGroups.includes(d.id)) && <Check size={9} strokeWidth={3} />}
|
| 2128 |
+
</div>
|
| 2129 |
</div>
|
| 2130 |
</div>
|
| 2131 |
))
|
|
|
|
| 2232 |
</div>
|
| 2233 |
</div>
|
| 2234 |
)}
|
| 2235 |
+
|
| 2236 |
+
{/* Delivery Audit & Removed Messages Review Modal */}
|
| 2237 |
+
{reviewSweepModal && (
|
| 2238 |
+
<div
|
| 2239 |
+
className="fixed inset-0 bg-black/80 backdrop-blur-sm z-[150] flex items-center justify-center p-4 animate-in fade-in duration-200"
|
| 2240 |
+
onClick={() => setReviewSweepModal(null)}
|
| 2241 |
+
>
|
| 2242 |
+
<div
|
| 2243 |
+
className="bg-[#111317] border border-white/10 rounded-2xl max-w-lg w-full max-h-[85vh] overflow-hidden flex flex-col shadow-2xl animate-in zoom-in-95 duration-200"
|
| 2244 |
+
onClick={(e) => e.stopPropagation()}
|
| 2245 |
+
>
|
| 2246 |
+
{/* Header */}
|
| 2247 |
+
<div className="p-4 px-5 border-b border-white/10 flex items-center justify-between bg-white/[0.02]">
|
| 2248 |
+
<div className="flex items-center gap-2.5">
|
| 2249 |
+
<div className="w-8 h-8 rounded-lg bg-rose-500/10 border border-rose-500/20 flex items-center justify-center text-rose-400 shrink-0">
|
| 2250 |
+
<AlertTriangle size={16} />
|
| 2251 |
+
</div>
|
| 2252 |
+
<div>
|
| 2253 |
+
<h3 className="text-sm font-bold text-white">
|
| 2254 |
+
Delivery Audit: Removed Messages
|
| 2255 |
+
</h3>
|
| 2256 |
+
<p className="text-[10px] text-neutral-400 truncate max-w-xs">
|
| 2257 |
+
{reviewSweepModal.name || 'Campaign'} • {reviewSweepModal.deleted_groups?.length || 0} groups deleted your post
|
| 2258 |
+
</p>
|
| 2259 |
+
</div>
|
| 2260 |
+
</div>
|
| 2261 |
+
<button
|
| 2262 |
+
onClick={() => setReviewSweepModal(null)}
|
| 2263 |
+
className="p-1.5 rounded-lg text-neutral-400 hover:text-white hover:bg-white/10 transition-colors cursor-pointer"
|
| 2264 |
+
>
|
| 2265 |
+
<X size={16} />
|
| 2266 |
+
</button>
|
| 2267 |
+
</div>
|
| 2268 |
+
|
| 2269 |
+
{/* Explanation & Account Reputation Warning */}
|
| 2270 |
+
<div className="p-3.5 bg-rose-500/10 border-b border-rose-500/20 text-xs text-rose-200/90 space-y-1">
|
| 2271 |
+
<div className="flex items-center gap-1.5 font-bold text-rose-400">
|
| 2272 |
+
<Shield size={13} />
|
| 2273 |
+
<span>Anti-Ban Recommendation</span>
|
| 2274 |
+
</div>
|
| 2275 |
+
<p className="text-[11px] text-rose-200/80 leading-relaxed">
|
| 2276 |
+
The groups below deleted your broadcast message shortly after delivery. Posting repeatedly in groups that auto-remove ads causes bots/admins to flag your Telegram account, resulting in SpamBot bans. Add them to your blacklist to protect your account.
|
| 2277 |
+
</p>
|
| 2278 |
+
</div>
|
| 2279 |
+
|
| 2280 |
+
{/* Selection Toolbar */}
|
| 2281 |
+
<div className="p-3 px-5 border-b border-white/5 flex items-center justify-between bg-white/[0.01]">
|
| 2282 |
+
<span className="text-[11px] font-bold text-neutral-400 uppercase tracking-wider">
|
| 2283 |
+
Select Groups ({selectedDeletedToBlacklist.length} / {reviewSweepModal.deleted_groups?.length || 0})
|
| 2284 |
+
</span>
|
| 2285 |
+
<div className="flex items-center gap-2">
|
| 2286 |
+
<button
|
| 2287 |
+
type="button"
|
| 2288 |
+
onClick={() => {
|
| 2289 |
+
const allIds = (reviewSweepModal.deleted_groups || []).map((x: any) => typeof x === 'object' ? x.id : x);
|
| 2290 |
+
setSelectedDeletedToBlacklist(allIds);
|
| 2291 |
+
}}
|
| 2292 |
+
className="text-[10px] font-bold text-indigo-400 hover:text-indigo-300 transition-colors cursor-pointer"
|
| 2293 |
+
>
|
| 2294 |
+
Select All
|
| 2295 |
+
</button>
|
| 2296 |
+
<span className="text-neutral-600 text-xs">•</span>
|
| 2297 |
+
<button
|
| 2298 |
+
type="button"
|
| 2299 |
+
onClick={() => setSelectedDeletedToBlacklist([])}
|
| 2300 |
+
className="text-[10px] font-bold text-neutral-400 hover:text-white transition-colors cursor-pointer"
|
| 2301 |
+
>
|
| 2302 |
+
Deselect All
|
| 2303 |
+
</button>
|
| 2304 |
+
</div>
|
| 2305 |
+
</div>
|
| 2306 |
+
|
| 2307 |
+
{/* Group List */}
|
| 2308 |
+
<div className="flex-1 overflow-y-auto p-4 space-y-2 custom-scrollbar max-h-72">
|
| 2309 |
+
{(reviewSweepModal.deleted_groups || []).map((item: any, idx: number) => {
|
| 2310 |
+
const gid = typeof item === 'object' ? item.id : item;
|
| 2311 |
+
const gname = typeof item === 'object' ? (item.name || item.id) : item;
|
| 2312 |
+
const greason = typeof item === 'object' ? item.reason : 'Removed by group bot';
|
| 2313 |
+
const isSelected = selectedDeletedToBlacklist.includes(gid);
|
| 2314 |
+
const alreadyBlacklisted = permanentExcludes.includes(gid);
|
| 2315 |
+
|
| 2316 |
+
return (
|
| 2317 |
+
<div
|
| 2318 |
+
key={idx}
|
| 2319 |
+
onClick={() => {
|
| 2320 |
+
if (alreadyBlacklisted) return;
|
| 2321 |
+
setSelectedDeletedToBlacklist(prev =>
|
| 2322 |
+
prev.includes(gid) ? prev.filter(id => id !== gid) : [...prev, gid]
|
| 2323 |
+
);
|
| 2324 |
+
}}
|
| 2325 |
+
className={`p-2.5 rounded-xl border transition-all flex items-center justify-between cursor-pointer ${
|
| 2326 |
+
alreadyBlacklisted
|
| 2327 |
+
? 'bg-white/[0.02] border-white/5 opacity-50 cursor-not-allowed'
|
| 2328 |
+
: isSelected
|
| 2329 |
+
? 'bg-rose-500/10 border-rose-500/30'
|
| 2330 |
+
: 'bg-white/[0.02] border-white/5 hover:bg-white/[0.04]'
|
| 2331 |
+
}`}
|
| 2332 |
+
>
|
| 2333 |
+
<div className="flex items-center gap-2.5 min-w-0 flex-1">
|
| 2334 |
+
<div className={`w-7 h-7 rounded-lg flex items-center justify-center text-xs font-bold shrink-0 ${
|
| 2335 |
+
isSelected ? 'bg-rose-500 text-white' : 'bg-white/5 text-neutral-400'
|
| 2336 |
+
}`}>
|
| 2337 |
+
{gname?.charAt(0) || '?'}
|
| 2338 |
+
</div>
|
| 2339 |
+
<div className="min-w-0 flex-1">
|
| 2340 |
+
<div className="flex items-center gap-1.5">
|
| 2341 |
+
<p className="text-xs font-semibold text-white truncate">{gname}</p>
|
| 2342 |
+
{alreadyBlacklisted && (
|
| 2343 |
+
<span className="text-[9px] font-bold px-1.5 py-0.2 rounded bg-amber-500/20 text-amber-300">
|
| 2344 |
+
Already Blacklisted
|
| 2345 |
+
</span>
|
| 2346 |
+
)}
|
| 2347 |
+
</div>
|
| 2348 |
+
<p className="text-[10px] text-rose-400/80 font-medium">{greason}</p>
|
| 2349 |
+
</div>
|
| 2350 |
+
</div>
|
| 2351 |
+
{!alreadyBlacklisted && (
|
| 2352 |
+
<div className={`w-4 h-4 rounded border shrink-0 flex items-center justify-center transition-all ${
|
| 2353 |
+
isSelected ? 'bg-rose-500 border-rose-500 text-white' : 'border-neutral-600'
|
| 2354 |
+
}`}>
|
| 2355 |
+
{isSelected && <Check size={10} strokeWidth={3} />}
|
| 2356 |
+
</div>
|
| 2357 |
+
)}
|
| 2358 |
+
</div>
|
| 2359 |
+
);
|
| 2360 |
+
})}
|
| 2361 |
+
</div>
|
| 2362 |
+
|
| 2363 |
+
{/* Footer */}
|
| 2364 |
+
<div className="p-3.5 px-5 border-t border-white/10 flex items-center justify-between bg-white/[0.01]">
|
| 2365 |
+
<button
|
| 2366 |
+
type="button"
|
| 2367 |
+
onClick={() => setReviewSweepModal(null)}
|
| 2368 |
+
className="px-3.5 py-1.5 rounded-lg text-xs font-semibold text-neutral-400 hover:text-white hover:bg-white/5 transition-all cursor-pointer"
|
| 2369 |
+
>
|
| 2370 |
+
Dismiss
|
| 2371 |
+
</button>
|
| 2372 |
+
<button
|
| 2373 |
+
type="button"
|
| 2374 |
+
disabled={isBlacklisting || selectedDeletedToBlacklist.length === 0}
|
| 2375 |
+
onClick={handleBlacklistSweepGroups}
|
| 2376 |
+
className="bg-rose-500 hover:bg-rose-600 disabled:opacity-40 text-white px-4 py-1.5 rounded-lg text-xs font-semibold shadow-sm transition-all active:scale-95 flex items-center gap-1.5 cursor-pointer"
|
| 2377 |
+
>
|
| 2378 |
+
{isBlacklisting ? (
|
| 2379 |
+
<>
|
| 2380 |
+
<Loader2 size={13} className="animate-spin" />
|
| 2381 |
+
<span>Saving Blacklist...</span>
|
| 2382 |
+
</>
|
| 2383 |
+
) : (
|
| 2384 |
+
<>
|
| 2385 |
+
<Shield size={13} />
|
| 2386 |
+
<span>Add {selectedDeletedToBlacklist.length} to Permanent Blacklist</span>
|
| 2387 |
+
</>
|
| 2388 |
+
)}
|
| 2389 |
+
</button>
|
| 2390 |
+
</div>
|
| 2391 |
+
</div>
|
| 2392 |
+
</div>
|
| 2393 |
+
)}
|
| 2394 |
</div>
|
| 2395 |
);
|
| 2396 |
}
|