Spaces:
Paused
Paused
CBV01 commited on
Commit ·
4df05ee
1
Parent(s): ccc7032
feat: redesign smart dm closer to match outbox monitor layout, fix dm entity resolution, live channel feed scraper, sleek campaign runtime & accounts dropdown, high-density spintax
Browse files- backend/main.py +239 -93
- frontend/src/app/ai-assistant/page.tsx +0 -0
- frontend/src/app/campaigns/page.tsx +204 -46
- frontend/src/app/scraper/page.tsx +74 -24
- frontend/src/components/SpintaxModal.tsx +142 -69
backend/main.py
CHANGED
|
@@ -185,76 +185,140 @@ async def lifespan(app: FastAPI):
|
|
| 185 |
|
| 186 |
async def verify_telegram_info(username: str) -> Dict[str, Any]:
|
| 187 |
"""
|
| 188 |
-
Checks t.me/username anonymously to
|
| 189 |
Supports K/M abbreviations, spaces, and commas.
|
| 190 |
"""
|
| 191 |
-
if not username: return {"exists": False, "participants_count": 0}
|
| 192 |
clean_user = username.replace('@', '').replace('https://t.me/', '').replace('t.me/', '').strip().split('/')[0].split('?')[0]
|
| 193 |
-
if not clean_user: return {"exists": False, "participants_count": 0}
|
| 194 |
|
| 195 |
# Safety check for BeautifulSoup availability
|
| 196 |
if not BS4_AVAILABLE:
|
| 197 |
-
return {"exists": True, "participants_count": 0}
|
| 198 |
|
| 199 |
-
url = f"https://t.me/{clean_user}"
|
| 200 |
headers = {
|
| 201 |
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36"
|
| 202 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
try:
|
| 204 |
-
async with httpx.AsyncClient(follow_redirects=True, timeout=
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
|
| 243 |
-
#
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
except Exception as e:
|
| 257 |
-
return {"exists": True, "participants_count": 0, "username": clean_user}
|
| 258 |
|
| 259 |
|
| 260 |
@app.get("/api/telegram/preview")
|
|
@@ -1049,19 +1113,30 @@ async def get_dialogs(req: FetchDialogsRequest, user_id: str = Depends(get_curre
|
|
| 1049 |
admin_rights = getattr(ent, 'admin_rights', None)
|
| 1050 |
default_banned = getattr(ent, 'default_banned_rights', None)
|
| 1051 |
banned = getattr(ent, 'banned_rights', None)
|
|
|
|
|
|
|
|
|
|
| 1052 |
|
| 1053 |
-
if
|
|
|
|
|
|
|
| 1054 |
can_send = True
|
| 1055 |
elif is_broadcast:
|
|
|
|
| 1056 |
can_send = bool(admin_rights and getattr(admin_rights, 'post_messages', False))
|
| 1057 |
else:
|
|
|
|
| 1058 |
if admin_rights:
|
| 1059 |
can_send = True
|
| 1060 |
elif banned and getattr(banned, 'send_messages', False):
|
| 1061 |
can_send = False
|
| 1062 |
elif default_banned and getattr(default_banned, 'send_messages', False):
|
| 1063 |
can_send = False
|
| 1064 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1065 |
|
| 1066 |
dialogs_list.append({
|
| 1067 |
"id": did,
|
|
@@ -4364,25 +4439,27 @@ async def generate_template_variations(req: AITemplateVariationsRequest, user_id
|
|
| 4364 |
if volume == "short":
|
| 4365 |
volume_guidelines = (
|
| 4366 |
"TARGET LENGTH: SHORT & PUNCHY (approx 45-75 words).\n"
|
| 4367 |
-
"- Bold, energetic headline hook.\n"
|
| 4368 |
-
"- 2-3 crisp bullet highlights
|
| 4369 |
-
"- Quick, direct call to action link."
|
| 4370 |
)
|
| 4371 |
elif volume == "lengthy":
|
| 4372 |
volume_guidelines = (
|
| 4373 |
-
"TARGET LENGTH: LENGTHY &
|
| 4374 |
-
"-
|
| 4375 |
-
"-
|
| 4376 |
-
"-
|
| 4377 |
-
"-
|
| 4378 |
-
"-
|
|
|
|
|
|
|
| 4379 |
)
|
| 4380 |
else: # moderate
|
| 4381 |
volume_guidelines = (
|
| 4382 |
-
"TARGET LENGTH: MODERATE & BALANCED (approx
|
| 4383 |
"- Compelling hook headline with emojis.\n"
|
| 4384 |
"- 1 structured paragraph explaining why this offer matters.\n"
|
| 4385 |
-
"-
|
| 4386 |
"- Clear call to action link."
|
| 4387 |
)
|
| 4388 |
|
|
@@ -4394,9 +4471,11 @@ async def generate_template_variations(req: AITemplateVariationsRequest, user_id
|
|
| 4394 |
sample_section = ""
|
| 4395 |
if sample_copy:
|
| 4396 |
sample_section = (
|
| 4397 |
-
f"\n\nUSER'S REFERENCE / SAMPLE COPY
|
| 4398 |
f"\"\"\"\n{sample_copy}\n\"\"\"\n"
|
| 4399 |
-
f"
|
|
|
|
|
|
|
| 4400 |
)
|
| 4401 |
|
| 4402 |
sys_prompt = (
|
|
@@ -4412,10 +4491,10 @@ async def generate_template_variations(req: AITemplateVariationsRequest, user_id
|
|
| 4412 |
f"- Variation 3: Social Proof & Problem-Solver\n"
|
| 4413 |
f"- Variation 4: Engaging Conversational Hook\n"
|
| 4414 |
f"- Variation 5: High Urgency & Limited-Time Perk\n\n"
|
| 4415 |
-
f"CRITICAL FORMATTING RULES:\n"
|
| 4416 |
f"1. THIS IS A TELEGRAM GROUP/CHANNEL PROMOTION BROADCAST, NOT AN EMAIL! Never start messages with 'Hello {{{{First Name}}}}' or letter greetings. Hook the reader immediately with an announcement, curiosity, question, or bold value.\n"
|
| 4417 |
-
f"2.
|
| 4418 |
-
f"3. EMOJIS & BULLETS: Make the content visually engaging and solid by using bullet points (•, 🔥, ⚡, 💎, ✅)
|
| 4419 |
f"4. {volume_guidelines}\n"
|
| 4420 |
f"5. {spintax_rule}\n"
|
| 4421 |
f"6. Return ONLY a valid JSON array of {target_count} strings: [\"Message 1...\", \"Message 2...\", ...].\n"
|
|
@@ -4460,19 +4539,38 @@ async def generate_template_variations(req: AITemplateVariationsRequest, user_id
|
|
| 4460 |
try:
|
| 4461 |
parsed = json.loads(cleaned[start:end+1])
|
| 4462 |
if isinstance(parsed, list):
|
| 4463 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4464 |
except Exception:
|
| 4465 |
try:
|
| 4466 |
fixed = re.sub(r',\s*\]', ']', cleaned[start:end+1])
|
| 4467 |
parsed = json.loads(fixed)
|
| 4468 |
if isinstance(parsed, list):
|
| 4469 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4470 |
except Exception:
|
| 4471 |
pass
|
| 4472 |
|
| 4473 |
if not variations:
|
| 4474 |
blocks = re.split(r'\n(?=(?:Variation|\d+[\.\)]))\s*', cleaned)
|
| 4475 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4476 |
|
| 4477 |
if variations:
|
| 4478 |
return {
|
|
@@ -4547,7 +4645,7 @@ async def check_account_spambot(phone: str, user_id: str = Depends(get_current_u
|
|
| 4547 |
|
| 4548 |
@app.get("/api/telegram/accounts/{phone}/dms")
|
| 4549 |
async def get_account_dms(phone: str, user_id: str = Depends(get_current_user_id)):
|
| 4550 |
-
"""Safely fetches
|
| 4551 |
conn = get_db_connection()
|
| 4552 |
row = conn.execute("SELECT session_string, api_id, api_hash FROM accounts WHERE phone_number = ? AND user_id = ?", (phone, user_id)).fetchone()
|
| 4553 |
if hasattr(conn, "close"): conn.close()
|
|
@@ -4563,7 +4661,8 @@ async def get_account_dms(phone: str, user_id: str = Depends(get_current_user_id
|
|
| 4563 |
|
| 4564 |
dms = []
|
| 4565 |
try:
|
| 4566 |
-
|
|
|
|
| 4567 |
if dialog.is_user:
|
| 4568 |
entity = dialog.entity
|
| 4569 |
if getattr(entity, 'bot', False):
|
|
@@ -4577,14 +4676,15 @@ async def get_account_dms(phone: str, user_id: str = Depends(get_current_user_id
|
|
| 4577 |
|
| 4578 |
dms.append({
|
| 4579 |
"id": entity.id,
|
|
|
|
| 4580 |
"name": full_name,
|
| 4581 |
"username": getattr(entity, 'username', None),
|
| 4582 |
"phone": getattr(entity, 'phone', None),
|
| 4583 |
-
"last_message": last_msg[:
|
| 4584 |
"date": dialog.date.isoformat() if dialog.date else None,
|
| 4585 |
"unread_count": dialog.unread_count or 0
|
| 4586 |
})
|
| 4587 |
-
if len(dms) >=
|
| 4588 |
break
|
| 4589 |
return {"dms": dms, "phone": phone, "total": len(dms)}
|
| 4590 |
except Exception as e:
|
|
@@ -4593,8 +4693,8 @@ async def get_account_dms(phone: str, user_id: str = Depends(get_current_user_id
|
|
| 4593 |
await client.disconnect()
|
| 4594 |
|
| 4595 |
@app.get("/api/telegram/accounts/{phone}/dms/{contact_id}/messages")
|
| 4596 |
-
async def get_dm_messages(phone: str, contact_id: int, user_id: str = Depends(get_current_user_id)):
|
| 4597 |
-
"""Fetches the last
|
| 4598 |
conn = get_db_connection()
|
| 4599 |
row = conn.execute("SELECT session_string, api_id, api_hash FROM accounts WHERE phone_number = ? AND user_id = ?", (phone, user_id)).fetchone()
|
| 4600 |
if hasattr(conn, "close"): conn.close()
|
|
@@ -4609,14 +4709,40 @@ async def get_dm_messages(phone: str, contact_id: int, user_id: str = Depends(ge
|
|
| 4609 |
raise HTTPException(status_code=401, detail="Account session expired.")
|
| 4610 |
|
| 4611 |
try:
|
| 4612 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4613 |
me = await client.get_me()
|
| 4614 |
-
|
| 4615 |
-
|
| 4616 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4617 |
|
| 4618 |
messages_list = []
|
| 4619 |
-
async for msg in client.iter_messages(entity, limit=
|
| 4620 |
is_out = msg.out or (msg.sender_id == me.id)
|
| 4621 |
messages_list.append({
|
| 4622 |
"id": msg.id,
|
|
@@ -4627,13 +4753,14 @@ async def get_dm_messages(phone: str, contact_id: int, user_id: str = Depends(ge
|
|
| 4627 |
messages_list.reverse()
|
| 4628 |
return {
|
| 4629 |
"contact": {
|
| 4630 |
-
"id":
|
| 4631 |
"name": full_name,
|
| 4632 |
-
"username":
|
| 4633 |
},
|
| 4634 |
"messages": messages_list
|
| 4635 |
}
|
| 4636 |
except Exception as e:
|
|
|
|
| 4637 |
raise HTTPException(status_code=400, detail=f"Failed to load messages: {str(e)}")
|
| 4638 |
finally:
|
| 4639 |
await client.disconnect()
|
|
@@ -4641,10 +4768,11 @@ async def get_dm_messages(phone: str, contact_id: int, user_id: str = Depends(ge
|
|
| 4641 |
|
| 4642 |
class DMSendRequest(BaseModel):
|
| 4643 |
message: str
|
|
|
|
| 4644 |
|
| 4645 |
@app.post("/api/telegram/accounts/{phone}/dms/{contact_id}/send")
|
| 4646 |
async def send_dm_message(phone: str, contact_id: int, req: DMSendRequest, user_id: str = Depends(get_current_user_id)):
|
| 4647 |
-
"""Sends a direct message reply to the contact in Telegram."""
|
| 4648 |
text = (req.message or "").strip()
|
| 4649 |
if not text:
|
| 4650 |
raise HTTPException(status_code=400, detail="Message text is required")
|
|
@@ -4663,7 +4791,24 @@ async def send_dm_message(phone: str, contact_id: int, req: DMSendRequest, user_
|
|
| 4663 |
raise HTTPException(status_code=401, detail="Account session expired.")
|
| 4664 |
|
| 4665 |
try:
|
| 4666 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4667 |
sent_msg = await client.send_message(entity, text)
|
| 4668 |
return {
|
| 4669 |
"status": "success",
|
|
@@ -4675,6 +4820,7 @@ async def send_dm_message(phone: str, contact_id: int, req: DMSendRequest, user_
|
|
| 4675 |
}
|
| 4676 |
}
|
| 4677 |
except Exception as e:
|
|
|
|
| 4678 |
raise HTTPException(status_code=400, detail=f"Failed to send reply: {str(e)}")
|
| 4679 |
finally:
|
| 4680 |
await client.disconnect()
|
|
|
|
| 185 |
|
| 186 |
async def verify_telegram_info(username: str) -> Dict[str, Any]:
|
| 187 |
"""
|
| 188 |
+
Checks t.me/s/username and t.me/username anonymously to get title, member count, photo, bio, and live channel feed posts.
|
| 189 |
Supports K/M abbreviations, spaces, and commas.
|
| 190 |
"""
|
| 191 |
+
if not username: return {"exists": False, "participants_count": 0, "posts": []}
|
| 192 |
clean_user = username.replace('@', '').replace('https://t.me/', '').replace('t.me/', '').strip().split('/')[0].split('?')[0]
|
| 193 |
+
if not clean_user: return {"exists": False, "participants_count": 0, "posts": []}
|
| 194 |
|
| 195 |
# Safety check for BeautifulSoup availability
|
| 196 |
if not BS4_AVAILABLE:
|
| 197 |
+
return {"exists": True, "participants_count": 0, "posts": []}
|
| 198 |
|
|
|
|
| 199 |
headers = {
|
| 200 |
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36"
|
| 201 |
}
|
| 202 |
+
|
| 203 |
+
title = ""
|
| 204 |
+
description = ""
|
| 205 |
+
photo_url = None
|
| 206 |
+
members = 0
|
| 207 |
+
chat_type = "group"
|
| 208 |
+
posts = []
|
| 209 |
+
|
| 210 |
try:
|
| 211 |
+
async with httpx.AsyncClient(follow_redirects=True, timeout=10) as client:
|
| 212 |
+
# 1. First fetch t.me/s/ for live posts & channel metadata
|
| 213 |
+
stream_url = f"https://t.me/s/{clean_user}"
|
| 214 |
+
try:
|
| 215 |
+
resp_s = await client.get(stream_url, headers=headers)
|
| 216 |
+
if resp_s.status_code == 200:
|
| 217 |
+
soup_s = BeautifulSoup(resp_s.text, 'html.parser')
|
| 218 |
+
|
| 219 |
+
# Title
|
| 220 |
+
t_elem = soup_s.find("div", class_="tgme_channel_info_header_title") or soup_s.find("div", class_="tgme_page_title")
|
| 221 |
+
if t_elem: title = t_elem.get_text(strip=True)
|
| 222 |
+
|
| 223 |
+
# Description
|
| 224 |
+
d_elem = soup_s.find("div", class_="tgme_channel_info_description") or soup_s.find("div", class_="tgme_page_description")
|
| 225 |
+
if d_elem: description = d_elem.get_text(strip=True)
|
| 226 |
+
|
| 227 |
+
# Photo
|
| 228 |
+
p_elem = soup_s.find("img", class_="tgme_page_photo_image")
|
| 229 |
+
if p_elem: photo_url = p_elem.get("src")
|
| 230 |
+
|
| 231 |
+
# Counters
|
| 232 |
+
counters = soup_s.find("div", class_="tgme_channel_info_counters") or soup_s.find("div", class_="tgme_page_extra")
|
| 233 |
+
if counters:
|
| 234 |
+
text_cnt = counters.get_text()
|
| 235 |
+
if "subscriber" in text_cnt.lower(): chat_type = "channel"
|
| 236 |
+
m = re.search(r'([\d\s,.]+)\s*([KkMm]?)\s*(subscribers|members|sub|subs|online)', text_cnt, re.IGNORECASE)
|
| 237 |
+
if m:
|
| 238 |
+
num_str = m.group(1).replace(' ', '').replace(',', '').strip()
|
| 239 |
+
unit = (m.group(2) or '').upper()
|
| 240 |
+
try:
|
| 241 |
+
val = float(num_str)
|
| 242 |
+
if unit == 'K': members = int(val * 1000)
|
| 243 |
+
elif unit == 'M': members = int(val * 1000000)
|
| 244 |
+
else: members = int(val)
|
| 245 |
+
except Exception:
|
| 246 |
+
digits = re.sub(r'\D', '', num_str)
|
| 247 |
+
members = int(digits) if digits else 0
|
| 248 |
+
|
| 249 |
+
# Live Posts
|
| 250 |
+
for m_elem in soup_s.find_all("div", class_="tgme_widget_message")[-15:]:
|
| 251 |
+
text_box = m_elem.find("div", class_="tgme_widget_message_text")
|
| 252 |
+
time_box = m_elem.find("time")
|
| 253 |
+
views_box = m_elem.find("span", class_="tgme_widget_message_views")
|
| 254 |
+
photo_box = m_elem.find("a", class_="tgme_widget_message_photo_wrap")
|
| 255 |
+
post_photo = None
|
| 256 |
+
if photo_box and photo_box.get("style"):
|
| 257 |
+
pmatch = re.search(r'url\(\s*[\'"]?(.*?)[\'"]?\s*\)', photo_box["style"])
|
| 258 |
+
if pmatch: post_photo = pmatch.group(1)
|
| 259 |
+
|
| 260 |
+
post_txt = text_box.get_text(separator="\n", strip=True) if text_box else ""
|
| 261 |
+
post_date = time_box.get_text(strip=True) if time_box else (time_box.get("datetime") if time_box else "")
|
| 262 |
+
post_views = views_box.get_text(strip=True) if views_box else ""
|
| 263 |
+
p_id = m_elem.get("data-post", "")
|
| 264 |
+
|
| 265 |
+
if post_txt or post_photo:
|
| 266 |
+
posts.append({
|
| 267 |
+
"id": p_id,
|
| 268 |
+
"text": post_txt,
|
| 269 |
+
"date": post_date,
|
| 270 |
+
"views": post_views,
|
| 271 |
+
"photo_url": post_photo
|
| 272 |
+
})
|
| 273 |
+
except Exception:
|
| 274 |
+
pass
|
| 275 |
|
| 276 |
+
# 2. Fallback to t.me/clean_user if title or members wasn't found
|
| 277 |
+
if not title or members == 0:
|
| 278 |
+
resp = await client.get(f"https://t.me/{clean_user}", headers=headers)
|
| 279 |
+
if resp.status_code == 200:
|
| 280 |
+
soup = BeautifulSoup(resp.text, 'html.parser')
|
| 281 |
+
title_elem = soup.find("div", class_="tgme_page_title")
|
| 282 |
+
if title_elem and not title:
|
| 283 |
+
title = title_elem.get_text(strip=True)
|
| 284 |
+
|
| 285 |
+
if not description:
|
| 286 |
+
desc_elem = soup.find("div", class_="tgme_page_description")
|
| 287 |
+
if desc_elem: description = desc_elem.get_text(strip=True)
|
| 288 |
+
|
| 289 |
+
if not photo_url:
|
| 290 |
+
photo_elem = soup.find("img", class_="tgme_page_photo_image")
|
| 291 |
+
if photo_elem: photo_url = photo_elem.get("src")
|
| 292 |
+
|
| 293 |
+
extra_elem = soup.find("div", class_="tgme_page_extra")
|
| 294 |
+
if extra_elem and members == 0:
|
| 295 |
+
text = extra_elem.get_text()
|
| 296 |
+
if "subscriber" in text.lower(): chat_type = "channel"
|
| 297 |
+
m = re.search(r'([\d\s,.]+)\s*([KkMm]?)\s*(subscribers|members|sub|subs|online)', text, re.IGNORECASE)
|
| 298 |
+
if m:
|
| 299 |
+
num_str = m.group(1).replace(' ', '').replace(',', '').strip()
|
| 300 |
+
unit = (m.group(2) or '').upper()
|
| 301 |
+
try:
|
| 302 |
+
val = float(num_str)
|
| 303 |
+
if unit == 'K': members = int(val * 1000)
|
| 304 |
+
elif unit == 'M': members = int(val * 1000000)
|
| 305 |
+
else: members = int(val)
|
| 306 |
+
except Exception:
|
| 307 |
+
digits = re.sub(r'\D', '', num_str)
|
| 308 |
+
members = int(digits) if digits else 0
|
| 309 |
+
|
| 310 |
+
return {
|
| 311 |
+
"exists": bool(title or members > 0 or posts),
|
| 312 |
+
"participants_count": members,
|
| 313 |
+
"title": title or clean_user,
|
| 314 |
+
"description": description,
|
| 315 |
+
"photo_url": photo_url,
|
| 316 |
+
"type": chat_type,
|
| 317 |
+
"username": clean_user,
|
| 318 |
+
"posts": posts
|
| 319 |
+
}
|
| 320 |
except Exception as e:
|
| 321 |
+
return {"exists": True, "participants_count": 0, "username": clean_user, "posts": []}
|
| 322 |
|
| 323 |
|
| 324 |
@app.get("/api/telegram/preview")
|
|
|
|
| 1113 |
admin_rights = getattr(ent, 'admin_rights', None)
|
| 1114 |
default_banned = getattr(ent, 'default_banned_rights', None)
|
| 1115 |
banned = getattr(ent, 'banned_rights', None)
|
| 1116 |
+
left = bool(getattr(ent, 'left', False))
|
| 1117 |
+
kicked = bool(getattr(ent, 'kicked', False))
|
| 1118 |
+
deactivated = bool(getattr(ent, 'deactivated', False))
|
| 1119 |
|
| 1120 |
+
if left or kicked or deactivated:
|
| 1121 |
+
can_send = False
|
| 1122 |
+
elif is_creator:
|
| 1123 |
can_send = True
|
| 1124 |
elif is_broadcast:
|
| 1125 |
+
# Telegram broadcast channel: ONLY admins with post_messages can post
|
| 1126 |
can_send = bool(admin_rights and getattr(admin_rights, 'post_messages', False))
|
| 1127 |
else:
|
| 1128 |
+
# Group / Supergroup:
|
| 1129 |
if admin_rights:
|
| 1130 |
can_send = True
|
| 1131 |
elif banned and getattr(banned, 'send_messages', False):
|
| 1132 |
can_send = False
|
| 1133 |
elif default_banned and getattr(default_banned, 'send_messages', False):
|
| 1134 |
can_send = False
|
| 1135 |
+
else:
|
| 1136 |
+
can_send = True
|
| 1137 |
+
except Exception as perm_err:
|
| 1138 |
+
log_debug(f"DIALOGS_PERM_CHECK_ERR: {str(perm_err)}")
|
| 1139 |
+
can_send = False
|
| 1140 |
|
| 1141 |
dialogs_list.append({
|
| 1142 |
"id": did,
|
|
|
|
| 4439 |
if volume == "short":
|
| 4440 |
volume_guidelines = (
|
| 4441 |
"TARGET LENGTH: SHORT & PUNCHY (approx 45-75 words).\n"
|
| 4442 |
+
"- Bold, energetic headline hook with emojis (🔥, ⚡).\n"
|
| 4443 |
+
"- 2-3 crisp bullet highlights (✅, 💎) on separate lines.\n"
|
| 4444 |
+
"- Quick, direct call to action with instruction (e.g. Reply 'INFO' or tap link)."
|
| 4445 |
)
|
| 4446 |
elif volume == "lengthy":
|
| 4447 |
volume_guidelines = (
|
| 4448 |
+
"TARGET LENGTH: LENGTHY, DETAILED & COMPREHENSIVE (approx 200-350 words).\n"
|
| 4449 |
+
"- Attention-grabbing headline hook with emojis (e.g. 📺🔥 ...).\n"
|
| 4450 |
+
"- Opening paragraph: Intriguing problem/solution question or compelling proposition.\n"
|
| 4451 |
+
"- Section 1 with header (e.g. ✅ WHAT WE OFFER) followed by 6 to 8 bullet items (📡, ⚽, 🎬, 🌍, 📺, 📱, 🔧, 🤝) on separate lines detailing features, compatibility, and quality.\n"
|
| 4452 |
+
"- Section 2 with header (e.g. 💎 WHY CHOOSE US) followed by 4 to 5 bullet points (✔️, 🚀, ⚡) highlighting stability, instant setup, responsive support, and guarantee.\n"
|
| 4453 |
+
"- Section 3 with header (e.g. 🚀 READY TO START?) explaining value.\n"
|
| 4454 |
+
"- Clear CTA with instructions (e.g. 💬 Reply 'SUBSCRIBE' or DM to get started).\n"
|
| 4455 |
+
"- Brief disclaimer/licensing note at the bottom."
|
| 4456 |
)
|
| 4457 |
else: # moderate
|
| 4458 |
volume_guidelines = (
|
| 4459 |
+
"TARGET LENGTH: MODERATE & BALANCED (approx 100-160 words).\n"
|
| 4460 |
"- Compelling hook headline with emojis.\n"
|
| 4461 |
"- 1 structured paragraph explaining why this offer matters.\n"
|
| 4462 |
+
"- 4-5 organized bullet points highlighting key features and benefits on separate lines.\n"
|
| 4463 |
"- Clear call to action link."
|
| 4464 |
)
|
| 4465 |
|
|
|
|
| 4471 |
sample_section = ""
|
| 4472 |
if sample_copy:
|
| 4473 |
sample_section = (
|
| 4474 |
+
f"\n\nUSER'S REFERENCE / SAMPLE COPY (FOR INSPIRATION ONLY):\n"
|
| 4475 |
f"\"\"\"\n{sample_copy}\n\"\"\"\n"
|
| 4476 |
+
f"CRITICAL ANTI-PLAGIARISM DIRECTIVE:\n"
|
| 4477 |
+
f"- DO NOT copy, echo, or output the reference copy back verbatim! That is strictly prohibited.\n"
|
| 4478 |
+
f"- Extract the core product/service topic (e.g. IPTV subscriptions, crypto alerts, SaaS tools) and write completely FRESH, NEW variations with unique headline hooks, distinct phrasing, rewritten bullet points, and different calls to action."
|
| 4479 |
)
|
| 4480 |
|
| 4481 |
sys_prompt = (
|
|
|
|
| 4491 |
f"- Variation 3: Social Proof & Problem-Solver\n"
|
| 4492 |
f"- Variation 4: Engaging Conversational Hook\n"
|
| 4493 |
f"- Variation 5: High Urgency & Limited-Time Perk\n\n"
|
| 4494 |
+
f"CRITICAL FORMATTING & PARAGRAPHING RULES:\n"
|
| 4495 |
f"1. THIS IS A TELEGRAM GROUP/CHANNEL PROMOTION BROADCAST, NOT AN EMAIL! Never start messages with 'Hello {{{{First Name}}}}' or letter greetings. Hook the reader immediately with an announcement, curiosity, question, or bold value.\n"
|
| 4496 |
+
f"2. MANDATORY DOUBLE LINE BREAKS: You MUST separate every headline, body paragraph, section title, bullet list, and CTA with double line breaks (\\n\\n). Do NOT clump sentences together into a single block of text!\n"
|
| 4497 |
+
f"3. EMOJIS & BULLETS: Make the content visually engaging and solid by using bullet points (•, 🔥, ⚡, 💎, ✅, ✔️) with each bullet on its own dedicated new line.\n"
|
| 4498 |
f"4. {volume_guidelines}\n"
|
| 4499 |
f"5. {spintax_rule}\n"
|
| 4500 |
f"6. Return ONLY a valid JSON array of {target_count} strings: [\"Message 1...\", \"Message 2...\", ...].\n"
|
|
|
|
| 4539 |
try:
|
| 4540 |
parsed = json.loads(cleaned[start:end+1])
|
| 4541 |
if isinstance(parsed, list):
|
| 4542 |
+
for x in parsed:
|
| 4543 |
+
t = str(x).replace('\\n', '\n').strip()
|
| 4544 |
+
t = re.sub(r'\n{3,}', '\n\n', t)
|
| 4545 |
+
if sample_copy and t.strip().lower() == sample_copy.strip().lower():
|
| 4546 |
+
continue
|
| 4547 |
+
if len(t) > 20:
|
| 4548 |
+
variations.append(t)
|
| 4549 |
except Exception:
|
| 4550 |
try:
|
| 4551 |
fixed = re.sub(r',\s*\]', ']', cleaned[start:end+1])
|
| 4552 |
parsed = json.loads(fixed)
|
| 4553 |
if isinstance(parsed, list):
|
| 4554 |
+
for x in parsed:
|
| 4555 |
+
t = str(x).replace('\\n', '\n').strip()
|
| 4556 |
+
t = re.sub(r'\n{3,}', '\n\n', t)
|
| 4557 |
+
if sample_copy and t.strip().lower() == sample_copy.strip().lower():
|
| 4558 |
+
continue
|
| 4559 |
+
if len(t) > 20:
|
| 4560 |
+
variations.append(t)
|
| 4561 |
except Exception:
|
| 4562 |
pass
|
| 4563 |
|
| 4564 |
if not variations:
|
| 4565 |
blocks = re.split(r'\n(?=(?:Variation|\d+[\.\)]))\s*', cleaned)
|
| 4566 |
+
for b in blocks:
|
| 4567 |
+
t = re.sub(r'^(?:Variation\s*\d+:?|\d+[\.\)])\s*', '', b).strip().strip('"\'')
|
| 4568 |
+
t = t.replace('\\n', '\n')
|
| 4569 |
+
t = re.sub(r'\n{3,}', '\n\n', t)
|
| 4570 |
+
if sample_copy and t.strip().lower() == sample_copy.strip().lower():
|
| 4571 |
+
continue
|
| 4572 |
+
if len(t) > 20:
|
| 4573 |
+
variations.append(t)
|
| 4574 |
|
| 4575 |
if variations:
|
| 4576 |
return {
|
|
|
|
| 4645 |
|
| 4646 |
@app.get("/api/telegram/accounts/{phone}/dms")
|
| 4647 |
async def get_account_dms(phone: str, user_id: str = Depends(get_current_user_id)):
|
| 4648 |
+
"""Safely fetches up to 60 recent 1-on-1 private DMs on-demand across up to 300 dialogs."""
|
| 4649 |
conn = get_db_connection()
|
| 4650 |
row = conn.execute("SELECT session_string, api_id, api_hash FROM accounts WHERE phone_number = ? AND user_id = ?", (phone, user_id)).fetchone()
|
| 4651 |
if hasattr(conn, "close"): conn.close()
|
|
|
|
| 4661 |
|
| 4662 |
dms = []
|
| 4663 |
try:
|
| 4664 |
+
# Scan up to 500 dialogs to find all personal user chats past channels and groups
|
| 4665 |
+
async for dialog in client.iter_dialogs(limit=500):
|
| 4666 |
if dialog.is_user:
|
| 4667 |
entity = dialog.entity
|
| 4668 |
if getattr(entity, 'bot', False):
|
|
|
|
| 4676 |
|
| 4677 |
dms.append({
|
| 4678 |
"id": entity.id,
|
| 4679 |
+
"access_hash": str(getattr(entity, 'access_hash', 0) or 0),
|
| 4680 |
"name": full_name,
|
| 4681 |
"username": getattr(entity, 'username', None),
|
| 4682 |
"phone": getattr(entity, 'phone', None),
|
| 4683 |
+
"last_message": last_msg[:140] if last_msg else "No messages",
|
| 4684 |
"date": dialog.date.isoformat() if dialog.date else None,
|
| 4685 |
"unread_count": dialog.unread_count or 0
|
| 4686 |
})
|
| 4687 |
+
if len(dms) >= 150:
|
| 4688 |
break
|
| 4689 |
return {"dms": dms, "phone": phone, "total": len(dms)}
|
| 4690 |
except Exception as e:
|
|
|
|
| 4693 |
await client.disconnect()
|
| 4694 |
|
| 4695 |
@app.get("/api/telegram/accounts/{phone}/dms/{contact_id}/messages")
|
| 4696 |
+
async def get_dm_messages(phone: str, contact_id: int, access_hash: Optional[str] = None, user_id: str = Depends(get_current_user_id)):
|
| 4697 |
+
"""Fetches the last 50 messages of a private DM conversation with robust entity resolution."""
|
| 4698 |
conn = get_db_connection()
|
| 4699 |
row = conn.execute("SELECT session_string, api_id, api_hash FROM accounts WHERE phone_number = ? AND user_id = ?", (phone, user_id)).fetchone()
|
| 4700 |
if hasattr(conn, "close"): conn.close()
|
|
|
|
| 4709 |
raise HTTPException(status_code=401, detail="Account session expired.")
|
| 4710 |
|
| 4711 |
try:
|
| 4712 |
+
from telethon.tl.types import InputPeerUser
|
| 4713 |
+
entity = None
|
| 4714 |
+
clean_hash = str(access_hash or "").strip()
|
| 4715 |
+
if clean_hash and clean_hash not in ("0", "None", ""):
|
| 4716 |
+
try:
|
| 4717 |
+
entity = InputPeerUser(user_id=int(contact_id), access_hash=int(clean_hash))
|
| 4718 |
+
except Exception:
|
| 4719 |
+
pass
|
| 4720 |
+
|
| 4721 |
+
if entity is None:
|
| 4722 |
+
try:
|
| 4723 |
+
entity = await client.get_input_entity(contact_id)
|
| 4724 |
+
except Exception:
|
| 4725 |
+
# Warm up entity cache by scanning recent dialogs
|
| 4726 |
+
await client.get_dialogs(limit=200)
|
| 4727 |
+
try:
|
| 4728 |
+
entity = await client.get_input_entity(contact_id)
|
| 4729 |
+
except Exception:
|
| 4730 |
+
entity = await client.get_entity(contact_id)
|
| 4731 |
+
|
| 4732 |
me = await client.get_me()
|
| 4733 |
+
full_name = "Telegram User"
|
| 4734 |
+
username = None
|
| 4735 |
+
try:
|
| 4736 |
+
full_user = await client.get_entity(entity)
|
| 4737 |
+
first = getattr(full_user, 'first_name', '') or ''
|
| 4738 |
+
last = getattr(full_user, 'last_name', '') or ''
|
| 4739 |
+
full_name = f"{first} {last}".strip() if (first or last) else "Telegram User"
|
| 4740 |
+
username = getattr(full_user, 'username', None)
|
| 4741 |
+
except Exception:
|
| 4742 |
+
pass
|
| 4743 |
|
| 4744 |
messages_list = []
|
| 4745 |
+
async for msg in client.iter_messages(entity, limit=50):
|
| 4746 |
is_out = msg.out or (msg.sender_id == me.id)
|
| 4747 |
messages_list.append({
|
| 4748 |
"id": msg.id,
|
|
|
|
| 4753 |
messages_list.reverse()
|
| 4754 |
return {
|
| 4755 |
"contact": {
|
| 4756 |
+
"id": contact_id,
|
| 4757 |
"name": full_name,
|
| 4758 |
+
"username": username
|
| 4759 |
},
|
| 4760 |
"messages": messages_list
|
| 4761 |
}
|
| 4762 |
except Exception as e:
|
| 4763 |
+
log_debug(f"DM_FETCH_MSGS_ERR: {str(e)}")
|
| 4764 |
raise HTTPException(status_code=400, detail=f"Failed to load messages: {str(e)}")
|
| 4765 |
finally:
|
| 4766 |
await client.disconnect()
|
|
|
|
| 4768 |
|
| 4769 |
class DMSendRequest(BaseModel):
|
| 4770 |
message: str
|
| 4771 |
+
access_hash: Optional[str] = None
|
| 4772 |
|
| 4773 |
@app.post("/api/telegram/accounts/{phone}/dms/{contact_id}/send")
|
| 4774 |
async def send_dm_message(phone: str, contact_id: int, req: DMSendRequest, user_id: str = Depends(get_current_user_id)):
|
| 4775 |
+
"""Sends a direct message reply to the contact in Telegram with guaranteed entity resolution."""
|
| 4776 |
text = (req.message or "").strip()
|
| 4777 |
if not text:
|
| 4778 |
raise HTTPException(status_code=400, detail="Message text is required")
|
|
|
|
| 4791 |
raise HTTPException(status_code=401, detail="Account session expired.")
|
| 4792 |
|
| 4793 |
try:
|
| 4794 |
+
from telethon.tl.types import InputPeerUser
|
| 4795 |
+
entity = None
|
| 4796 |
+
if req.access_hash and req.access_hash != "0":
|
| 4797 |
+
try:
|
| 4798 |
+
entity = InputPeerUser(user_id=int(contact_id), access_hash=int(req.access_hash))
|
| 4799 |
+
except Exception:
|
| 4800 |
+
pass
|
| 4801 |
+
|
| 4802 |
+
if entity is None:
|
| 4803 |
+
try:
|
| 4804 |
+
entity = await client.get_input_entity(contact_id)
|
| 4805 |
+
except Exception:
|
| 4806 |
+
await client.get_dialogs(limit=100)
|
| 4807 |
+
try:
|
| 4808 |
+
entity = await client.get_input_entity(contact_id)
|
| 4809 |
+
except Exception:
|
| 4810 |
+
entity = await client.get_entity(contact_id)
|
| 4811 |
+
|
| 4812 |
sent_msg = await client.send_message(entity, text)
|
| 4813 |
return {
|
| 4814 |
"status": "success",
|
|
|
|
| 4820 |
}
|
| 4821 |
}
|
| 4822 |
except Exception as e:
|
| 4823 |
+
log_debug(f"DM_SEND_REPLY_ERR: {str(e)}")
|
| 4824 |
raise HTTPException(status_code=400, detail=f"Failed to send reply: {str(e)}")
|
| 4825 |
finally:
|
| 4826 |
await client.disconnect()
|
frontend/src/app/ai-assistant/page.tsx
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
frontend/src/app/campaigns/page.tsx
CHANGED
|
@@ -64,11 +64,13 @@ export default function CampaignsPage() {
|
|
| 64 |
const [isUploadingMedia, setIsUploadingMedia] = useState(false);
|
| 65 |
|
| 66 |
const [loading, setLoading] = useState(false);
|
|
|
|
| 67 |
const [success, setSuccess] = useState(false);
|
| 68 |
const [editingId, setEditingId] = useState<number | null>(null);
|
| 69 |
-
const [creationError, setCreationError] = useState("");
|
| 70 |
const [isSpintaxModalOpen, setIsSpintaxModalOpen] = useState(false);
|
| 71 |
const [isAiAssistantOpen, setIsAiAssistantOpen] = useState(false);
|
|
|
|
|
|
|
| 72 |
|
| 73 |
const [loadingTasks, setLoadingTasks] = useState(true);
|
| 74 |
const [currentPage, setCurrentPage] = useState(1);
|
|
@@ -478,7 +480,10 @@ export default function CampaignsPage() {
|
|
| 478 |
const matchesType = filterType === 'all' ||
|
| 479 |
(filterType === 'channels' && (d.is_channel || d.type === 'channel')) ||
|
| 480 |
(filterType === 'groups' && (!d.is_channel && d.type !== 'channel'));
|
| 481 |
-
|
|
|
|
|
|
|
|
|
|
| 482 |
});
|
| 483 |
|
| 484 |
const getStatusColor = (status: string) => {
|
|
@@ -856,6 +861,12 @@ export default function CampaignsPage() {
|
|
| 856 |
</div>
|
| 857 |
) : (
|
| 858 |
<form onSubmit={handleSubmit} id="campaign-form" className="space-y-4">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 859 |
{/* Top Form Grid */}
|
| 860 |
<div className="grid grid-cols-1 md:grid-cols-2 gap-3.5">
|
| 861 |
<div className="space-y-1">
|
|
@@ -881,57 +892,171 @@ export default function CampaignsPage() {
|
|
| 881 |
</span>
|
| 882 |
)}
|
| 883 |
</div>
|
|
|
|
|
|
|
| 884 |
<div className="relative">
|
| 885 |
-
|
| 886 |
-
|
| 887 |
-
|
| 888 |
-
|
| 889 |
-
|
| 890 |
-
|
| 891 |
-
|
| 892 |
-
|
| 893 |
-
|
| 894 |
-
|
| 895 |
-
|
| 896 |
-
|
| 897 |
-
|
| 898 |
-
|
| 899 |
-
|
| 900 |
-
|
| 901 |
-
|
| 902 |
-
|
| 903 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 904 |
</div>
|
| 905 |
</div>
|
| 906 |
</div>
|
| 907 |
|
| 908 |
{/* Schedule & Intervals */}
|
| 909 |
<div className="grid grid-cols-1 md:grid-cols-3 gap-3.5">
|
| 910 |
-
<div className="space-y-1">
|
| 911 |
<div className="flex items-center justify-between">
|
| 912 |
<label className="text-[11px] font-bold text-foreground/40 uppercase tracking-wider ml-0.5 flex items-center gap-1">
|
| 913 |
<Calendar size={11} className="text-indigo-400" />
|
| 914 |
<span>Target Run Time</span>
|
| 915 |
</label>
|
| 916 |
-
<
|
| 917 |
-
|
| 918 |
-
|
| 919 |
-
|
| 920 |
-
|
| 921 |
-
|
| 922 |
-
|
| 923 |
-
|
| 924 |
-
|
| 925 |
-
|
| 926 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 927 |
</div>
|
| 928 |
-
<
|
| 929 |
-
|
| 930 |
-
|
| 931 |
-
|
| 932 |
-
|
| 933 |
-
|
| 934 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 935 |
</div>
|
| 936 |
|
| 937 |
<div className="space-y-1">
|
|
@@ -1231,14 +1356,47 @@ export default function CampaignsPage() {
|
|
| 1231 |
|
| 1232 |
{/* Target Card with Independent Isolated Scroll (Item 6) */}
|
| 1233 |
<div className="flex flex-col h-[270px] max-h-[270px] bg-background/50 border border-border/80 rounded-xl overflow-hidden shrink-0">
|
| 1234 |
-
<div className="p-2 px-3 border-b border-border/60 bg-foreground/[0.02] flex justify-between items-center shrink-0">
|
| 1235 |
-
<
|
| 1236 |
-
|
| 1237 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1238 |
<div className="flex items-center gap-1">
|
| 1239 |
-
<button type="button" disabled={currentPage === 1} onClick={() => setCurrentPage(p => p - 1)} className="p-1 hover:bg-foreground/5 rounded-md disabled:opacity-20"><ChevronLeft size={13} /></button>
|
| 1240 |
<span className="text-[10px] font-bold text-foreground/40 px-1">{currentPage} / {Math.max(1, Math.ceil(filteredDialogs.length / pageSize))}</span>
|
| 1241 |
-
<button type="button" disabled={currentPage * pageSize >= filteredDialogs.length} onClick={() => setCurrentPage(p => p + 1)} className="p-1 hover:bg-foreground/5 rounded-md disabled:opacity-20"><ChevronRight size={13} /></button>
|
| 1242 |
</div>
|
| 1243 |
</div>
|
| 1244 |
|
|
|
|
| 64 |
const [isUploadingMedia, setIsUploadingMedia] = useState(false);
|
| 65 |
|
| 66 |
const [loading, setLoading] = useState(false);
|
| 67 |
+
const [creationError, setCreationError] = useState("");
|
| 68 |
const [success, setSuccess] = useState(false);
|
| 69 |
const [editingId, setEditingId] = useState<number | null>(null);
|
|
|
|
| 70 |
const [isSpintaxModalOpen, setIsSpintaxModalOpen] = useState(false);
|
| 71 |
const [isAiAssistantOpen, setIsAiAssistantOpen] = useState(false);
|
| 72 |
+
const [isAccountDropdownOpen, setIsAccountDropdownOpen] = useState(false);
|
| 73 |
+
const [groupPermissionFilter, setGroupPermissionFilter] = useState<'all' | 'sendable' | 'restricted'>('all');
|
| 74 |
|
| 75 |
const [loadingTasks, setLoadingTasks] = useState(true);
|
| 76 |
const [currentPage, setCurrentPage] = useState(1);
|
|
|
|
| 480 |
const matchesType = filterType === 'all' ||
|
| 481 |
(filterType === 'channels' && (d.is_channel || d.type === 'channel')) ||
|
| 482 |
(filterType === 'groups' && (!d.is_channel && d.type !== 'channel'));
|
| 483 |
+
const matchesPermission = groupPermissionFilter === 'all' ||
|
| 484 |
+
(groupPermissionFilter === 'sendable' && d.can_send !== false) ||
|
| 485 |
+
(groupPermissionFilter === 'restricted' && d.can_send === false);
|
| 486 |
+
return matchesSearch && !isExcluded && matchesType && matchesPermission;
|
| 487 |
});
|
| 488 |
|
| 489 |
const getStatusColor = (status: string) => {
|
|
|
|
| 861 |
</div>
|
| 862 |
) : (
|
| 863 |
<form onSubmit={handleSubmit} id="campaign-form" className="space-y-4">
|
| 864 |
+
{creationError && (
|
| 865 |
+
<div className="p-3 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400 text-xs font-semibold flex items-center gap-2">
|
| 866 |
+
<AlertCircle size={14} className="shrink-0" />
|
| 867 |
+
<span>{creationError}</span>
|
| 868 |
+
</div>
|
| 869 |
+
)}
|
| 870 |
{/* Top Form Grid */}
|
| 871 |
<div className="grid grid-cols-1 md:grid-cols-2 gap-3.5">
|
| 872 |
<div className="space-y-1">
|
|
|
|
| 892 |
</span>
|
| 893 |
)}
|
| 894 |
</div>
|
| 895 |
+
|
| 896 |
+
{/* Custom Modern Account Selector Dropdown */}
|
| 897 |
<div className="relative">
|
| 898 |
+
{(() => {
|
| 899 |
+
const selectedAcc = accounts.find(a => a.phone_number === campaignData.phone_number);
|
| 900 |
+
return (
|
| 901 |
+
<>
|
| 902 |
+
<button
|
| 903 |
+
type="button"
|
| 904 |
+
onClick={() => setIsAccountDropdownOpen(!isAccountDropdownOpen)}
|
| 905 |
+
className="w-full bg-input hover:bg-card border border-border/80 hover:border-indigo-500/40 rounded-xl py-2 px-3 flex items-center justify-between text-xs text-foreground focus:ring-2 focus:ring-indigo-500/20 transition-all cursor-pointer shadow-sm group"
|
| 906 |
+
>
|
| 907 |
+
<div className="flex items-center gap-2.5 min-w-0">
|
| 908 |
+
{selectedAcc ? (
|
| 909 |
+
<>
|
| 910 |
+
<div className="relative w-6 h-6 rounded-lg bg-indigo-500/20 text-indigo-400 font-bold text-[10px] flex items-center justify-center shrink-0 border border-indigo-500/30 overflow-hidden">
|
| 911 |
+
{selectedAcc.profile_photo ? (
|
| 912 |
+
<img src={selectedAcc.profile_photo} alt="" className="w-full h-full object-cover" />
|
| 913 |
+
) : (
|
| 914 |
+
<span>{selectedAcc.first_name?.charAt(0) || selectedAcc.phone_number?.slice(-2) || 'A'}</span>
|
| 915 |
+
)}
|
| 916 |
+
<span className="absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full bg-emerald-400 ring-1 ring-card" />
|
| 917 |
+
</div>
|
| 918 |
+
<div className="text-left truncate">
|
| 919 |
+
<span className="font-bold text-foreground block truncate leading-tight">
|
| 920 |
+
{selectedAcc.first_name ? `${selectedAcc.first_name} ${selectedAcc.last_name || ''}` : selectedAcc.phone_number}
|
| 921 |
+
</span>
|
| 922 |
+
<span className="text-[10px] text-foreground/45 font-mono">
|
| 923 |
+
{selectedAcc.phone_number} {selectedAcc.username ? `• @${selectedAcc.username}` : ''}
|
| 924 |
+
</span>
|
| 925 |
+
</div>
|
| 926 |
+
</>
|
| 927 |
+
) : (
|
| 928 |
+
<span className="text-foreground/40 font-medium">Select Transmitting Account Node...</span>
|
| 929 |
+
)}
|
| 930 |
+
</div>
|
| 931 |
+
<div className="text-foreground/40 group-hover:text-foreground transition-colors shrink-0 ml-2">
|
| 932 |
+
<ChevronDown size={14} className={`transition-transform duration-200 ${isAccountDropdownOpen ? 'rotate-180' : ''}`} />
|
| 933 |
+
</div>
|
| 934 |
+
</button>
|
| 935 |
+
|
| 936 |
+
{isAccountDropdownOpen && (
|
| 937 |
+
<>
|
| 938 |
+
<div className="fixed inset-0 z-40" onClick={() => setIsAccountDropdownOpen(false)} />
|
| 939 |
+
<div className="absolute top-full left-0 right-0 mt-1.5 z-50 bg-card border border-border rounded-xl shadow-2xl p-1.5 space-y-1 max-h-60 overflow-y-auto custom-scrollbar animate-in fade-in-50 zoom-in-95">
|
| 940 |
+
{accounts.map(acc => {
|
| 941 |
+
const isSelected = acc.phone_number === campaignData.phone_number;
|
| 942 |
+
return (
|
| 943 |
+
<div
|
| 944 |
+
key={acc.phone_number}
|
| 945 |
+
onClick={() => {
|
| 946 |
+
setCampaignData({ ...campaignData, phone_number: acc.phone_number });
|
| 947 |
+
fetchDialogs(acc.phone_number);
|
| 948 |
+
setIsAccountDropdownOpen(false);
|
| 949 |
+
}}
|
| 950 |
+
className={`p-2 rounded-lg flex items-center justify-between gap-2.5 transition-all cursor-pointer ${
|
| 951 |
+
isSelected ? 'bg-indigo-500/15 border border-indigo-500/30 text-indigo-300' : 'hover:bg-foreground/5 text-foreground/80'
|
| 952 |
+
}`}
|
| 953 |
+
>
|
| 954 |
+
<div className="flex items-center gap-2.5 min-w-0">
|
| 955 |
+
<div className="relative w-7 h-7 rounded-lg bg-indigo-500/15 text-indigo-400 font-bold text-xs flex items-center justify-center shrink-0 border border-indigo-500/25 overflow-hidden">
|
| 956 |
+
{acc.profile_photo ? (
|
| 957 |
+
<img src={acc.profile_photo} alt="" className="w-full h-full object-cover" />
|
| 958 |
+
) : (
|
| 959 |
+
<span>{acc.first_name?.charAt(0) || acc.phone_number?.slice(-2) || 'A'}</span>
|
| 960 |
+
)}
|
| 961 |
+
<span className="absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full bg-emerald-400 ring-1 ring-card" />
|
| 962 |
+
</div>
|
| 963 |
+
<div className="text-left min-w-0">
|
| 964 |
+
<div className="font-bold text-xs truncate text-foreground flex items-center gap-1.5">
|
| 965 |
+
<span>{acc.first_name ? `${acc.first_name} ${acc.last_name || ''}` : acc.phone_number}</span>
|
| 966 |
+
{acc.is_primary && (
|
| 967 |
+
<span className="text-[9px] px-1 py-0.2 rounded bg-indigo-500/20 text-indigo-400 font-semibold">Primary</span>
|
| 968 |
+
)}
|
| 969 |
+
</div>
|
| 970 |
+
<div className="text-[10px] text-foreground/45 font-mono truncate">
|
| 971 |
+
{acc.phone_number} {acc.country ? `• ${acc.country}` : ''}
|
| 972 |
+
</div>
|
| 973 |
+
</div>
|
| 974 |
+
</div>
|
| 975 |
+
{isSelected && <Check size={14} className="text-indigo-400 shrink-0" />}
|
| 976 |
+
</div>
|
| 977 |
+
);
|
| 978 |
+
})}
|
| 979 |
+
</div>
|
| 980 |
+
</>
|
| 981 |
+
)}
|
| 982 |
+
</>
|
| 983 |
+
);
|
| 984 |
+
})()}
|
| 985 |
</div>
|
| 986 |
</div>
|
| 987 |
</div>
|
| 988 |
|
| 989 |
{/* Schedule & Intervals */}
|
| 990 |
<div className="grid grid-cols-1 md:grid-cols-3 gap-3.5">
|
| 991 |
+
<div className="space-y-1.5">
|
| 992 |
<div className="flex items-center justify-between">
|
| 993 |
<label className="text-[11px] font-bold text-foreground/40 uppercase tracking-wider ml-0.5 flex items-center gap-1">
|
| 994 |
<Calendar size={11} className="text-indigo-400" />
|
| 995 |
<span>Target Run Time</span>
|
| 996 |
</label>
|
| 997 |
+
<div className="flex items-center gap-1 text-[10px]">
|
| 998 |
+
<button
|
| 999 |
+
type="button"
|
| 1000 |
+
onClick={() => {
|
| 1001 |
+
const now = new Date();
|
| 1002 |
+
const nowISO = new Date(now.getTime() - (now.getTimezoneOffset() * 60000)).toISOString().slice(0, 16);
|
| 1003 |
+
setCampaignData(prev => ({ ...prev, schedule_time: nowISO }));
|
| 1004 |
+
}}
|
| 1005 |
+
className="px-1.5 py-0.5 rounded bg-indigo-500/10 text-indigo-400 hover:bg-indigo-500/20 font-bold transition-all cursor-pointer"
|
| 1006 |
+
>
|
| 1007 |
+
Now
|
| 1008 |
+
</button>
|
| 1009 |
+
<button
|
| 1010 |
+
type="button"
|
| 1011 |
+
onClick={() => {
|
| 1012 |
+
const d = new Date(Date.now() + 15 * 60000);
|
| 1013 |
+
const iso = new Date(d.getTime() - (d.getTimezoneOffset() * 60000)).toISOString().slice(0, 16);
|
| 1014 |
+
setCampaignData(prev => ({ ...prev, schedule_time: iso }));
|
| 1015 |
+
}}
|
| 1016 |
+
className="px-1.5 py-0.5 rounded bg-foreground/5 text-foreground/60 hover:text-foreground font-semibold transition-all cursor-pointer"
|
| 1017 |
+
>
|
| 1018 |
+
+15m
|
| 1019 |
+
</button>
|
| 1020 |
+
<button
|
| 1021 |
+
type="button"
|
| 1022 |
+
onClick={() => {
|
| 1023 |
+
const d = new Date(Date.now() + 60 * 60000);
|
| 1024 |
+
const iso = new Date(d.getTime() - (d.getTimezoneOffset() * 60000)).toISOString().slice(0, 16);
|
| 1025 |
+
setCampaignData(prev => ({ ...prev, schedule_time: iso }));
|
| 1026 |
+
}}
|
| 1027 |
+
className="px-1.5 py-0.5 rounded bg-foreground/5 text-foreground/60 hover:text-foreground font-semibold transition-all cursor-pointer"
|
| 1028 |
+
>
|
| 1029 |
+
+1h
|
| 1030 |
+
</button>
|
| 1031 |
+
<button
|
| 1032 |
+
type="button"
|
| 1033 |
+
onClick={() => {
|
| 1034 |
+
const d = new Date();
|
| 1035 |
+
d.setDate(d.getDate() + 1);
|
| 1036 |
+
d.setHours(9, 0, 0, 0);
|
| 1037 |
+
const iso = new Date(d.getTime() - (d.getTimezoneOffset() * 60000)).toISOString().slice(0, 16);
|
| 1038 |
+
setCampaignData(prev => ({ ...prev, schedule_time: iso }));
|
| 1039 |
+
}}
|
| 1040 |
+
className="px-1.5 py-0.5 rounded bg-foreground/5 text-foreground/60 hover:text-foreground font-semibold transition-all cursor-pointer"
|
| 1041 |
+
>
|
| 1042 |
+
Tmr 9AM
|
| 1043 |
+
</button>
|
| 1044 |
+
</div>
|
| 1045 |
</div>
|
| 1046 |
+
<div className="relative">
|
| 1047 |
+
<input
|
| 1048 |
+
type="datetime-local"
|
| 1049 |
+
required
|
| 1050 |
+
value={campaignData.schedule_time}
|
| 1051 |
+
onChange={(e) => setCampaignData({ ...campaignData, schedule_time: e.target.value })}
|
| 1052 |
+
className="w-full bg-input hover:bg-card border border-border/80 hover:border-indigo-500/40 focus:border-indigo-500 rounded-xl py-2 px-3 text-xs font-semibold text-foreground focus:ring-2 focus:ring-indigo-500/20 outline-none transition-all shadow-sm [color-scheme:dark]"
|
| 1053 |
+
/>
|
| 1054 |
+
</div>
|
| 1055 |
+
{campaignData.schedule_time && (
|
| 1056 |
+
<p className="text-[10px] text-indigo-400 font-medium pl-1">
|
| 1057 |
+
⚡ Scheduled for: {new Date(campaignData.schedule_time).toLocaleString(undefined, { dateStyle: 'medium', timeStyle: 'short' })}
|
| 1058 |
+
</p>
|
| 1059 |
+
)}
|
| 1060 |
</div>
|
| 1061 |
|
| 1062 |
<div className="space-y-1">
|
|
|
|
| 1356 |
|
| 1357 |
{/* Target Card with Independent Isolated Scroll (Item 6) */}
|
| 1358 |
<div className="flex flex-col h-[270px] max-h-[270px] bg-background/50 border border-border/80 rounded-xl overflow-hidden shrink-0">
|
| 1359 |
+
<div className="p-2 px-3 border-b border-border/60 bg-foreground/[0.02] flex justify-between items-center shrink-0 flex-wrap gap-1.5">
|
| 1360 |
+
<div className="flex items-center gap-1.5">
|
| 1361 |
+
<span className="text-[10px] font-bold text-foreground/50">
|
| 1362 |
+
{filteredDialogs.length} targets
|
| 1363 |
+
</span>
|
| 1364 |
+
<div className="flex items-center gap-0.5 bg-background/80 p-0.5 rounded-lg border border-border/60">
|
| 1365 |
+
<button
|
| 1366 |
+
type="button"
|
| 1367 |
+
onClick={() => { setGroupPermissionFilter('all'); setCurrentPage(1); }}
|
| 1368 |
+
className={`px-1.5 py-0.5 rounded text-[9px] font-bold transition-all cursor-pointer ${
|
| 1369 |
+
groupPermissionFilter === 'all' ? 'bg-indigo-600 text-white' : 'text-foreground/50 hover:text-foreground'
|
| 1370 |
+
}`}
|
| 1371 |
+
>
|
| 1372 |
+
All
|
| 1373 |
+
</button>
|
| 1374 |
+
<button
|
| 1375 |
+
type="button"
|
| 1376 |
+
onClick={() => { setGroupPermissionFilter('sendable'); setCurrentPage(1); }}
|
| 1377 |
+
className={`px-1.5 py-0.5 rounded text-[9px] font-bold transition-all cursor-pointer flex items-center gap-0.5 ${
|
| 1378 |
+
groupPermissionFilter === 'sendable' ? 'bg-emerald-600 text-white shadow-xs' : 'text-emerald-400 hover:text-emerald-300'
|
| 1379 |
+
}`}
|
| 1380 |
+
title="Only show groups where sending messages is allowed"
|
| 1381 |
+
>
|
| 1382 |
+
<span>✓ Sendable</span>
|
| 1383 |
+
</button>
|
| 1384 |
+
<button
|
| 1385 |
+
type="button"
|
| 1386 |
+
onClick={() => { setGroupPermissionFilter('restricted'); setCurrentPage(1); }}
|
| 1387 |
+
className={`px-1.5 py-0.5 rounded text-[9px] font-bold transition-all cursor-pointer flex items-center gap-0.5 ${
|
| 1388 |
+
groupPermissionFilter === 'restricted' ? 'bg-rose-600 text-white shadow-xs' : 'text-rose-400 hover:text-rose-300'
|
| 1389 |
+
}`}
|
| 1390 |
+
title="Read-only channels or posting restricted"
|
| 1391 |
+
>
|
| 1392 |
+
<span>✕ Restricted</span>
|
| 1393 |
+
</button>
|
| 1394 |
+
</div>
|
| 1395 |
+
</div>
|
| 1396 |
<div className="flex items-center gap-1">
|
| 1397 |
+
<button type="button" disabled={currentPage === 1} onClick={() => setCurrentPage(p => p - 1)} className="p-1 hover:bg-foreground/5 rounded-md disabled:opacity-20 cursor-pointer"><ChevronLeft size={13} /></button>
|
| 1398 |
<span className="text-[10px] font-bold text-foreground/40 px-1">{currentPage} / {Math.max(1, Math.ceil(filteredDialogs.length / pageSize))}</span>
|
| 1399 |
+
<button type="button" disabled={currentPage * pageSize >= filteredDialogs.length} onClick={() => setCurrentPage(p => p + 1)} className="p-1 hover:bg-foreground/5 rounded-md disabled:opacity-20 cursor-pointer"><ChevronRight size={13} /></button>
|
| 1400 |
</div>
|
| 1401 |
</div>
|
| 1402 |
|
frontend/src/app/scraper/page.tsx
CHANGED
|
@@ -4,7 +4,7 @@ import React, { useState, useRef, useEffect } from 'react';
|
|
| 4 |
import {
|
| 5 |
Search, Loader2, Users, UsersRound, Megaphone, CheckCircle2, X, ExternalLink, Plus, AlertCircle,
|
| 6 |
Sparkles, Settings2, Download, Copy, ChevronDown, ChevronUp, Minimize2, Maximize2, Zap, Sliders, Check, FileText,
|
| 7 |
-
Cpu, Eye, EyeOff, RefreshCw, Key
|
| 8 |
} from 'lucide-react';
|
| 9 |
import { apiFetch, getApiBase } from '@/lib/auth';
|
| 10 |
import { Preloader } from '@/components/Preloader';
|
|
@@ -1473,31 +1473,81 @@ export default function ScraperPage() {
|
|
| 1473 |
</div>
|
| 1474 |
)}
|
| 1475 |
|
| 1476 |
-
{/*
|
| 1477 |
-
|
| 1478 |
-
<div className="
|
| 1479 |
-
<
|
| 1480 |
-
<
|
| 1481 |
-
|
| 1482 |
-
|
| 1483 |
-
|
| 1484 |
-
|
| 1485 |
-
|
| 1486 |
-
|
| 1487 |
-
<
|
| 1488 |
-
|
| 1489 |
-
|
| 1490 |
-
|
| 1491 |
-
|
| 1492 |
-
|
| 1493 |
-
|
| 1494 |
-
|
|
|
|
|
|
|
| 1495 |
</div>
|
| 1496 |
-
|
| 1497 |
-
<div className="
|
| 1498 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1499 |
</div>
|
| 1500 |
-
|
| 1501 |
</div>
|
| 1502 |
|
| 1503 |
{/* Action Bar Footer */}
|
|
|
|
| 4 |
import {
|
| 5 |
Search, Loader2, Users, UsersRound, Megaphone, CheckCircle2, X, ExternalLink, Plus, AlertCircle,
|
| 6 |
Sparkles, Settings2, Download, Copy, ChevronDown, ChevronUp, Minimize2, Maximize2, Zap, Sliders, Check, FileText,
|
| 7 |
+
Cpu, Eye, EyeOff, RefreshCw, Key, Radio
|
| 8 |
} from 'lucide-react';
|
| 9 |
import { apiFetch, getApiBase } from '@/lib/auth';
|
| 10 |
import { Preloader } from '@/components/Preloader';
|
|
|
|
| 1473 |
</div>
|
| 1474 |
)}
|
| 1475 |
|
| 1476 |
+
{/* Native Scrollable Live Feed Stream */}
|
| 1477 |
+
<div className="space-y-2">
|
| 1478 |
+
<div className="flex items-center justify-between">
|
| 1479 |
+
<span className="text-[11px] font-bold text-foreground/40 uppercase tracking-wider flex items-center gap-1.5">
|
| 1480 |
+
<Radio size={12} className="text-emerald-400 animate-pulse" />
|
| 1481 |
+
<span>Live Channel Feed & Recent Posts</span>
|
| 1482 |
+
{previewData?.posts && previewData.posts.length > 0 && (
|
| 1483 |
+
<span className="text-[9px] px-1.5 py-0.2 rounded-full bg-indigo-500/10 text-indigo-400 font-mono font-bold">
|
| 1484 |
+
{previewData.posts.length} Posts
|
| 1485 |
+
</span>
|
| 1486 |
+
)}
|
| 1487 |
+
</span>
|
| 1488 |
+
<a
|
| 1489 |
+
href={`https://t.me/s/${(previewData?.username || previewItem.username || '').replace('@', '')}`}
|
| 1490 |
+
target="_blank"
|
| 1491 |
+
rel="noopener noreferrer"
|
| 1492 |
+
className="text-[10px] text-indigo-400 hover:text-indigo-300 font-mono flex items-center gap-1"
|
| 1493 |
+
>
|
| 1494 |
+
<span>t.me/s/{(previewData?.username || previewItem.username || '').replace('@', '')}</span>
|
| 1495 |
+
<ExternalLink size={10} />
|
| 1496 |
+
</a>
|
| 1497 |
</div>
|
| 1498 |
+
|
| 1499 |
+
<div className="w-full max-h-96 min-h-[180px] rounded-xl overflow-y-auto border border-border/80 bg-background/60 p-3 space-y-3 custom-scrollbar">
|
| 1500 |
+
{isPreviewLoading ? (
|
| 1501 |
+
<div className="flex flex-col items-center justify-center py-12 text-foreground/40">
|
| 1502 |
+
<Loader2 size={24} className="animate-spin text-indigo-500 mb-2" />
|
| 1503 |
+
<span className="text-xs font-semibold">Connecting to live Telegram stream...</span>
|
| 1504 |
+
</div>
|
| 1505 |
+
) : previewData?.posts && previewData.posts.length > 0 ? (
|
| 1506 |
+
previewData.posts.map((post: any, pIdx: number) => (
|
| 1507 |
+
<div key={pIdx} className="p-3 rounded-xl bg-card border border-border/60 hover:border-indigo-500/30 transition-all space-y-2 shadow-xs">
|
| 1508 |
+
{post.photo_url && (
|
| 1509 |
+
<div className="w-full rounded-lg overflow-hidden max-h-56 bg-black/20 flex items-center justify-center">
|
| 1510 |
+
<img
|
| 1511 |
+
src={post.photo_url}
|
| 1512 |
+
alt="Post media"
|
| 1513 |
+
className="w-full h-auto max-h-56 object-cover rounded-lg"
|
| 1514 |
+
onError={(e) => { (e.target as HTMLElement).style.display = 'none'; }}
|
| 1515 |
+
/>
|
| 1516 |
+
</div>
|
| 1517 |
+
)}
|
| 1518 |
+
{post.text && (
|
| 1519 |
+
<p className="text-xs text-foreground/85 whitespace-pre-wrap leading-relaxed font-sans select-text">
|
| 1520 |
+
{post.text}
|
| 1521 |
+
</p>
|
| 1522 |
+
)}
|
| 1523 |
+
<div className="flex items-center justify-between pt-1 border-t border-border/40 text-[10px] text-foreground/40 font-mono">
|
| 1524 |
+
<span>{post.date || 'Recent'}</span>
|
| 1525 |
+
{post.views && (
|
| 1526 |
+
<span className="flex items-center gap-1 bg-foreground/5 px-1.5 py-0.5 rounded text-foreground/60 font-semibold">
|
| 1527 |
+
<Eye size={10} /> {post.views}
|
| 1528 |
+
</span>
|
| 1529 |
+
)}
|
| 1530 |
+
</div>
|
| 1531 |
+
</div>
|
| 1532 |
+
))
|
| 1533 |
+
) : (
|
| 1534 |
+
<div className="p-8 text-center space-y-2">
|
| 1535 |
+
<p className="text-xs font-medium text-foreground/60">
|
| 1536 |
+
No public feed posts accessible or this is a closed group with restricted history.
|
| 1537 |
+
</p>
|
| 1538 |
+
<a
|
| 1539 |
+
href={`https://t.me/${(previewData?.username || previewItem.username || '').replace('@', '')}`}
|
| 1540 |
+
target="_blank"
|
| 1541 |
+
rel="noopener noreferrer"
|
| 1542 |
+
className="inline-flex items-center gap-1 text-xs text-indigo-400 hover:text-indigo-300 font-semibold"
|
| 1543 |
+
>
|
| 1544 |
+
<span>View Community Directly on Telegram</span>
|
| 1545 |
+
<ExternalLink size={12} />
|
| 1546 |
+
</a>
|
| 1547 |
+
</div>
|
| 1548 |
+
)}
|
| 1549 |
</div>
|
| 1550 |
+
</div>
|
| 1551 |
</div>
|
| 1552 |
|
| 1553 |
{/* Action Bar Footer */}
|
frontend/src/components/SpintaxModal.tsx
CHANGED
|
@@ -26,6 +26,24 @@ interface SpintaxModalProps {
|
|
| 26 |
|
| 27 |
// Built-in intelligent vocabulary dictionary for deep 80%-90% natural spintaxing
|
| 28 |
const SYNONYMS_MAP: Record<string, string[]> = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
// Greetings & Openers
|
| 30 |
"hello": ["Hello", "Hi", "Hey", "Greetings", "Welcome"],
|
| 31 |
"hi": ["Hi", "Hello", "Hey", "Good day", "Greetings"],
|
|
@@ -34,66 +52,88 @@ const SYNONYMS_MAP: Record<string, string[]> = {
|
|
| 34 |
"good day": ["Good day", "Hello", "Hi", "Greetings", "Welcome"],
|
| 35 |
"hey there": ["Hey there", "Hello", "Hi folks", "Hey everyone", "Greetings"],
|
| 36 |
|
| 37 |
-
// Openings &
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
"hope you are well": ["hope you're doing great", "hope all is well with you", "hope you are having a productive day", "trust you are doing well", "hope your week is going great"],
|
| 39 |
"i wanted to reach out": ["reaching out to you", "connecting with you", "just wanted to drop a quick line", "wanted to touch base", "reaching out directly"],
|
| 40 |
"quick question": ["brief inquiry", "quick question for you", "short question", "quick thought", "quick query"],
|
| 41 |
"take a look": ["check out", "take a look at", "explore", "discover", "dive into"],
|
| 42 |
"check out": ["check out", "take a look at", "explore", "have a look at", "inspect"],
|
| 43 |
-
"are you looking for": ["in search of", "looking to find", "interested in", "seeking", "on the hunt for"],
|
| 44 |
"don't miss out": ["be sure not to miss", "don't miss this opportunity", "grab this while available", "act quickly", "don't sleep on this"],
|
| 45 |
|
| 46 |
-
//
|
| 47 |
-
"
|
| 48 |
-
"
|
| 49 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
"exclusive": ["exclusive", "limited", "VIP", "premier", "private"],
|
| 51 |
-
"affordable": ["cost-effective", "budget-friendly", "highly affordable", "valuable"
|
| 52 |
"fast": ["lightning-fast", "ultra-quick", "instant", "rapid", "swift"],
|
| 53 |
-
"
|
| 54 |
-
"powerful": ["high-performance", "robust", "powerful", "heavy-duty", "advanced"],
|
| 55 |
"easy": ["effortless", "seamless", "simple", "straightforward", "hassle-free"],
|
| 56 |
-
"new": ["brand-new", "latest", "fresh", "cutting-edge"
|
| 57 |
-
"huge": ["massive", "substantial", "enormous", "huge"
|
| 58 |
-
"opportunity": ["chance", "opportunity", "opening", "
|
| 59 |
-
"results": ["outcomes", "results", "returns", "
|
| 60 |
-
"solution": ["solution", "platform", "system", "setup"
|
| 61 |
|
| 62 |
-
// Verbs
|
| 63 |
"offer": ["provide", "deliver", "present", "offer", "bring you"],
|
|
|
|
| 64 |
"provide": ["deliver", "provide", "supply", "furnish", "offer"],
|
| 65 |
"help": ["assist", "support", "empower", "help", "guide"],
|
|
|
|
| 66 |
"boost": ["elevate", "supercharge", "boost", "maximize", "scale up"],
|
| 67 |
-
"grow": ["scale", "expand", "grow", "accelerate"
|
| 68 |
"get": ["obtain", "access", "secure", "unlock", "claim"],
|
| 69 |
"discover": ["uncover", "explore", "discover", "learn about", "find"],
|
| 70 |
-
"join": ["hop into", "join", "become part of", "connect with"
|
| 71 |
"start": ["kick off", "begin", "launch", "start", "get rolling with"],
|
| 72 |
-
"save": ["save", "cut down on", "reduce", "pocket extra"
|
| 73 |
-
"earn": ["make", "generate", "earn", "pull in"
|
| 74 |
-
"
|
| 75 |
-
"
|
|
|
|
| 76 |
|
| 77 |
-
// Transitions
|
| 78 |
"also": ["furthermore", "additionally", "moreover", "in addition", "plus"],
|
| 79 |
"additionally": ["also", "furthermore", "moreover", "plus", "on top of that"],
|
| 80 |
-
"besides": ["moreover", "furthermore", "also", "in addition", "what's more"],
|
| 81 |
-
"in fact": ["actually", "truth is", "as a matter of fact", "in reality"],
|
| 82 |
-
"for example": ["for instance", "as an example", "such as", "take for instance"],
|
| 83 |
"right now": ["currently", "at this moment", "today", "right now", "instantly"],
|
| 84 |
-
|
| 85 |
-
// Calls to Action & Urgency
|
| 86 |
-
"contact us": ["reach out to us", "send us a message", "drop us a DM", "connect with our team", "contact us"],
|
| 87 |
-
"reach out": ["reach out", "send a direct message", "get in touch", "contact us", "drop a message"],
|
| 88 |
-
"let me know": ["let me know your thoughts", "feel free to reply", "drop a reply", "let us know what you think", "shoot me a message"],
|
| 89 |
-
"click here": ["visit here", "check the link", "click below", "explore here", "tap the link below"],
|
| 90 |
-
"dm me": ["DM me", "send a direct message", "message me directly", "drop a message", "reach out via DM"],
|
| 91 |
-
"check the link": ["follow the link", "visit the URL", "check the link", "tap below", "head over to the link"],
|
| 92 |
-
|
| 93 |
-
// Closings & Signoffs
|
| 94 |
-
"best regards": ["Best regards", "Warm regards", "Cheers", "Talk soon", "Respectfully"],
|
| 95 |
-
"thanks": ["Thanks", "Thank you", "Much appreciated", "Many thanks", "Cheers"],
|
| 96 |
-
"cheers": ["Cheers", "Best regards", "Talk soon", "Have a great day", "Warmly"]
|
| 97 |
};
|
| 98 |
|
| 99 |
// Evaluates a Spintax string into one random resolved string
|
|
@@ -109,14 +149,30 @@ export function evaluateSpintax(text: string): string {
|
|
| 109 |
return result;
|
| 110 |
}
|
| 111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
// Validates brace matching
|
| 113 |
export function validateSpintaxBraces(text: string): { isValid: boolean; error?: string } {
|
| 114 |
let depth = 0;
|
| 115 |
for (let i = 0; i < text.length; i++) {
|
| 116 |
if (text[i] === '{') {
|
| 117 |
-
// Check if it's part of a variable like {{First Name}}
|
| 118 |
if (text[i + 1] === '{') {
|
| 119 |
-
i++;
|
| 120 |
continue;
|
| 121 |
}
|
| 122 |
depth++;
|
|
@@ -152,7 +208,7 @@ export function generateSmartSpintax(input: string): string {
|
|
| 152 |
return `__URL_${shielded.length - 1}__`;
|
| 153 |
});
|
| 154 |
|
| 155 |
-
// Sort phrases by length descending so longer phrases match
|
| 156 |
const phrases = Object.keys(SYNONYMS_MAP).sort((a, b) => b.length - a.length);
|
| 157 |
|
| 158 |
for (const phrase of phrases) {
|
|
@@ -161,7 +217,6 @@ export function generateSmartSpintax(input: string): string {
|
|
| 161 |
const pattern = new RegExp(`(?<!\\{)(?<!\\|)\\b${phrase.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b(?!\\|)(?!\\})`, 'gi');
|
| 162 |
|
| 163 |
output = output.replace(pattern, (matched) => {
|
| 164 |
-
// Preserve capitalization of first letter if user had it uppercase
|
| 165 |
const isCapital = matched[0] === matched[0].toUpperCase();
|
| 166 |
const formattedVariants = variants.map(v => {
|
| 167 |
if (isCapital) {
|
|
@@ -169,7 +224,6 @@ export function generateSmartSpintax(input: string): string {
|
|
| 169 |
}
|
| 170 |
return v.charAt(0).toLowerCase() + v.slice(1);
|
| 171 |
});
|
| 172 |
-
// Ensure original matched is included first or amongst choices
|
| 173 |
const uniqueChoices = Array.from(new Set([matched, ...formattedVariants]));
|
| 174 |
return `{${uniqueChoices.join('|')}}`;
|
| 175 |
});
|
|
@@ -333,53 +387,72 @@ export function SpintaxModal({ isOpen, onClose, initialText, onApply }: SpintaxM
|
|
| 333 |
{/* Body */}
|
| 334 |
<div className="p-6 overflow-y-auto space-y-5 custom-scrollbar flex-1">
|
| 335 |
{/* Toolbar */}
|
| 336 |
-
|
| 337 |
-
|
|
|
|
| 338 |
<button
|
| 339 |
type="button"
|
| 340 |
onClick={handleAutoSpintax}
|
| 341 |
disabled={isAiLoading || !text.trim()}
|
| 342 |
className="px-3.5 py-1.5 rounded-xl bg-gradient-to-r from-indigo-600 to-purple-600 hover:from-indigo-500 hover:to-purple-500 disabled:opacity-50 text-white text-xs font-bold transition-all shadow-sm flex items-center gap-1.5 active:scale-95 cursor-pointer"
|
| 343 |
-
title="Enrich message variations with your configured OpenRouter model"
|
| 344 |
>
|
| 345 |
{isAiLoading ? (
|
| 346 |
<>
|
| 347 |
<Loader2 size={13} className="animate-spin" />
|
| 348 |
-
<span>AI Spinning...</span>
|
| 349 |
</>
|
| 350 |
) : (
|
| 351 |
<>
|
| 352 |
<Wand2 size={13} />
|
| 353 |
-
<span>AI
|
| 354 |
</>
|
| 355 |
)}
|
| 356 |
</button>
|
| 357 |
-
|
| 358 |
-
<span className="text-[11px] text-emerald-400 font-semibold px-2 animate-in fade-in">
|
| 359 |
-
{aiNote}
|
| 360 |
-
</span>
|
| 361 |
-
) : (
|
| 362 |
-
<span className="text-[11px] text-foreground/40 font-medium px-2 hidden sm:inline">
|
| 363 |
-
Adds rich variations to greetings, adjectives & CTAs via AI
|
| 364 |
-
</span>
|
| 365 |
-
)}
|
| 366 |
-
</div>
|
| 367 |
-
<div className="flex items-center gap-1.5">
|
| 368 |
-
<button
|
| 369 |
-
type="button"
|
| 370 |
-
onClick={() => setText(prev => prev + " {Hello|Hi|Hey}")}
|
| 371 |
-
className="px-2 py-1 bg-foreground/5 hover:bg-foreground/10 text-foreground/60 rounded-lg text-[10px] font-bold"
|
| 372 |
-
>
|
| 373 |
-
+ Greeting
|
| 374 |
-
</button>
|
| 375 |
<button
|
| 376 |
type="button"
|
| 377 |
-
onClick={() =>
|
| 378 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 379 |
>
|
| 380 |
-
|
|
|
|
| 381 |
</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 382 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 383 |
</div>
|
| 384 |
|
| 385 |
{/* Editor Area */}
|
|
|
|
| 26 |
|
| 27 |
// Built-in intelligent vocabulary dictionary for deep 80%-90% natural spintaxing
|
| 28 |
const SYNONYMS_MAP: Record<string, string[]> = {
|
| 29 |
+
// Whole Promotional Sections & Headings
|
| 30 |
+
"what we offer": ["WHAT WE OFFER", "OUR COMPLETE PACKAGE INCLUDES", "HERE IS WHAT YOU GET", "PREMIUM FEATURES & ACCESS"],
|
| 31 |
+
"why choose our service": ["WHY CHOOSE OUR SERVICE?", "WHY THOUSANDS TRUST US:", "THE PERKS OF CHOOSING US:", "WHY WE LEAD THE MARKET:"],
|
| 32 |
+
"why choose us": ["WHY CHOOSE US?", "WHY CLIENTS TRUST US:", "THE ADVANTAGES OF OUR SERVICE:", "WHY WORK WITH US?"],
|
| 33 |
+
"your entertainment starts here": ["YOUR ENTERTAINMENT STARTS HERE!", "STREAM UNLIMITED ENTERTAINMENT NOW!", "UPGRADE YOUR STREAMING TODAY!", "YOUR ACCESS STARTS RIGHT HERE!"],
|
| 34 |
+
"interested in subscribing": ["INTERESTED IN SUBSCRIBING?", "READY TO GET STARTED?", "LOOKING TO ACTIVATE YOUR PASS?", "READY TO JOIN TODAY?"],
|
| 35 |
+
"flexible subscription options": ["Flexible Subscription Options", "Customizable Plans & Pricing", "Budget-Friendly Membership Tiers", "Tailored Packages for Everyone"],
|
| 36 |
+
"simple activation process": ["Simple Activation Process", "Quick 1-Click Activation", "Frictionless Instant Setup", "Prompt Account Onboarding"],
|
| 37 |
+
"device compatibility assistance": ["Device Compatibility Assistance", "Support Across All Your Devices", "Multi-Screen Hardware Guidance", "Assistance on Any Compatible Screen"],
|
| 38 |
+
"responsive customer support": ["Responsive Customer Support", "Fast 24/7 Customer Care", "Always-Available Support Team", "Speedy Client Assistance"],
|
| 39 |
+
"professional customer support": ["Professional Customer Support", "Dedicated Expert Support", "Reliable 24/7 Client Care", "Friendly Technical Assistance"],
|
| 40 |
+
"easy setup & activation assistance": ["Easy Setup & Activation Assistance", "Instant Setup with Full Guidance", "Hassle-Free Activation Support", "Quick 2-Minute Setup & Help"],
|
| 41 |
+
"live tv channels": ["Live TV Channels", "Real-Time TV Networks", "HD Television Channels", "Premium Live Broadcasts"],
|
| 42 |
+
"sports & live events": ["Sports & Live Events", "Live Games and Championship Matches", "Sports Broadcasts and Pay-Per-View Events"],
|
| 43 |
+
"movies & tv series": ["Movies & TV Series", "Blockbuster Movies & Hit Series", "Top Films, Binge-Worthy Series & Shows"],
|
| 44 |
+
"international channels": ["International Channels", "Worldwide TV Networks", "Global Channels From Every Country"],
|
| 45 |
+
"compatible devices": ["Compatible Devices", "Supported Streaming Hardware", "Smart TVs, Phones & Streaming Boxes"],
|
| 46 |
+
|
| 47 |
// Greetings & Openers
|
| 48 |
"hello": ["Hello", "Hi", "Hey", "Greetings", "Welcome"],
|
| 49 |
"hi": ["Hi", "Hello", "Hey", "Good day", "Greetings"],
|
|
|
|
| 52 |
"good day": ["Good day", "Hello", "Hi", "Greetings", "Welcome"],
|
| 53 |
"hey there": ["Hey there", "Hello", "Hi folks", "Hey everyone", "Greetings"],
|
| 54 |
|
| 55 |
+
// Openings & Questions
|
| 56 |
+
"looking for a reliable": ["Looking for a reliable", "Searching for a dependable", "Want an ultra-stable", "Need a rock-solid", "Seeking a verified"],
|
| 57 |
+
"looking for a": ["Looking for a", "Searching for a", "In need of a", "Want a top-tier", "Seeking a quality"],
|
| 58 |
+
"looking for": ["searching for", "looking for", "in search of", "seeking", "on the hunt for"],
|
| 59 |
+
"enjoy a wide selection of": ["Enjoy a wide selection of", "Experience an extensive library of", "Stream unlimited access to", "Unlock a complete lineup of"],
|
| 60 |
+
"wide selection of": ["wide selection of", "huge library of", "massive collection of", "broad variety of"],
|
| 61 |
+
"wide selection": ["wide selection", "vast library", "extensive collection", "rich variety"],
|
| 62 |
"hope you are well": ["hope you're doing great", "hope all is well with you", "hope you are having a productive day", "trust you are doing well", "hope your week is going great"],
|
| 63 |
"i wanted to reach out": ["reaching out to you", "connecting with you", "just wanted to drop a quick line", "wanted to touch base", "reaching out directly"],
|
| 64 |
"quick question": ["brief inquiry", "quick question for you", "short question", "quick thought", "quick query"],
|
| 65 |
"take a look": ["check out", "take a look at", "explore", "discover", "dive into"],
|
| 66 |
"check out": ["check out", "take a look at", "explore", "have a look at", "inspect"],
|
|
|
|
| 67 |
"don't miss out": ["be sure not to miss", "don't miss this opportunity", "grab this while available", "act quickly", "don't sleep on this"],
|
| 68 |
|
| 69 |
+
// CTAs & Closers
|
| 70 |
+
"reply “subscribe” to get started": ["Reply “SUBSCRIBE” to get started!", "Send “SUBSCRIBE” to activate instantly!", "Type “SUBSCRIBE” to lock in your pass!", "Message “SUBSCRIBE” to claim access!"],
|
| 71 |
+
"reply “subscribe”": ["Reply “SUBSCRIBE”", "Send “SUBSCRIBE”", "Type “SUBSCRIBE”", "Message “SUBSCRIBE”"],
|
| 72 |
+
"send me a message today": ["Send me a message today", "Drop me a direct message now", "Reach out directly right now", "Message me today for details"],
|
| 73 |
+
"send me a message": ["send me a message", "drop me a DM", "reach out directly", "shoot me a message"],
|
| 74 |
+
"contact us": ["reach out to us", "send us a message", "drop us a DM", "connect with our team", "contact us"],
|
| 75 |
+
"reach out": ["reach out", "send a direct message", "get in touch", "contact us", "drop a message"],
|
| 76 |
+
"let me know": ["let me know your thoughts", "feel free to reply", "drop a reply", "let us know what you think", "shoot me a message"],
|
| 77 |
+
"click here": ["visit here", "check the link", "click below", "explore here", "tap the link below"],
|
| 78 |
+
"dm me": ["DM me", "send a direct message", "message me directly", "drop a message", "reach out via DM"],
|
| 79 |
+
"best regards": ["Best regards", "Warm regards", "Cheers", "Talk soon", "Respectfully"],
|
| 80 |
+
"thanks": ["Thanks", "Thank you", "Much appreciated", "Many thanks", "Cheers"],
|
| 81 |
+
|
| 82 |
+
// Adjectives & Nouns
|
| 83 |
+
"reliable": ["dependable", "trusted", "rock-solid", "proven", "reliable"],
|
| 84 |
+
"subscription": ["subscription", "membership pass", "access plan", "service plan", "subscription package"],
|
| 85 |
+
"subscriptions": ["subscriptions", "membership passes", "access plans", "service packages"],
|
| 86 |
+
"entertainment": ["entertainment", "streaming content", "viewing experience", "media enjoyment"],
|
| 87 |
+
"favorite": ["favorite", "preferred", "top-rated", "most-watched"],
|
| 88 |
+
"channels": ["channels", "networks", "broadcasts", "stations"],
|
| 89 |
+
"sports": ["sports matches", "live sports", "games and events", "championship sports"],
|
| 90 |
+
"movies": ["movies", "blockbusters", "films", "cinema releases"],
|
| 91 |
+
"series": ["TV series", "shows", "series", "hit series"],
|
| 92 |
+
"devices": ["devices", "screens", "hardware setups", "supported gadgets"],
|
| 93 |
+
"assistance": ["guidance", "assistance", "support", "help", "onboarding"],
|
| 94 |
+
"support": ["support", "customer care", "assistance", "help"],
|
| 95 |
+
"service": ["service", "platform", "solution", "setup"],
|
| 96 |
+
"options": ["options", "packages", "plans", "tiers", "choices"],
|
| 97 |
+
"packages": ["packages", "bundles", "plans", "tiers"],
|
| 98 |
+
"details": ["details", "specs", "information", "pricing"],
|
| 99 |
+
"quality": ["streaming quality", "resolution", "clarity", "playback performance"],
|
| 100 |
+
"great": ["great", "amazing", "exceptional", "top-notch", "fantastic"],
|
| 101 |
+
"best": ["top-tier", "leading", "finest", "premier", "best"],
|
| 102 |
+
"special": ["exclusive", "unique", "special", "tailored"],
|
| 103 |
"exclusive": ["exclusive", "limited", "VIP", "premier", "private"],
|
| 104 |
+
"affordable": ["cost-effective", "budget-friendly", "highly affordable", "valuable"],
|
| 105 |
"fast": ["lightning-fast", "ultra-quick", "instant", "rapid", "swift"],
|
| 106 |
+
"powerful": ["high-performance", "robust", "powerful", "advanced"],
|
|
|
|
| 107 |
"easy": ["effortless", "seamless", "simple", "straightforward", "hassle-free"],
|
| 108 |
+
"new": ["brand-new", "latest", "fresh", "cutting-edge"],
|
| 109 |
+
"huge": ["massive", "substantial", "enormous", "huge"],
|
| 110 |
+
"opportunity": ["chance", "opportunity", "opening", "deal"],
|
| 111 |
+
"results": ["outcomes", "results", "returns", "gains"],
|
| 112 |
+
"solution": ["solution", "platform", "system", "setup"],
|
| 113 |
|
| 114 |
+
// Verbs
|
| 115 |
"offer": ["provide", "deliver", "present", "offer", "bring you"],
|
| 116 |
+
"offers": ["provides", "delivers", "presents", "offers"],
|
| 117 |
"provide": ["deliver", "provide", "supply", "furnish", "offer"],
|
| 118 |
"help": ["assist", "support", "empower", "help", "guide"],
|
| 119 |
+
"enjoy": ["stream", "enjoy", "experience", "watch", "access"],
|
| 120 |
"boost": ["elevate", "supercharge", "boost", "maximize", "scale up"],
|
| 121 |
+
"grow": ["scale", "expand", "grow", "accelerate"],
|
| 122 |
"get": ["obtain", "access", "secure", "unlock", "claim"],
|
| 123 |
"discover": ["uncover", "explore", "discover", "learn about", "find"],
|
| 124 |
+
"join": ["hop into", "join", "become part of", "connect with"],
|
| 125 |
"start": ["kick off", "begin", "launch", "start", "get rolling with"],
|
| 126 |
+
"save": ["save", "cut down on", "reduce", "pocket extra"],
|
| 127 |
+
"earn": ["make", "generate", "earn", "pull in"],
|
| 128 |
+
"create": ["build", "generate", "create", "craft"],
|
| 129 |
+
"depend": ["rely", "depend", "hinge", "vary based"],
|
| 130 |
+
"started": ["set up", "started", "rolling", "onboarded"],
|
| 131 |
|
| 132 |
+
// Transitions
|
| 133 |
"also": ["furthermore", "additionally", "moreover", "in addition", "plus"],
|
| 134 |
"additionally": ["also", "furthermore", "moreover", "plus", "on top of that"],
|
|
|
|
|
|
|
|
|
|
| 135 |
"right now": ["currently", "at this moment", "today", "right now", "instantly"],
|
| 136 |
+
"today": ["today", "right now", "instantly", "straight away"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
};
|
| 138 |
|
| 139 |
// Evaluates a Spintax string into one random resolved string
|
|
|
|
| 149 |
return result;
|
| 150 |
}
|
| 151 |
|
| 152 |
+
// Calculates percentage of words spun
|
| 153 |
+
export function calculateSpintaxDensity(str: string): number {
|
| 154 |
+
if (!str.trim()) return 0;
|
| 155 |
+
const totalWords = str.trim().split(/\s+/).filter(Boolean).length;
|
| 156 |
+
if (totalWords === 0) return 0;
|
| 157 |
+
let spunWordCount = 0;
|
| 158 |
+
const regex = /\{([^{}]+)\}/g;
|
| 159 |
+
let match;
|
| 160 |
+
while ((match = regex.exec(str)) !== null) {
|
| 161 |
+
const inner = match[1];
|
| 162 |
+
const options = inner.split('|');
|
| 163 |
+
const avgWords = options.reduce((acc, opt) => acc + opt.trim().split(/\s+/).filter(Boolean).length, 0) / options.length;
|
| 164 |
+
spunWordCount += avgWords;
|
| 165 |
+
}
|
| 166 |
+
return Math.min(100, Math.round((spunWordCount / totalWords) * 100));
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
// Validates brace matching
|
| 170 |
export function validateSpintaxBraces(text: string): { isValid: boolean; error?: string } {
|
| 171 |
let depth = 0;
|
| 172 |
for (let i = 0; i < text.length; i++) {
|
| 173 |
if (text[i] === '{') {
|
|
|
|
| 174 |
if (text[i + 1] === '{') {
|
| 175 |
+
i++;
|
| 176 |
continue;
|
| 177 |
}
|
| 178 |
depth++;
|
|
|
|
| 208 |
return `__URL_${shielded.length - 1}__`;
|
| 209 |
});
|
| 210 |
|
| 211 |
+
// Sort phrases by length descending so longer multi-word phrases match first
|
| 212 |
const phrases = Object.keys(SYNONYMS_MAP).sort((a, b) => b.length - a.length);
|
| 213 |
|
| 214 |
for (const phrase of phrases) {
|
|
|
|
| 217 |
const pattern = new RegExp(`(?<!\\{)(?<!\\|)\\b${phrase.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b(?!\\|)(?!\\})`, 'gi');
|
| 218 |
|
| 219 |
output = output.replace(pattern, (matched) => {
|
|
|
|
| 220 |
const isCapital = matched[0] === matched[0].toUpperCase();
|
| 221 |
const formattedVariants = variants.map(v => {
|
| 222 |
if (isCapital) {
|
|
|
|
| 224 |
}
|
| 225 |
return v.charAt(0).toLowerCase() + v.slice(1);
|
| 226 |
});
|
|
|
|
| 227 |
const uniqueChoices = Array.from(new Set([matched, ...formattedVariants]));
|
| 228 |
return `{${uniqueChoices.join('|')}}`;
|
| 229 |
});
|
|
|
|
| 387 |
{/* Body */}
|
| 388 |
<div className="p-6 overflow-y-auto space-y-5 custom-scrollbar flex-1">
|
| 389 |
{/* Toolbar */}
|
| 390 |
+
{/* Toolbar with High Density Metrics & Options */}
|
| 391 |
+
<div className="flex flex-wrap items-center justify-between gap-2.5 bg-foreground/[0.03] p-2.5 rounded-2xl border border-border/60">
|
| 392 |
+
<div className="flex items-center gap-2 flex-wrap">
|
| 393 |
<button
|
| 394 |
type="button"
|
| 395 |
onClick={handleAutoSpintax}
|
| 396 |
disabled={isAiLoading || !text.trim()}
|
| 397 |
className="px-3.5 py-1.5 rounded-xl bg-gradient-to-r from-indigo-600 to-purple-600 hover:from-indigo-500 hover:to-purple-500 disabled:opacity-50 text-white text-xs font-bold transition-all shadow-sm flex items-center gap-1.5 active:scale-95 cursor-pointer"
|
| 398 |
+
title="Enrich message variations with your configured OpenRouter model for 85-90% spintax density"
|
| 399 |
>
|
| 400 |
{isAiLoading ? (
|
| 401 |
<>
|
| 402 |
<Loader2 size={13} className="animate-spin" />
|
| 403 |
+
<span>AI Deep-Spinning...</span>
|
| 404 |
</>
|
| 405 |
) : (
|
| 406 |
<>
|
| 407 |
<Wand2 size={13} />
|
| 408 |
+
<span>AI Deep-Spin (85%+)</span>
|
| 409 |
</>
|
| 410 |
)}
|
| 411 |
</button>
|
| 412 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 413 |
<button
|
| 414 |
type="button"
|
| 415 |
+
onClick={() => {
|
| 416 |
+
const spun = generateSmartSpintax(text);
|
| 417 |
+
setText(spun);
|
| 418 |
+
setAiNote('Applied local high-density phrase & vocabulary spintax.');
|
| 419 |
+
setTimeout(() => setAiNote(''), 4000);
|
| 420 |
+
}}
|
| 421 |
+
disabled={!text.trim()}
|
| 422 |
+
className="px-3 py-1.5 rounded-xl bg-foreground/5 hover:bg-foreground/10 text-foreground/80 hover:text-foreground text-xs font-bold border border-border/70 transition-all flex items-center gap-1.5 active:scale-95 cursor-pointer"
|
| 423 |
+
title="Instantly spin common phrases, headlines, headings, and keywords locally"
|
| 424 |
>
|
| 425 |
+
<RefreshCw size={12} className="text-indigo-400" />
|
| 426 |
+
<span>Instant High-Density Spin</span>
|
| 427 |
</button>
|
| 428 |
+
|
| 429 |
+
{aiNote ? (
|
| 430 |
+
<span className="text-[11px] text-emerald-400 font-semibold px-2 animate-in fade-in">
|
| 431 |
+
{aiNote}
|
| 432 |
+
</span>
|
| 433 |
+
) : null}
|
| 434 |
</div>
|
| 435 |
+
|
| 436 |
+
{/* Live Spintax Density Badge */}
|
| 437 |
+
{(() => {
|
| 438 |
+
const density = calculateSpintaxDensity(text);
|
| 439 |
+
const uniqueness = Math.min(99, Math.round(density * 1.05));
|
| 440 |
+
return (
|
| 441 |
+
<div className="flex items-center gap-1.5">
|
| 442 |
+
<span className={`text-[10px] font-bold px-2 py-0.5 rounded-full border flex items-center gap-1 ${
|
| 443 |
+
density >= 70
|
| 444 |
+
? 'bg-emerald-500/15 text-emerald-400 border-emerald-500/30'
|
| 445 |
+
: density > 0
|
| 446 |
+
? 'bg-amber-500/15 text-amber-400 border-amber-500/30'
|
| 447 |
+
: 'bg-foreground/5 text-foreground/40 border-border/60'
|
| 448 |
+
}`}>
|
| 449 |
+
<Sparkles size={10} />
|
| 450 |
+
<span>{density}% Anti-Ban Density</span>
|
| 451 |
+
{density > 0 && <span className="font-mono text-[9px] opacity-80">(~{uniqueness}% Unique)</span>}
|
| 452 |
+
</span>
|
| 453 |
+
</div>
|
| 454 |
+
);
|
| 455 |
+
})()}
|
| 456 |
</div>
|
| 457 |
|
| 458 |
{/* Editor Area */}
|