(self, query)
| 13746 | } |
| 13747 | |
| 13748 | async def analyze_telegram(self, query): |
| 13749 | results = [] |
| 13750 | seen_ids = set() |
| 13751 | base_icon = SOCIAL_MAP["Telegram"]["icon"] |
| 13752 | |
| 13753 | api_id = self.creds.get('tg_id') |
| 13754 | api_hash = self.creds.get('tg_hash') |
| 13755 | session_str = self.telegram_session() |
| 13756 | |
| 13757 | if not api_id or not api_hash or not session_str: |
| 13758 | info = {"Status": " Accesso Negato", "Note": "Inserisci API ID/HASH Telegram e fai Login per la ricerca profonda."} |
| 13759 | return [{"username": query, "type": "Telegram", "info": info, "main_img": base_icon, "status_code": 401, "url": ""}] |
| 13760 | |
| 13761 | try: |
| 13762 | client = TelegramClient(StringSession(session_str), int(api_id), api_hash, loop=get_telethon_loop()) |
| 13763 | await client.connect() |
| 13764 | if not await client.is_user_authorized(): |
| 13765 | raise Exception("Sessione scaduta") |
| 13766 | |
| 13767 | # 1. Tentiamo prima il Match Esatto (Molto pi preciso per trovare profili specifici) |
| 13768 | try: |
| 13769 | entity = await client.get_entity(query) |
| 13770 | res = await self._parse_tg_entity(client, entity, base_icon, query, exact=True) |
| 13771 | if res: |
| 13772 | results.append(res) |
| 13773 | seen_ids.add(entity.id) |
| 13774 | except Exception: |
| 13775 | pass |
| 13776 | |
| 13777 | # 2. Procediamo con la Ricerca Globale allargata |
| 13778 | search_results = await client(functions.contacts.SearchRequest(q=query, limit=15)) |
| 13779 | |
| 13780 | for user in search_results.users: |
| 13781 | if user.id not in seen_ids: |
| 13782 | res = await self._parse_tg_entity(client, user, base_icon, query, exact=False) |
| 13783 | if res: results.append(res) |
| 13784 | seen_ids.add(user.id) |
| 13785 | |
| 13786 | for chat in search_results.chats: |
| 13787 | if chat.id not in seen_ids: |
| 13788 | res = await self._parse_tg_entity(client, chat, base_icon, query, exact=False) |
| 13789 | if res: results.append(res) |
| 13790 | seen_ids.add(chat.id) |
| 13791 | |
| 13792 | await client.disconnect() |
| 13793 | |
| 13794 | if not results: |
| 13795 | info = {"Status": " Nessun Risultato", "Note": "La ricerca API non ha prodotto risultati."} |
| 13796 | return [{"username": query, "type": "Telegram", "info": info, "main_img": base_icon, "status_code": 404, "url": ""}] |
| 13797 | |
| 13798 | return results |
| 13799 | |
| 13800 | except Exception as e: |
| 13801 | print(f"[*] Errore API Telegram: {e}") |
| 13802 | info = {"Status": " Errore API", "Note": str(e)} |
| 13803 | return [{"username": query, "type": "Telegram", "info": info, "main_img": base_icon, "status_code": 500, "url": ""}] |
| 13804 | |
| 13805 | async def get_tg_participants_csv(self, entity_id): |
no test coverage detected