Spaces:
Paused
Paused
CBV01 commited on
Commit ·
b4f6b0d
1
Parent(s): 0cea1f8
fix: private group entity resolution, join notification toasts, scraper/lead join fixes, and accounts/campaigns color tweaking
Browse files- backend/main.py +107 -14
- frontend/src/app/accounts/page.tsx +39 -23
- frontend/src/app/campaigns/page.tsx +51 -10
- frontend/src/app/compare/page.tsx +33 -16
- frontend/src/app/leads/page.tsx +52 -10
- frontend/src/app/scraper/page.tsx +1 -1
backend/main.py
CHANGED
|
@@ -1007,7 +1007,9 @@ class CompareAccountsRequest(BaseModel):
|
|
| 1007 |
|
| 1008 |
class SingleJoinRequest(BaseModel):
|
| 1009 |
phone_number: str
|
| 1010 |
-
target: str
|
|
|
|
|
|
|
| 1011 |
|
| 1012 |
def _normalize_tg_id(raw_id: Any) -> str:
|
| 1013 |
s = str(raw_id).strip()
|
|
@@ -1138,16 +1140,115 @@ async def compare_accounts(req: CompareAccountsRequest, user_id: str = Depends(g
|
|
| 1138 |
|
| 1139 |
@app.post("/api/telegram/join")
|
| 1140 |
async def join_single_target(req: SingleJoinRequest, user_id: str = Depends(get_current_user_id)):
|
| 1141 |
-
"""Join a single group or channel with a specific account."""
|
| 1142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1143 |
try:
|
| 1144 |
-
await smart_join(client,
|
| 1145 |
-
return {"status": "success", "message": f"Successfully joined {
|
| 1146 |
except Exception as e:
|
|
|
|
| 1147 |
err_msg = str(e)
|
| 1148 |
if "flood" in err_msg.lower():
|
| 1149 |
raise HTTPException(status_code=429, detail="Telegram rate limit (FloodWait). Please wait a few moments before joining again.")
|
| 1150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1151 |
|
| 1152 |
|
| 1153 |
@app.post("/api/telegram/qr/init")
|
|
@@ -2120,14 +2221,6 @@ class JoinRequest(BaseModel):
|
|
| 2120 |
group_id: str
|
| 2121 |
phone_number: str
|
| 2122 |
|
| 2123 |
-
@app.post("/api/telegram/join")
|
| 2124 |
-
async def join_single(req: JoinRequest, user_id: str = Depends(get_current_user_id)):
|
| 2125 |
-
try:
|
| 2126 |
-
client = await POOL.get_client(user_id, req.phone_number)
|
| 2127 |
-
await smart_join(client, req.group_id, user_id, req.phone_number)
|
| 2128 |
-
return {"status": "success"}
|
| 2129 |
-
except Exception as e:
|
| 2130 |
-
raise HTTPException(status_code=400, detail=str(e))
|
| 2131 |
|
| 2132 |
@app.post("/api/telegram/extract")
|
| 2133 |
async def extract_group_members(req: JoinRequest, user_id: str = Depends(get_current_user_id)):
|
|
|
|
| 1007 |
|
| 1008 |
class SingleJoinRequest(BaseModel):
|
| 1009 |
phone_number: str
|
| 1010 |
+
target: Optional[str] = None
|
| 1011 |
+
group_id: Optional[str] = None
|
| 1012 |
+
source_phone: Optional[str] = None
|
| 1013 |
|
| 1014 |
def _normalize_tg_id(raw_id: Any) -> str:
|
| 1015 |
s = str(raw_id).strip()
|
|
|
|
| 1140 |
|
| 1141 |
@app.post("/api/telegram/join")
|
| 1142 |
async def join_single_target(req: SingleJoinRequest, user_id: str = Depends(get_current_user_id)):
|
| 1143 |
+
"""Join a single group or channel with a specific account, with assistance for private groups."""
|
| 1144 |
+
target_str = (req.target or req.group_id or "").strip()
|
| 1145 |
+
if not target_str:
|
| 1146 |
+
raise HTTPException(status_code=400, detail="Missing target or group_id to join.")
|
| 1147 |
+
|
| 1148 |
+
phone_number = req.phone_number.strip()
|
| 1149 |
+
client = await POOL.get_client(user_id, phone_number)
|
| 1150 |
+
|
| 1151 |
+
# 1. Try standard direct join
|
| 1152 |
+
direct_err = None
|
| 1153 |
try:
|
| 1154 |
+
await smart_join(client, target_str, user_id, phone_number)
|
| 1155 |
+
return {"status": "success", "message": f"Successfully joined {target_str}"}
|
| 1156 |
except Exception as e:
|
| 1157 |
+
direct_err = e
|
| 1158 |
err_msg = str(e)
|
| 1159 |
if "flood" in err_msg.lower():
|
| 1160 |
raise HTTPException(status_code=429, detail="Telegram rate limit (FloodWait). Please wait a few moments before joining again.")
|
| 1161 |
+
log_debug(f"DIRECT_JOIN_FAILED for {target_str}: {err_msg}")
|
| 1162 |
+
|
| 1163 |
+
# 2. If direct join failed (e.g. Could not resolve entity for -100...) and source_phone is available:
|
| 1164 |
+
if req.source_phone and req.source_phone.strip() and req.source_phone.strip() != phone_number:
|
| 1165 |
+
source_phone = req.source_phone.strip()
|
| 1166 |
+
try:
|
| 1167 |
+
client_source = await POOL.get_client(user_id, source_phone)
|
| 1168 |
+
source_entity = await resolve_tg_entity(client_source, target_str)
|
| 1169 |
+
if source_entity:
|
| 1170 |
+
# If the entity actually has a public username, join by username
|
| 1171 |
+
uname = getattr(source_entity, 'username', None)
|
| 1172 |
+
if uname:
|
| 1173 |
+
try:
|
| 1174 |
+
await smart_join(client, f"@{uname}", user_id, phone_number)
|
| 1175 |
+
return {"status": "success", "message": f"Successfully joined @{uname}"}
|
| 1176 |
+
except Exception as u_err:
|
| 1177 |
+
log_debug(f"USERNAME_JOIN_FALLBACK_ERR: {u_err}")
|
| 1178 |
+
|
| 1179 |
+
# Try to extract or export invite link through the source account
|
| 1180 |
+
invite_link = None
|
| 1181 |
+
try:
|
| 1182 |
+
is_chan = getattr(source_entity, 'broadcast', False) or getattr(source_entity, 'megagroup', False)
|
| 1183 |
+
if is_chan:
|
| 1184 |
+
from telethon.tl.functions.channels import GetFullChannelRequest
|
| 1185 |
+
from telethon.tl.functions.messages import ExportChatInviteRequest
|
| 1186 |
+
full = await client_source(GetFullChannelRequest(source_entity))
|
| 1187 |
+
if hasattr(full.full_chat, 'exported_invite') and full.full_chat.exported_invite:
|
| 1188 |
+
invite_link = getattr(full.full_chat.exported_invite, 'link', None)
|
| 1189 |
+
if not invite_link:
|
| 1190 |
+
try:
|
| 1191 |
+
exp = await client_source(ExportChatInviteRequest(source_entity))
|
| 1192 |
+
invite_link = getattr(exp, 'link', None)
|
| 1193 |
+
except Exception: pass
|
| 1194 |
+
else:
|
| 1195 |
+
from telethon.tl.functions.messages import GetFullChatRequest, ExportChatInviteRequest
|
| 1196 |
+
full = await client_source(GetFullChatRequest(source_entity.id))
|
| 1197 |
+
if hasattr(full.full_chat, 'exported_invite') and full.full_chat.exported_invite:
|
| 1198 |
+
invite_link = getattr(full.full_chat.exported_invite, 'link', None)
|
| 1199 |
+
if not invite_link:
|
| 1200 |
+
try:
|
| 1201 |
+
exp = await client_source(ExportChatInviteRequest(source_entity.id))
|
| 1202 |
+
invite_link = getattr(exp, 'link', None)
|
| 1203 |
+
except Exception: pass
|
| 1204 |
+
except Exception as exp_err:
|
| 1205 |
+
log_debug(f"SOURCE_LINK_EXTRACTION_ERR: {exp_err}")
|
| 1206 |
+
|
| 1207 |
+
if invite_link:
|
| 1208 |
+
await smart_join(client, invite_link, user_id, phone_number)
|
| 1209 |
+
return {"status": "success", "message": "Successfully joined via chat invite link"}
|
| 1210 |
+
|
| 1211 |
+
# Try direct invitation via source account
|
| 1212 |
+
try:
|
| 1213 |
+
user_b = None
|
| 1214 |
+
try:
|
| 1215 |
+
user_b = await client_source.get_entity(phone_number)
|
| 1216 |
+
except Exception: pass
|
| 1217 |
+
|
| 1218 |
+
if user_b:
|
| 1219 |
+
is_chan = getattr(source_entity, 'broadcast', False) or getattr(source_entity, 'megagroup', False)
|
| 1220 |
+
if is_chan:
|
| 1221 |
+
from telethon.tl.functions.channels import InviteToChannelRequest
|
| 1222 |
+
await client_source(InviteToChannelRequest(channel=source_entity, users=[user_b]))
|
| 1223 |
+
else:
|
| 1224 |
+
from telethon.tl.functions.messages import AddChatUserRequest
|
| 1225 |
+
await client_source(AddChatUserRequest(chat_id=source_entity.id, user_id=user_b, fwd_limit=100))
|
| 1226 |
+
|
| 1227 |
+
# Record persistence in database
|
| 1228 |
+
try:
|
| 1229 |
+
conn = get_db_connection()
|
| 1230 |
+
conn.execute(
|
| 1231 |
+
"INSERT OR IGNORE INTO account_joins (user_id, phone_number, group_id) VALUES (?, ?, ?)",
|
| 1232 |
+
(user_id, phone_number, str(target_str))
|
| 1233 |
+
)
|
| 1234 |
+
if hasattr(conn, "commit"): conn.commit()
|
| 1235 |
+
if hasattr(conn, "close"): conn.close()
|
| 1236 |
+
except: pass
|
| 1237 |
+
return {"status": "success", "message": f"Account {source_phone} added {phone_number} to {getattr(source_entity, 'title', target_str)}"}
|
| 1238 |
+
except Exception as inv_err:
|
| 1239 |
+
log_debug(f"SOURCE_INVITATION_ERR: {inv_err}")
|
| 1240 |
+
except Exception as src_err:
|
| 1241 |
+
log_debug(f"SOURCE_ASSISTANCE_FAILED: {src_err}")
|
| 1242 |
+
|
| 1243 |
+
# Fallback error messaging
|
| 1244 |
+
err_str = str(direct_err)
|
| 1245 |
+
if "Could not resolve entity" in err_str:
|
| 1246 |
+
raise HTTPException(
|
| 1247 |
+
status_code=400,
|
| 1248 |
+
detail="This group/channel is private without a public link. Account has no admin permissions to export an invite link or add members."
|
| 1249 |
+
)
|
| 1250 |
+
raise HTTPException(status_code=400, detail=f"Join failed: {err_str}")
|
| 1251 |
+
|
| 1252 |
|
| 1253 |
|
| 1254 |
@app.post("/api/telegram/qr/init")
|
|
|
|
| 2221 |
group_id: str
|
| 2222 |
phone_number: str
|
| 2223 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2224 |
|
| 2225 |
@app.post("/api/telegram/extract")
|
| 2226 |
async def extract_group_members(req: JoinRequest, user_id: str = Depends(get_current_user_id)):
|
frontend/src/app/accounts/page.tsx
CHANGED
|
@@ -399,31 +399,46 @@ export default function AccountsPage() {
|
|
| 399 |
</div>
|
| 400 |
) : (
|
| 401 |
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 animate-in fade-in slide-in-from-bottom-4 duration-500">
|
| 402 |
-
{accounts.map((acc) =>
|
| 403 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 404 |
{/* Header: Status and Active Indicator */}
|
| 405 |
<div className="flex justify-between items-center mb-6">
|
| 406 |
-
<span className={`px-3 py-1 text-[8px] font-black rounded-full flex items-center gap-1.5 uppercase tracking-widest transition-all ${
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
|
|
|
|
|
|
| 415 |
</span>
|
| 416 |
|
| 417 |
<div className="flex items-center gap-2">
|
| 418 |
-
{
|
| 419 |
-
<div className="flex items-center gap-1.5 px-3 py-1 bg-
|
| 420 |
-
<Star size={10} className="fill-
|
| 421 |
-
PRIMARY
|
| 422 |
</div>
|
| 423 |
) : (
|
| 424 |
<button
|
| 425 |
onClick={() => handleSetActive(acc.phone_number)}
|
| 426 |
-
className="px-3 py-1 bg-white/5 hover:bg-
|
| 427 |
>
|
| 428 |
{actionLoading === acc.phone_number + '_active' ? <Loader2 size={8} className="animate-spin" /> : 'SET PRIMARY'}
|
| 429 |
</button>
|
|
@@ -434,18 +449,18 @@ export default function AccountsPage() {
|
|
| 434 |
{/* Profile Section - Compact */}
|
| 435 |
<div className="flex flex-col items-center mb-4">
|
| 436 |
<div className="relative mb-2 group-hover:scale-105 transition-transform duration-300">
|
| 437 |
-
<div className=
|
| 438 |
{acc.profile_photo ? (
|
| 439 |
<img
|
| 440 |
src={acc.profile_photo.startsWith('http') ? acc.profile_photo : (process.env.NEXT_PUBLIC_API_URL ? `${process.env.NEXT_PUBLIC_API_URL}${acc.profile_photo}` : `http://localhost:8000${acc.profile_photo}`)}
|
| 441 |
className="w-full h-full rounded-[0.9rem] object-cover"
|
| 442 |
onError={(e) => {
|
| 443 |
const target = e.target as any;
|
| 444 |
-
target.src = `https://ui-avatars.com/api/?name=${encodeURIComponent(acc.first_name || 'A')}&background=6366f1&color=fff`;
|
| 445 |
}}
|
| 446 |
/>
|
| 447 |
) : (
|
| 448 |
-
<div className=
|
| 449 |
<Users size={18} />
|
| 450 |
</div>
|
| 451 |
)}
|
|
@@ -454,8 +469,8 @@ export default function AccountsPage() {
|
|
| 454 |
<h4 className="text-sm font-bold text-foreground tracking-tight px-2 text-center leading-tight">
|
| 455 |
{acc.first_name || 'Neural'} {acc.last_name || 'Node'}
|
| 456 |
</h4>
|
| 457 |
-
<div className=
|
| 458 |
-
<span className="text-[8px] font-bold
|
| 459 |
</div>
|
| 460 |
</div>
|
| 461 |
|
|
@@ -479,7 +494,7 @@ export default function AccountsPage() {
|
|
| 479 |
<div className="mt-auto grid grid-cols-4 gap-2.5 pt-4 border-t border-white/5">
|
| 480 |
<button
|
| 481 |
onClick={() => handleSyncProfile(acc.phone_number)}
|
| 482 |
-
className=
|
| 483 |
title="Sync Profile"
|
| 484 |
>
|
| 485 |
{actionLoading === acc.phone_number + '_sync' ? <Loader2 size={14} className="animate-spin" /> : <CloudSync size={16} />}
|
|
@@ -535,7 +550,8 @@ export default function AccountsPage() {
|
|
| 535 |
</button>
|
| 536 |
</div>
|
| 537 |
</div>
|
| 538 |
-
|
|
|
|
| 539 |
</div>
|
| 540 |
)}
|
| 541 |
|
|
|
|
| 399 |
</div>
|
| 400 |
) : (
|
| 401 |
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 animate-in fade-in slide-in-from-bottom-4 duration-500">
|
| 402 |
+
{accounts.map((acc) => {
|
| 403 |
+
const isPrimary = Boolean(acc.is_active);
|
| 404 |
+
const isOnline = acc.status === 'active';
|
| 405 |
+
const isResting = acc.status === 'resting' || acc.status === 'pending';
|
| 406 |
+
|
| 407 |
+
const cardBorderBg = isPrimary
|
| 408 |
+
? "bg-gradient-to-b from-amber-500/[0.08] via-amber-500/[0.02] to-card border-2 border-amber-500/60 shadow-lg shadow-amber-500/10"
|
| 409 |
+
: isOnline
|
| 410 |
+
? "bg-gradient-to-b from-indigo-500/[0.04] to-card border border-indigo-500/30 hover:border-indigo-500/60 shadow-sm"
|
| 411 |
+
: isResting
|
| 412 |
+
? "bg-gradient-to-b from-amber-500/[0.03] to-card border border-amber-500/25"
|
| 413 |
+
: "bg-gradient-to-b from-red-500/[0.04] to-card border border-red-500/30";
|
| 414 |
+
|
| 415 |
+
return (
|
| 416 |
+
<div key={acc.phone_number} className={`${cardBorderBg} rounded-2xl p-4 group relative transition-all flex flex-col`}>
|
| 417 |
{/* Header: Status and Active Indicator */}
|
| 418 |
<div className="flex justify-between items-center mb-6">
|
| 419 |
+
<span className={`px-3 py-1 text-[8px] font-black rounded-full flex items-center gap-1.5 uppercase tracking-widest transition-all ${
|
| 420 |
+
isOnline ? 'bg-emerald-500/10 text-emerald-500 border border-emerald-500/20' :
|
| 421 |
+
isResting ? 'bg-amber-500/10 text-amber-500 border border-amber-500/20' :
|
| 422 |
+
'bg-red-500/10 text-red-500 border border-red-500/20'
|
| 423 |
+
}`}>
|
| 424 |
+
<div className={`w-1 h-1 rounded-full ${
|
| 425 |
+
isOnline ? 'bg-emerald-500 animate-pulse' :
|
| 426 |
+
isResting ? 'bg-amber-500' :
|
| 427 |
+
'bg-red-500'
|
| 428 |
+
}`} />
|
| 429 |
+
{isOnline ? 'ONLINE' : acc.status.toUpperCase()}
|
| 430 |
</span>
|
| 431 |
|
| 432 |
<div className="flex items-center gap-2">
|
| 433 |
+
{isPrimary ? (
|
| 434 |
+
<div className="flex items-center gap-1.5 px-3 py-1 bg-amber-500/15 text-amber-400 rounded-full text-[8px] font-black uppercase tracking-widest border border-amber-500/30 shadow-xs">
|
| 435 |
+
<Star size={10} className="fill-amber-400 text-amber-400" />
|
| 436 |
+
PRIMARY NODE
|
| 437 |
</div>
|
| 438 |
) : (
|
| 439 |
<button
|
| 440 |
onClick={() => handleSetActive(acc.phone_number)}
|
| 441 |
+
className="px-3 py-1 bg-white/5 hover:bg-amber-500/20 text-foreground/40 hover:text-amber-400 rounded-full text-[8px] font-black uppercase tracking-widest transition-all border border-white/5 hover:border-amber-500/30 active:scale-95 cursor-pointer"
|
| 442 |
>
|
| 443 |
{actionLoading === acc.phone_number + '_active' ? <Loader2 size={8} className="animate-spin" /> : 'SET PRIMARY'}
|
| 444 |
</button>
|
|
|
|
| 449 |
{/* Profile Section - Compact */}
|
| 450 |
<div className="flex flex-col items-center mb-4">
|
| 451 |
<div className="relative mb-2 group-hover:scale-105 transition-transform duration-300">
|
| 452 |
+
<div className={`relative w-12 h-12 rounded-2xl border p-0.5 bg-background shadow-md overflow-hidden flex items-center justify-center ${isPrimary ? 'border-amber-500/50 shadow-amber-500/10' : 'border-border/80'}`}>
|
| 453 |
{acc.profile_photo ? (
|
| 454 |
<img
|
| 455 |
src={acc.profile_photo.startsWith('http') ? acc.profile_photo : (process.env.NEXT_PUBLIC_API_URL ? `${process.env.NEXT_PUBLIC_API_URL}${acc.profile_photo}` : `http://localhost:8000${acc.profile_photo}`)}
|
| 456 |
className="w-full h-full rounded-[0.9rem] object-cover"
|
| 457 |
onError={(e) => {
|
| 458 |
const target = e.target as any;
|
| 459 |
+
target.src = `https://ui-avatars.com/api/?name=${encodeURIComponent(acc.first_name || 'A')}&background=${isPrimary ? 'f59e0b' : '6366f1'}&color=fff`;
|
| 460 |
}}
|
| 461 |
/>
|
| 462 |
) : (
|
| 463 |
+
<div className={`w-full h-full rounded-[0.9rem] flex items-center justify-center ${isPrimary ? 'bg-amber-500/10 text-amber-400' : 'bg-indigo-500/10 text-indigo-500'}`}>
|
| 464 |
<Users size={18} />
|
| 465 |
</div>
|
| 466 |
)}
|
|
|
|
| 469 |
<h4 className="text-sm font-bold text-foreground tracking-tight px-2 text-center leading-tight">
|
| 470 |
{acc.first_name || 'Neural'} {acc.last_name || 'Node'}
|
| 471 |
</h4>
|
| 472 |
+
<div className={`mt-1 flex items-center gap-1.5 px-2 py-0.5 rounded-full border ${isPrimary ? 'bg-amber-500/10 border-amber-500/20 text-amber-400' : 'bg-indigo-500/10 border-indigo-500/20 text-indigo-400'}`}>
|
| 473 |
+
<span className="text-[8px] font-bold uppercase tracking-wider">@{acc.username || 'arkitel_node'}</span>
|
| 474 |
</div>
|
| 475 |
</div>
|
| 476 |
|
|
|
|
| 494 |
<div className="mt-auto grid grid-cols-4 gap-2.5 pt-4 border-t border-white/5">
|
| 495 |
<button
|
| 496 |
onClick={() => handleSyncProfile(acc.phone_number)}
|
| 497 |
+
className={`aspect-square rounded-xl flex items-center justify-center transition-all border active:scale-90 ${isPrimary ? 'bg-amber-500/10 hover:bg-amber-500 text-amber-400 hover:text-white border-amber-500/20' : 'bg-indigo-600/10 hover:bg-indigo-600 text-indigo-500 hover:text-white border-indigo-500/10'}`}
|
| 498 |
title="Sync Profile"
|
| 499 |
>
|
| 500 |
{actionLoading === acc.phone_number + '_sync' ? <Loader2 size={14} className="animate-spin" /> : <CloudSync size={16} />}
|
|
|
|
| 550 |
</button>
|
| 551 |
</div>
|
| 552 |
</div>
|
| 553 |
+
);
|
| 554 |
+
})}
|
| 555 |
</div>
|
| 556 |
)}
|
| 557 |
|
frontend/src/app/campaigns/page.tsx
CHANGED
|
@@ -438,11 +438,47 @@ export default function CampaignsPage() {
|
|
| 438 |
|
| 439 |
const getStatusColor = (status: string) => {
|
| 440 |
switch (status) {
|
| 441 |
-
case 'completed': return 'bg-emerald-500/
|
| 442 |
-
case 'processing':
|
| 443 |
-
case '
|
| 444 |
-
case '
|
| 445 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 446 |
}
|
| 447 |
};
|
| 448 |
|
|
@@ -552,10 +588,12 @@ export default function CampaignsPage() {
|
|
| 552 |
failedCount = JSON.parse(camp.failed_groups || '[]').length;
|
| 553 |
} catch (e) { }
|
| 554 |
|
|
|
|
|
|
|
| 555 |
return (
|
| 556 |
<div
|
| 557 |
key={camp.id}
|
| 558 |
-
className=
|
| 559 |
>
|
| 560 |
<div>
|
| 561 |
{/* Top Row: Status Pill & Quick Action Bar */}
|
|
@@ -673,10 +711,12 @@ export default function CampaignsPage() {
|
|
| 673 |
) : (
|
| 674 |
/* List View */
|
| 675 |
<div className="space-y-3">
|
| 676 |
-
{filteredCampaigns.map((camp) =>
|
| 677 |
-
|
|
|
|
|
|
|
| 678 |
<div className="flex items-center gap-3.5 min-w-0">
|
| 679 |
-
<div className={`w-11 h-11 rounded-xl flex items-center justify-center shrink-0 ${
|
| 680 |
<Megaphone size={20} />
|
| 681 |
</div>
|
| 682 |
<div className="min-w-0">
|
|
@@ -727,7 +767,8 @@ export default function CampaignsPage() {
|
|
| 727 |
</div>
|
| 728 |
</div>
|
| 729 |
</div>
|
| 730 |
-
|
|
|
|
| 731 |
</div>
|
| 732 |
)}
|
| 733 |
|
|
|
|
| 438 |
|
| 439 |
const getStatusColor = (status: string) => {
|
| 440 |
switch (status) {
|
| 441 |
+
case 'completed': return 'bg-emerald-500/15 text-emerald-400 border-emerald-500/30';
|
| 442 |
+
case 'processing':
|
| 443 |
+
case 'active':
|
| 444 |
+
case 'running': return 'bg-amber-500/15 text-amber-400 border-amber-500/30';
|
| 445 |
+
case 'paused': return 'bg-blue-500/15 text-blue-400 border-blue-500/30';
|
| 446 |
+
case 'failed':
|
| 447 |
+
case 'error': return 'bg-rose-500/15 text-rose-400 border-rose-500/30';
|
| 448 |
+
default: return 'bg-indigo-500/15 text-indigo-400 border-indigo-500/30';
|
| 449 |
+
}
|
| 450 |
+
};
|
| 451 |
+
|
| 452 |
+
const getCampaignCardStyle = (status: string) => {
|
| 453 |
+
switch (status) {
|
| 454 |
+
case 'completed':
|
| 455 |
+
return {
|
| 456 |
+
cardBg: 'bg-gradient-to-b from-emerald-500/[0.08] via-emerald-500/[0.02] to-card border-2 border-emerald-500/50 shadow-md shadow-emerald-500/10',
|
| 457 |
+
iconColor: 'bg-emerald-500/15 text-emerald-400 border-emerald-500/30'
|
| 458 |
+
};
|
| 459 |
+
case 'processing':
|
| 460 |
+
case 'active':
|
| 461 |
+
case 'running':
|
| 462 |
+
return {
|
| 463 |
+
cardBg: 'bg-gradient-to-b from-amber-500/[0.08] via-amber-500/[0.02] to-card border-2 border-amber-500/50 shadow-md shadow-amber-500/10',
|
| 464 |
+
iconColor: 'bg-amber-500/15 text-amber-400 border-amber-500/30'
|
| 465 |
+
};
|
| 466 |
+
case 'failed':
|
| 467 |
+
case 'error':
|
| 468 |
+
return {
|
| 469 |
+
cardBg: 'bg-gradient-to-b from-rose-500/[0.08] via-rose-500/[0.02] to-card border-2 border-rose-500/50 shadow-md shadow-rose-500/10',
|
| 470 |
+
iconColor: 'bg-rose-500/15 text-rose-400 border-rose-500/30'
|
| 471 |
+
};
|
| 472 |
+
case 'paused':
|
| 473 |
+
return {
|
| 474 |
+
cardBg: 'bg-gradient-to-b from-blue-500/[0.04] to-card border border-blue-500/30 shadow-xs',
|
| 475 |
+
iconColor: 'bg-blue-500/15 text-blue-400 border-blue-500/30'
|
| 476 |
+
};
|
| 477 |
+
default:
|
| 478 |
+
return {
|
| 479 |
+
cardBg: 'bg-card border border-border/80 shadow-xs hover:border-indigo-500/40',
|
| 480 |
+
iconColor: 'bg-indigo-500/10 text-indigo-400 border-indigo-500/20'
|
| 481 |
+
};
|
| 482 |
}
|
| 483 |
};
|
| 484 |
|
|
|
|
| 588 |
failedCount = JSON.parse(camp.failed_groups || '[]').length;
|
| 589 |
} catch (e) { }
|
| 590 |
|
| 591 |
+
const cardStyle = getCampaignCardStyle(camp.status);
|
| 592 |
+
|
| 593 |
return (
|
| 594 |
<div
|
| 595 |
key={camp.id}
|
| 596 |
+
className={`${cardStyle.cardBg} rounded-2xl p-4.5 transition-all flex flex-col justify-between group/card relative`}
|
| 597 |
>
|
| 598 |
<div>
|
| 599 |
{/* Top Row: Status Pill & Quick Action Bar */}
|
|
|
|
| 711 |
) : (
|
| 712 |
/* List View */
|
| 713 |
<div className="space-y-3">
|
| 714 |
+
{filteredCampaigns.map((camp) => {
|
| 715 |
+
const cardStyle = getCampaignCardStyle(camp.status);
|
| 716 |
+
return (
|
| 717 |
+
<div key={camp.id} className={`${cardStyle.cardBg} rounded-2xl p-4 transition-all flex flex-col md:flex-row md:items-center justify-between gap-4 group/card`}>
|
| 718 |
<div className="flex items-center gap-3.5 min-w-0">
|
| 719 |
+
<div className={`w-11 h-11 rounded-xl flex items-center justify-center shrink-0 border ${cardStyle.iconColor}`}>
|
| 720 |
<Megaphone size={20} />
|
| 721 |
</div>
|
| 722 |
<div className="min-w-0">
|
|
|
|
| 767 |
</div>
|
| 768 |
</div>
|
| 769 |
</div>
|
| 770 |
+
);
|
| 771 |
+
})}
|
| 772 |
</div>
|
| 773 |
)}
|
| 774 |
|
frontend/src/app/compare/page.tsx
CHANGED
|
@@ -22,7 +22,8 @@ import {
|
|
| 22 |
RefreshCw,
|
| 23 |
SlidersHorizontal,
|
| 24 |
Tv,
|
| 25 |
-
MessageSquare
|
|
|
|
| 26 |
} from 'lucide-react';
|
| 27 |
import Link from 'next/link';
|
| 28 |
import { apiFetch } from '@/lib/auth';
|
|
@@ -181,12 +182,15 @@ export default function ComparePage() {
|
|
| 181 |
setJoiningId(groupItem.id);
|
| 182 |
setError('');
|
| 183 |
|
|
|
|
| 184 |
try {
|
| 185 |
const res = await apiFetch('/api/telegram/join', {
|
| 186 |
method: 'POST',
|
| 187 |
body: JSON.stringify({
|
| 188 |
phone_number: targetPhone,
|
| 189 |
-
target: target
|
|
|
|
|
|
|
| 190 |
})
|
| 191 |
});
|
| 192 |
|
|
@@ -247,12 +251,15 @@ export default function ComparePage() {
|
|
| 247 |
msg: `Joining (${i + 1}/${itemsToJoin.length}): ${item.title}...`
|
| 248 |
});
|
| 249 |
|
|
|
|
| 250 |
try {
|
| 251 |
const res = await apiFetch('/api/telegram/join', {
|
| 252 |
method: 'POST',
|
| 253 |
body: JSON.stringify({
|
| 254 |
phone_number: targetPhone,
|
| 255 |
-
target: target
|
|
|
|
|
|
|
| 256 |
})
|
| 257 |
});
|
| 258 |
if (res.ok) {
|
|
@@ -343,24 +350,34 @@ export default function ComparePage() {
|
|
| 343 |
</div>
|
| 344 |
</header>
|
| 345 |
|
| 346 |
-
{/*
|
| 347 |
-
{
|
| 348 |
-
<div className="
|
| 349 |
-
<div className="flex items-center
|
| 350 |
-
<
|
| 351 |
-
<span>{error}</span>
|
| 352 |
</div>
|
| 353 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 354 |
</div>
|
| 355 |
)}
|
| 356 |
|
| 357 |
-
{
|
| 358 |
-
<div className="
|
| 359 |
-
<div className="flex items-center
|
| 360 |
-
<
|
| 361 |
-
<span>{successMsg}</span>
|
| 362 |
</div>
|
| 363 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
</div>
|
| 365 |
)}
|
| 366 |
|
|
|
|
| 22 |
RefreshCw,
|
| 23 |
SlidersHorizontal,
|
| 24 |
Tv,
|
| 25 |
+
MessageSquare,
|
| 26 |
+
X
|
| 27 |
} from 'lucide-react';
|
| 28 |
import Link from 'next/link';
|
| 29 |
import { apiFetch } from '@/lib/auth';
|
|
|
|
| 182 |
setJoiningId(groupItem.id);
|
| 183 |
setError('');
|
| 184 |
|
| 185 |
+
const sourcePhone = targetPhone === phoneA ? phoneB : phoneA;
|
| 186 |
try {
|
| 187 |
const res = await apiFetch('/api/telegram/join', {
|
| 188 |
method: 'POST',
|
| 189 |
body: JSON.stringify({
|
| 190 |
phone_number: targetPhone,
|
| 191 |
+
target: target,
|
| 192 |
+
group_id: target,
|
| 193 |
+
source_phone: sourcePhone
|
| 194 |
})
|
| 195 |
});
|
| 196 |
|
|
|
|
| 251 |
msg: `Joining (${i + 1}/${itemsToJoin.length}): ${item.title}...`
|
| 252 |
});
|
| 253 |
|
| 254 |
+
const sourcePhone = targetPhone === phoneA ? phoneB : phoneA;
|
| 255 |
try {
|
| 256 |
const res = await apiFetch('/api/telegram/join', {
|
| 257 |
method: 'POST',
|
| 258 |
body: JSON.stringify({
|
| 259 |
phone_number: targetPhone,
|
| 260 |
+
target: target,
|
| 261 |
+
group_id: target,
|
| 262 |
+
source_phone: sourcePhone
|
| 263 |
})
|
| 264 |
});
|
| 265 |
if (res.ok) {
|
|
|
|
| 350 |
</div>
|
| 351 |
</header>
|
| 352 |
|
| 353 |
+
{/* Floating Global Toasts */}
|
| 354 |
+
{successMsg && (
|
| 355 |
+
<div className="fixed top-6 right-6 z-[100] max-w-md bg-card/95 backdrop-blur-xl border border-emerald-500/40 text-emerald-400 p-4 rounded-2xl flex items-center gap-3 animate-in fade-in slide-in-from-top-4 duration-300 shadow-2xl shadow-emerald-500/20">
|
| 356 |
+
<div className="w-8 h-8 rounded-xl bg-emerald-500/10 flex items-center justify-center text-emerald-400 shrink-0 border border-emerald-500/20">
|
| 357 |
+
<CheckCircle2 size={18} />
|
|
|
|
| 358 |
</div>
|
| 359 |
+
<div className="flex-1 min-w-0">
|
| 360 |
+
<h5 className="text-xs font-bold text-foreground">Operation Successful</h5>
|
| 361 |
+
<p className="text-[11px] text-foreground/70 font-medium leading-tight mt-0.5">{successMsg}</p>
|
| 362 |
+
</div>
|
| 363 |
+
<button onClick={() => setSuccessMsg('')} className="text-foreground/40 hover:text-foreground p-1 transition-colors">
|
| 364 |
+
<X size={15} />
|
| 365 |
+
</button>
|
| 366 |
</div>
|
| 367 |
)}
|
| 368 |
|
| 369 |
+
{error && (
|
| 370 |
+
<div className="fixed top-6 right-6 z-[100] max-w-md bg-card/95 backdrop-blur-xl border border-rose-500/40 text-rose-400 p-4 rounded-2xl flex items-center gap-3 animate-in fade-in slide-in-from-top-4 duration-300 shadow-2xl shadow-rose-500/20">
|
| 371 |
+
<div className="w-8 h-8 rounded-xl bg-rose-500/10 flex items-center justify-center text-rose-400 shrink-0 border border-rose-500/20">
|
| 372 |
+
<AlertCircle size={18} />
|
|
|
|
| 373 |
</div>
|
| 374 |
+
<div className="flex-1 min-w-0">
|
| 375 |
+
<h5 className="text-xs font-bold text-foreground">Action Alert</h5>
|
| 376 |
+
<p className="text-[11px] text-foreground/70 font-medium leading-tight mt-0.5">{error}</p>
|
| 377 |
+
</div>
|
| 378 |
+
<button onClick={() => setError('')} className="text-foreground/40 hover:text-foreground p-1 transition-colors">
|
| 379 |
+
<X size={15} />
|
| 380 |
+
</button>
|
| 381 |
</div>
|
| 382 |
)}
|
| 383 |
|
frontend/src/app/leads/page.tsx
CHANGED
|
@@ -52,6 +52,8 @@ export default function LeadsPage() {
|
|
| 52 |
const [extractingPhone, setExtractingPhone] = useState('');
|
| 53 |
const [accounts, setAccounts] = useState<any[]>([]);
|
| 54 |
const [copyStatus, setCopyStatus] = useState<{[key: string]: boolean}>({});
|
|
|
|
|
|
|
| 55 |
|
| 56 |
// Bulk join progress tracker
|
| 57 |
const [joinProgress, setJoinProgress] = useState<{
|
|
@@ -251,23 +253,31 @@ export default function LeadsPage() {
|
|
| 251 |
};
|
| 252 |
|
| 253 |
const handleSingleJoin = async (id: string, username: string | null) => {
|
|
|
|
|
|
|
|
|
|
| 254 |
try {
|
| 255 |
-
const
|
| 256 |
-
|
|
|
|
| 257 |
|
| 258 |
const res = await apiFetch('/api/telegram/join', {
|
| 259 |
method: 'POST',
|
| 260 |
-
body: JSON.stringify({ group_id:
|
| 261 |
});
|
|
|
|
| 262 |
if (res.ok) {
|
| 263 |
// Mark as joined immediately in UI so the button changes to a badge
|
| 264 |
-
setJoinedIds(prev => new Set([...prev, id, username ||
|
|
|
|
|
|
|
| 265 |
} else {
|
| 266 |
-
|
| 267 |
-
setError(d.detail || 'Join failed');
|
| 268 |
}
|
| 269 |
} catch (e: any) {
|
| 270 |
-
setError(e.message);
|
|
|
|
|
|
|
| 271 |
}
|
| 272 |
};
|
| 273 |
|
|
@@ -516,6 +526,37 @@ export default function LeadsPage() {
|
|
| 516 |
</div>
|
| 517 |
</div>
|
| 518 |
)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 519 |
<header className="sticky top-16 md:top-0 z-20 bg-background/90 backdrop-blur-md pt-2 pb-5 mb-5 border-b border-border/50 transition-all flex flex-col md:flex-row justify-between items-start md:items-center gap-4">
|
| 520 |
<div>
|
| 521 |
<h2 className="text-2xl font-bold tracking-tight text-foreground flex items-center gap-2">
|
|
@@ -650,10 +691,11 @@ export default function LeadsPage() {
|
|
| 650 |
) : (
|
| 651 |
<button
|
| 652 |
onClick={(e) => { e.stopPropagation(); handleSingleJoin(l.id, l.username); }}
|
| 653 |
-
|
| 654 |
-
|
|
|
|
| 655 |
>
|
| 656 |
-
<UserPlus size={14} />
|
| 657 |
</button>
|
| 658 |
)}
|
| 659 |
<button
|
|
|
|
| 52 |
const [extractingPhone, setExtractingPhone] = useState('');
|
| 53 |
const [accounts, setAccounts] = useState<any[]>([]);
|
| 54 |
const [copyStatus, setCopyStatus] = useState<{[key: string]: boolean}>({});
|
| 55 |
+
const [joiningLeadId, setJoiningLeadId] = useState<string | null>(null);
|
| 56 |
+
const [successMsg, setSuccessMsg] = useState<string>('');
|
| 57 |
|
| 58 |
// Bulk join progress tracker
|
| 59 |
const [joinProgress, setJoinProgress] = useState<{
|
|
|
|
| 253 |
};
|
| 254 |
|
| 255 |
const handleSingleJoin = async (id: string, username: string | null) => {
|
| 256 |
+
const target = username ? `@${username.replace(/^@/, '')}` : id;
|
| 257 |
+
setJoiningLeadId(id);
|
| 258 |
+
setError('');
|
| 259 |
try {
|
| 260 |
+
const activeAcc = accounts.find(a => a.is_active) || accounts.find(a => a.status === 'active') || accounts[0];
|
| 261 |
+
const phoneNumber = activeAcc?.phone_number;
|
| 262 |
+
if (!phoneNumber) throw new Error("No active Telegram account found. Please connect or activate an account in Fleet.");
|
| 263 |
|
| 264 |
const res = await apiFetch('/api/telegram/join', {
|
| 265 |
method: 'POST',
|
| 266 |
+
body: JSON.stringify({ group_id: target, target: target, phone_number: phoneNumber })
|
| 267 |
});
|
| 268 |
+
const d = await res.json();
|
| 269 |
if (res.ok) {
|
| 270 |
// Mark as joined immediately in UI so the button changes to a badge
|
| 271 |
+
setJoinedIds(prev => new Set([...prev, id, target, username || '']));
|
| 272 |
+
setSuccessMsg(`Successfully joined ${target}`);
|
| 273 |
+
setTimeout(() => setSuccessMsg(''), 4500);
|
| 274 |
} else {
|
| 275 |
+
setError(d.detail || 'Join request declined by Telegram.');
|
|
|
|
| 276 |
}
|
| 277 |
} catch (e: any) {
|
| 278 |
+
setError(e.message || 'Failed to join group.');
|
| 279 |
+
} finally {
|
| 280 |
+
setJoiningLeadId(null);
|
| 281 |
}
|
| 282 |
};
|
| 283 |
|
|
|
|
| 526 |
</div>
|
| 527 |
</div>
|
| 528 |
)}
|
| 529 |
+
{/* Floating Notifications */}
|
| 530 |
+
{successMsg && (
|
| 531 |
+
<div className="fixed top-6 right-6 z-[100] max-w-md bg-card/95 backdrop-blur-xl border border-emerald-500/40 text-emerald-400 p-4 rounded-2xl flex items-center gap-3 animate-in fade-in slide-in-from-top-4 duration-300 shadow-2xl shadow-emerald-500/20">
|
| 532 |
+
<div className="w-8 h-8 rounded-xl bg-emerald-500/10 flex items-center justify-center text-emerald-400 shrink-0 border border-emerald-500/20">
|
| 533 |
+
<CheckCircle2 size={18} />
|
| 534 |
+
</div>
|
| 535 |
+
<div className="flex-1 min-w-0">
|
| 536 |
+
<h5 className="text-xs font-bold text-foreground">Action Successful</h5>
|
| 537 |
+
<p className="text-[11px] text-foreground/70 font-medium leading-tight mt-0.5">{successMsg}</p>
|
| 538 |
+
</div>
|
| 539 |
+
<button onClick={() => setSuccessMsg('')} className="text-foreground/40 hover:text-foreground p-1 transition-colors">
|
| 540 |
+
<X size={15} />
|
| 541 |
+
</button>
|
| 542 |
+
</div>
|
| 543 |
+
)}
|
| 544 |
+
|
| 545 |
+
{error && (
|
| 546 |
+
<div className="fixed top-6 right-6 z-[100] max-w-md bg-card/95 backdrop-blur-xl border border-rose-500/40 text-rose-400 p-4 rounded-2xl flex items-center gap-3 animate-in fade-in slide-in-from-top-4 duration-300 shadow-2xl shadow-rose-500/20">
|
| 547 |
+
<div className="w-8 h-8 rounded-xl bg-rose-500/10 flex items-center justify-center text-rose-400 shrink-0 border border-rose-500/20">
|
| 548 |
+
<AlertTriangle size={18} />
|
| 549 |
+
</div>
|
| 550 |
+
<div className="flex-1 min-w-0">
|
| 551 |
+
<h5 className="text-xs font-bold text-foreground">Attention</h5>
|
| 552 |
+
<p className="text-[11px] text-foreground/70 font-medium leading-tight mt-0.5">{error}</p>
|
| 553 |
+
</div>
|
| 554 |
+
<button onClick={() => setError('')} className="text-foreground/40 hover:text-foreground p-1 transition-colors">
|
| 555 |
+
<X size={15} />
|
| 556 |
+
</button>
|
| 557 |
+
</div>
|
| 558 |
+
)}
|
| 559 |
+
|
| 560 |
<header className="sticky top-16 md:top-0 z-20 bg-background/90 backdrop-blur-md pt-2 pb-5 mb-5 border-b border-border/50 transition-all flex flex-col md:flex-row justify-between items-start md:items-center gap-4">
|
| 561 |
<div>
|
| 562 |
<h2 className="text-2xl font-bold tracking-tight text-foreground flex items-center gap-2">
|
|
|
|
| 691 |
) : (
|
| 692 |
<button
|
| 693 |
onClick={(e) => { e.stopPropagation(); handleSingleJoin(l.id, l.username); }}
|
| 694 |
+
disabled={joiningLeadId === l.id}
|
| 695 |
+
className="p-1.5 bg-foreground/5 hover:bg-emerald-500/10 hover:text-emerald-500 rounded-lg text-foreground/30 transition-all cursor-pointer disabled:opacity-50"
|
| 696 |
+
title="Join Community"
|
| 697 |
>
|
| 698 |
+
{joiningLeadId === l.id ? <Loader2 size={14} className="animate-spin text-emerald-400" /> : <UserPlus size={14} />}
|
| 699 |
</button>
|
| 700 |
)}
|
| 701 |
<button
|
frontend/src/app/scraper/page.tsx
CHANGED
|
@@ -127,7 +127,7 @@ export default function ScraperPage() {
|
|
| 127 |
|
| 128 |
const res = await apiFetch('/api/telegram/join', {
|
| 129 |
method: 'POST',
|
| 130 |
-
body: JSON.stringify({ group_id: groupId, phone_number: phoneNumber })
|
| 131 |
});
|
| 132 |
const data = await res.json();
|
| 133 |
if (res.ok) {
|
|
|
|
| 127 |
|
| 128 |
const res = await apiFetch('/api/telegram/join', {
|
| 129 |
method: 'POST',
|
| 130 |
+
body: JSON.stringify({ group_id: groupId, target: groupId, phone_number: phoneNumber })
|
| 131 |
});
|
| 132 |
const data = await res.json();
|
| 133 |
if (res.ok) {
|