Spaces:
Paused
Paused
CBV01 commited on
Commit ·
09e1fa5
1
Parent(s): 83163cd
Fix Admin joining by improving account selection and group resolution
Browse files- backend/main.py +9 -0
- frontend/src/app/leads/page.tsx +3 -1
- frontend/src/app/scraper/page.tsx +5 -2
backend/main.py
CHANGED
|
@@ -292,6 +292,15 @@ async def resolve_tg_entity(client, target):
|
|
| 292 |
entity = await client.get_entity(username)
|
| 293 |
return entity
|
| 294 |
except: pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 295 |
except Exception as gl_e:
|
| 296 |
log_debug(f"RESOLVE_GL_ERR for {target}: {str(gl_e)}")
|
| 297 |
|
|
|
|
| 292 |
entity = await client.get_entity(username)
|
| 293 |
return entity
|
| 294 |
except: pass
|
| 295 |
+
|
| 296 |
+
# 4. Final Hail Mary: Search for it globally to "prime" the session
|
| 297 |
+
try:
|
| 298 |
+
from telethon.tl.functions.contacts import SearchRequest # type: ignore
|
| 299 |
+
await client(SearchRequest(q=target_str, limit=5))
|
| 300 |
+
entity = await client.get_entity(target_str)
|
| 301 |
+
return entity
|
| 302 |
+
except: pass
|
| 303 |
+
|
| 304 |
except Exception as gl_e:
|
| 305 |
log_debug(f"RESOLVE_GL_ERR for {target}: {str(gl_e)}")
|
| 306 |
|
frontend/src/app/leads/page.tsx
CHANGED
|
@@ -114,7 +114,9 @@ export default function LeadsPage() {
|
|
| 114 |
const handleBulkJoin = async () => {
|
| 115 |
const groupIds = Array.from(selectedIds).filter(id => typeof id === 'string') as string[];
|
| 116 |
if (groupIds.length === 0) return;
|
| 117 |
-
|
|
|
|
|
|
|
| 118 |
if (!phoneNumber) { setError('No connected account found.'); return; }
|
| 119 |
|
| 120 |
// Reset and open the progress modal
|
|
|
|
| 114 |
const handleBulkJoin = async () => {
|
| 115 |
const groupIds = Array.from(selectedIds).filter(id => typeof id === 'string') as string[];
|
| 116 |
if (groupIds.length === 0) return;
|
| 117 |
+
|
| 118 |
+
const activeAcc = accounts.find(a => a.status === 'active') || accounts[0];
|
| 119 |
+
const phoneNumber = activeAcc?.phone_number;
|
| 120 |
if (!phoneNumber) { setError('No connected account found.'); return; }
|
| 121 |
|
| 122 |
// Reset and open the progress modal
|
frontend/src/app/scraper/page.tsx
CHANGED
|
@@ -120,7 +120,9 @@ export default function ScraperPage() {
|
|
| 120 |
try {
|
| 121 |
const accRes = await apiFetch('/api/telegram/accounts');
|
| 122 |
const accData = await accRes.json();
|
| 123 |
-
|
|
|
|
|
|
|
| 124 |
if (!phoneNumber) throw new Error("No connected account.");
|
| 125 |
|
| 126 |
const res = await apiFetch('/api/telegram/join', {
|
|
@@ -152,7 +154,8 @@ export default function ScraperPage() {
|
|
| 152 |
try {
|
| 153 |
const accRes = await apiFetch('/api/telegram/accounts');
|
| 154 |
const accData = await accRes.json();
|
| 155 |
-
const
|
|
|
|
| 156 |
if (!phoneNumber) throw new Error('No connected account found.');
|
| 157 |
|
| 158 |
const token = localStorage.getItem('tg_auth_token') || '';
|
|
|
|
| 120 |
try {
|
| 121 |
const accRes = await apiFetch('/api/telegram/accounts');
|
| 122 |
const accData = await accRes.json();
|
| 123 |
+
// Find first active account
|
| 124 |
+
const activeAcc = accData.accounts?.find((a: any) => a.status === 'active') || accData.accounts?.[0];
|
| 125 |
+
const phoneNumber = activeAcc?.phone_number;
|
| 126 |
if (!phoneNumber) throw new Error("No connected account.");
|
| 127 |
|
| 128 |
const res = await apiFetch('/api/telegram/join', {
|
|
|
|
| 154 |
try {
|
| 155 |
const accRes = await apiFetch('/api/telegram/accounts');
|
| 156 |
const accData = await accRes.json();
|
| 157 |
+
const activeAcc = accData.accounts?.find((a: any) => a.status === 'active');
|
| 158 |
+
const phoneNumber = activeAcc?.phone_number || accData.accounts?.[0]?.phone_number;
|
| 159 |
if (!phoneNumber) throw new Error('No connected account found.');
|
| 160 |
|
| 161 |
const token = localStorage.getItem('tg_auth_token') || '';
|