@onairos/react-native 3.7.2 → 3.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/api/index.js +219 -9
- package/lib/commonjs/components/BodyText.js +27 -9
- package/lib/commonjs/components/BrandMark.js +111 -10
- package/lib/commonjs/components/CodeInput.js +116 -9
- package/lib/commonjs/components/EmailInput.js +30 -8
- package/lib/commonjs/components/GoogleButton.js +56 -9
- package/lib/commonjs/components/HeadingGroup.js +43 -9
- package/lib/commonjs/components/LLMDataInputModal.js +664 -14
- package/lib/commonjs/components/ModalHeader.js +99 -9
- package/lib/commonjs/components/ModalSheet.js +47 -9
- package/lib/commonjs/components/Onairos.js +380 -14
- package/lib/commonjs/components/OnairosButton.js +313 -13
- package/lib/commonjs/components/OnairosSignInButton.js +130 -12
- package/lib/commonjs/components/Overlay.js +465 -13
- package/lib/commonjs/components/PersonaImage.js +137 -10
- package/lib/commonjs/components/PersonaLoadingScreen.js +318 -12
- package/lib/commonjs/components/PersonalizationConsentScreen.js +467 -13
- package/lib/commonjs/components/PinCreationScreen.js +403 -12
- package/lib/commonjs/components/PinInput.js +464 -9
- package/lib/commonjs/components/PlatformConnectorsStep.js +1311 -23
- package/lib/commonjs/components/PlatformList.js +137 -10
- package/lib/commonjs/components/PlatformToggle.js +180 -9
- package/lib/commonjs/components/PrimaryButton.js +180 -10
- package/lib/commonjs/components/SignInMatchAnimation.js +197 -9
- package/lib/commonjs/components/SignInStep.js +345 -12
- package/lib/commonjs/components/UniversalOnboarding.js +2780 -30
- package/lib/commonjs/components/VerificationStep.js +176 -11
- package/lib/commonjs/components/WelcomeScreen.js +461 -22
- package/lib/commonjs/components/icons/Basicproficon.js +37 -8
- package/lib/commonjs/components/icons/Basicprofile.js +21 -8
- package/lib/commonjs/components/icons/Checkbox.js +21 -8
- package/lib/commonjs/components/icons/Checkmark.js +27 -8
- package/lib/commonjs/components/icons/Contentanalysis.js +21 -8
- package/lib/commonjs/components/icons/Contenticon.js +39 -8
- package/lib/commonjs/components/icons/EnochE.js +41 -8
- package/lib/commonjs/components/icons/Personalityicon.js +30 -8
- package/lib/commonjs/components/icons/Personalityprofile.js +21 -8
- package/lib/commonjs/components/icons/Personalitytraits.js +21 -8
- package/lib/commonjs/components/icons/Userpreferences.js +21 -8
- package/lib/commonjs/components/icons/index.js +84 -17
- package/lib/commonjs/components/onboarding/OAuthWebView.js +1754 -18
- package/lib/commonjs/components/onboarding/OnboardingHeader.js +74 -10
- package/lib/commonjs/components/onboarding/PinInput.js +283 -10
- package/lib/commonjs/components/onboarding/PlatformConnector.js +249 -11
- package/lib/commonjs/config/PLATFORM_APIS.md +849 -0
- package/lib/commonjs/config/api.js +56 -7
- package/lib/commonjs/constants/index.js +120 -7
- package/lib/commonjs/context/AuthContext.js +345 -10
- package/lib/commonjs/hooks/useConnectedAccounts.js +111 -9
- package/lib/commonjs/hooks/useConnections.js +102 -8
- package/lib/commonjs/hooks/useCredentials.js +178 -10
- package/lib/commonjs/hooks/useUserConnections.js +148 -10
- package/lib/commonjs/index.js +439 -34
- package/lib/commonjs/services/apiClient.js +298 -8
- package/lib/commonjs/services/biometricPinService.js +180 -8
- package/lib/commonjs/services/chatGPTConversationExtractor.js +155 -8
- package/lib/commonjs/services/chatGPTConversationService.js +275 -9
- package/lib/commonjs/services/claudeConversationExtractor.js +103 -8
- package/lib/commonjs/services/claudeConversationService.js +158 -9
- package/lib/commonjs/services/connectedAccountsService.js +310 -10
- package/lib/commonjs/services/googleAuthService.js +252 -11
- package/lib/commonjs/services/hingeDataExtractor.js +105 -8
- package/lib/commonjs/services/hingeDataService.js +150 -9
- package/lib/commonjs/services/imageCompressionService.js +260 -7
- package/lib/commonjs/services/instagramDataExtractor.js +126 -8
- package/lib/commonjs/services/instagramDataService.js +163 -9
- package/lib/commonjs/services/jwtStorageService.js +276 -7
- package/lib/commonjs/services/linkedinDOMExtractor.js +245 -7
- package/lib/commonjs/services/linkedinProfileService.js +222 -9
- package/lib/commonjs/services/linkedinScrapingService.js +230 -8
- package/lib/commonjs/services/llmDataStorage.js +294 -8
- package/lib/commonjs/services/mobileTrainingService.js +186 -8
- package/lib/commonjs/services/netflixDataExtractor.js +120 -8
- package/lib/commonjs/services/netflixDataService.js +198 -9
- package/lib/commonjs/services/pinEncryptionService.js +84 -8
- package/lib/commonjs/services/pinStorageUtils.js +105 -7
- package/lib/commonjs/services/platformAuthService.js +1484 -12
- package/lib/commonjs/services/sephoraDataExtractor.js +140 -8
- package/lib/commonjs/services/sephoraDataService.js +200 -9
- package/lib/commonjs/services/spotifyDataExtractor.js +148 -8
- package/lib/commonjs/services/spotifyDataService.js +241 -9
- package/lib/commonjs/services/storageService.js +404 -8
- package/lib/commonjs/services/telegramDataExtractor.js +115 -8
- package/lib/commonjs/services/telegramDataService.js +499 -9
- package/lib/commonjs/services/trainingApiHelpers.js +73 -7
- package/lib/commonjs/services/userConnectionsService.js +340 -10
- package/lib/commonjs/services/youtubeMigrationService.js +416 -10
- package/lib/commonjs/theme/index.js +250 -7
- package/lib/commonjs/types/ambient.d.js +2 -1
- package/lib/commonjs/types/declarations.d.js +2 -1
- package/lib/commonjs/types/index.js +6 -1
- package/lib/commonjs/types/node-fix.d.js +2 -1
- package/lib/commonjs/types/node-override.d.js +2 -1
- package/lib/commonjs/types/opacity.d.js +2 -1
- package/lib/commonjs/types.js +14 -1
- package/lib/commonjs/utils/Portal.js +98 -8
- package/lib/commonjs/utils/api.js +130 -9
- package/lib/commonjs/utils/assetRegistry.js +210 -35
- package/lib/commonjs/utils/auth.js +112 -9
- package/lib/commonjs/utils/connectorTests.js +613 -29
- package/lib/commonjs/utils/crypto.js +62 -8
- package/lib/commonjs/utils/debugHelper.js +64 -1
- package/lib/commonjs/utils/encryption.js +76 -7
- package/lib/commonjs/utils/eventUtils.js +288 -1
- package/lib/commonjs/utils/haptics.js +66 -9
- package/lib/commonjs/utils/imagePreloader.js +6 -1
- package/lib/commonjs/utils/networkDiagnostics.js +226 -8
- package/lib/commonjs/utils/onairosApi.js +350 -9
- package/lib/commonjs/utils/programmaticFlow.js +117 -9
- package/lib/commonjs/utils/retryHelper.js +220 -1
- package/lib/commonjs/utils/secureStorage.js +349 -10
- package/lib/commonjs/utils/webviewScripts/chatgpt.js +551 -1
- package/lib/commonjs/utils/webviewScripts/claude.js +376 -1
- package/lib/commonjs/utils/webviewScripts/hinge.js +411 -1
- package/lib/commonjs/utils/webviewScripts/index.js +698 -15
- package/lib/commonjs/utils/webviewScripts/instagram.js +454 -1
- package/lib/commonjs/utils/webviewScripts/linkedin.js +880 -1
- package/lib/commonjs/utils/webviewScripts/netflix.js +382 -1
- package/lib/commonjs/utils/webviewScripts/sephora.js +516 -1
- package/lib/commonjs/utils/webviewScripts/spotify.js +419 -1
- package/lib/commonjs/utils/webviewScripts/telegram.js +678 -1
- package/lib/module/api/index.js +211 -1
- package/lib/module/components/BodyText.js +20 -1
- package/lib/module/components/BrandMark.js +104 -1
- package/lib/module/components/CodeInput.js +109 -1
- package/lib/module/components/EmailInput.js +23 -1
- package/lib/module/components/GoogleButton.js +49 -1
- package/lib/module/components/HeadingGroup.js +36 -1
- package/lib/module/components/LLMDataInputModal.js +656 -7
- package/lib/module/components/ModalHeader.js +92 -1
- package/lib/module/components/ModalSheet.js +39 -1
- package/lib/module/components/Onairos.js +373 -1
- package/lib/module/components/OnairosButton.js +305 -1
- package/lib/module/components/OnairosSignInButton.js +121 -1
- package/lib/module/components/Overlay.js +456 -1
- package/lib/module/components/PersonaImage.js +129 -1
- package/lib/module/components/PersonaLoadingScreen.js +310 -1
- package/lib/module/components/PersonalizationConsentScreen.js +460 -1
- package/lib/module/components/PinCreationScreen.js +396 -1
- package/lib/module/components/PinInput.js +456 -1
- package/lib/module/components/PlatformConnectorsStep.js +1302 -6
- package/lib/module/components/PlatformList.js +129 -1
- package/lib/module/components/PlatformToggle.js +173 -1
- package/lib/module/components/PrimaryButton.js +172 -1
- package/lib/module/components/SignInMatchAnimation.js +189 -1
- package/lib/module/components/SignInStep.js +338 -1
- package/lib/module/components/UniversalOnboarding.js +2770 -1
- package/lib/module/components/VerificationStep.js +168 -1
- package/lib/module/components/WelcomeScreen.js +453 -1
- package/lib/module/components/icons/Basicproficon.js +30 -1
- package/lib/module/components/icons/Basicprofile.js +14 -1
- package/lib/module/components/icons/Checkbox.js +14 -1
- package/lib/module/components/icons/Checkmark.js +20 -1
- package/lib/module/components/icons/Contentanalysis.js +14 -1
- package/lib/module/components/icons/Contenticon.js +32 -1
- package/lib/module/components/icons/EnochE.js +34 -1
- package/lib/module/components/icons/Personalityicon.js +23 -1
- package/lib/module/components/icons/Personalityprofile.js +14 -1
- package/lib/module/components/icons/Personalitytraits.js +14 -1
- package/lib/module/components/icons/Userpreferences.js +14 -1
- package/lib/module/components/icons/index.js +13 -1
- package/lib/module/components/onboarding/OAuthWebView.js +1746 -1
- package/lib/module/components/onboarding/OnboardingHeader.js +66 -1
- package/lib/module/components/onboarding/PinInput.js +274 -1
- package/lib/module/components/onboarding/PlatformConnector.js +240 -1
- package/lib/module/config/PLATFORM_APIS.md +849 -0
- package/lib/module/config/api.js +47 -1
- package/lib/module/constants/index.js +114 -1
- package/lib/module/context/AuthContext.js +335 -1
- package/lib/module/hooks/useConnectedAccounts.js +106 -1
- package/lib/module/hooks/useConnections.js +95 -1
- package/lib/module/hooks/useCredentials.js +171 -6
- package/lib/module/hooks/useUserConnections.js +140 -1
- package/lib/module/index.js +172 -1
- package/lib/module/services/apiClient.js +295 -1
- package/lib/module/services/biometricPinService.js +169 -1
- package/lib/module/services/chatGPTConversationExtractor.js +149 -1
- package/lib/module/services/chatGPTConversationService.js +268 -1
- package/lib/module/services/claudeConversationExtractor.js +97 -1
- package/lib/module/services/claudeConversationService.js +151 -1
- package/lib/module/services/connectedAccountsService.js +293 -1
- package/lib/module/services/googleAuthService.js +241 -1
- package/lib/module/services/hingeDataExtractor.js +99 -1
- package/lib/module/services/hingeDataService.js +143 -1
- package/lib/module/services/imageCompressionService.js +250 -1
- package/lib/module/services/instagramDataExtractor.js +120 -1
- package/lib/module/services/instagramDataService.js +156 -1
- package/lib/module/services/jwtStorageService.js +257 -1
- package/lib/module/services/linkedinDOMExtractor.js +234 -1
- package/lib/module/services/linkedinProfileService.js +210 -1
- package/lib/module/services/linkedinScrapingService.js +219 -1
- package/lib/module/services/llmDataStorage.js +277 -1
- package/lib/module/services/mobileTrainingService.js +173 -1
- package/lib/module/services/netflixDataExtractor.js +114 -1
- package/lib/module/services/netflixDataService.js +191 -1
- package/lib/module/services/pinEncryptionService.js +74 -6
- package/lib/module/services/pinStorageUtils.js +93 -1
- package/lib/module/services/platformAuthService.js +1461 -1
- package/lib/module/services/sephoraDataExtractor.js +134 -1
- package/lib/module/services/sephoraDataService.js +193 -1
- package/lib/module/services/spotifyDataExtractor.js +142 -1
- package/lib/module/services/spotifyDataService.js +234 -1
- package/lib/module/services/storageService.js +383 -1
- package/lib/module/services/telegramDataExtractor.js +109 -1
- package/lib/module/services/telegramDataService.js +493 -1
- package/lib/module/services/trainingApiHelpers.js +67 -1
- package/lib/module/services/userConnectionsService.js +329 -1
- package/lib/module/services/youtubeMigrationService.js +405 -1
- package/lib/module/theme/index.js +245 -1
- package/lib/module/types.js +10 -1
- package/lib/module/utils/Portal.js +90 -1
- package/lib/module/utils/api.js +118 -1
- package/lib/module/utils/assetRegistry.js +200 -34
- package/lib/module/utils/auth.js +100 -1
- package/lib/module/utils/connectorTests.js +600 -27
- package/lib/module/utils/crypto.js +54 -1
- package/lib/module/utils/debugHelper.js +54 -1
- package/lib/module/utils/encryption.js +67 -1
- package/lib/module/utils/eventUtils.js +270 -1
- package/lib/module/utils/haptics.js +59 -8
- package/lib/module/utils/imagePreloader.js +3 -1
- package/lib/module/utils/networkDiagnostics.js +217 -1
- package/lib/module/utils/onairosApi.js +333 -1
- package/lib/module/utils/programmaticFlow.js +111 -1
- package/lib/module/utils/retryHelper.js +211 -1
- package/lib/module/utils/secureStorage.js +330 -6
- package/lib/module/utils/webviewScripts/chatgpt.js +545 -1
- package/lib/module/utils/webviewScripts/claude.js +370 -1
- package/lib/module/utils/webviewScripts/hinge.js +405 -1
- package/lib/module/utils/webviewScripts/index.js +434 -1
- package/lib/module/utils/webviewScripts/instagram.js +448 -1
- package/lib/module/utils/webviewScripts/linkedin.js +874 -1
- package/lib/module/utils/webviewScripts/netflix.js +376 -1
- package/lib/module/utils/webviewScripts/sephora.js +510 -1
- package/lib/module/utils/webviewScripts/spotify.js +413 -1
- package/lib/module/utils/webviewScripts/telegram.js +672 -1
- package/package.json +2 -2
|
@@ -1 +1,493 @@
|
|
|
1
|
-
import{API_CONFIG}from'../config/api';import AsyncStorage from'@react-native-async-storage/async-storage';function _0x37b7(_0x318b62,_0x37b7cd){_0x318b62=_0x318b62-0x0;const _0xa7c3a1=_0x318b();let _0x22c401=_0xa7c3a1[_0x318b62];return _0x22c401;}import{Platform}from'react-native';export const storeTelegramData=async(_0x28d1c4,_0x358152)=>{const _0x12e4d4={'qWnlz':_0x37b7(0x0),'yURGg':_0x37b7(0x1),'qgyzf':_0x37b7(0x2),'cQUby':_0x37b7(0x3),'IhjKq':_0x37b7(0x4),'zGopF':_0x37b7(0x5),'lNZkt':_0x37b7(0x6),'cXdAp':_0x37b7(0x7),'EaJii':_0x37b7(0x8),'sMUIW':'1.0.0','otpur':function(_0x174ae1,_0x452e6d){return _0x174ae1===_0x452e6d;},'sywSm':function(_0x190260,_0x1881d4){return _0x190260===_0x1881d4;},'cTcsv':_0x37b7(0x9),'tWqIl':_0x37b7(0xa),'OJqEa':'Android','lFQvv':_0x37b7(0xb),'XBFxF':_0x37b7(0xc),'eLcFt':_0x37b7(0xd),'JmVfv':'📍\x20[TELEGRAM_SERVICE]\x20URL:','pXZLC':function(_0x436902,_0x38e776,_0x3aabd7){return _0x436902(_0x38e776,_0x3aabd7);},'FDIEy':_0x37b7(0xe),'iWBso':function(_0x48272c,_0x16e20d){return _0x48272c!==_0x16e20d;},'pnoOL':_0x37b7(0xf),'wNtlf':'ygcaZ','kynaC':'Telegram\x20data\x20stored\x20successfully','DZveO':_0x37b7(0x10),'AGgEW':_0x37b7(0x11),'PgBuo':'Network\x20error.\x20Please\x20check\x20your\x20connection.'};console[_0x37b7(0x12)](_0x37b7(0x13),_0x28d1c4),console[_0x37b7(0x12)](_0x37b7(0x14),_0x358152['dialogs']['length']),console[_0x37b7(0x12)](_0x12e4d4[_0x37b7(0x15)],_0x358152[_0x37b7(0x16)]['length']);if(!_0x28d1c4)return console[_0x37b7(0x17)](_0x12e4d4[_0x37b7(0x18)]),{'success':![],'error':_0x12e4d4[_0x37b7(0x19)]};try{const _0x279134=await AsyncStorage[_0x37b7(0x1a)](_0x12e4d4[_0x37b7(0x1b)])||await AsyncStorage[_0x37b7(0x1a)](_0x12e4d4[_0x37b7(0x1c)])||await AsyncStorage[_0x37b7(0x1a)](_0x12e4d4[_0x37b7(0x1d)]);if(!_0x279134)return console['error'](_0x12e4d4[_0x37b7(0x1e)]),{'success':![],'error':_0x12e4d4[_0x37b7(0x1f)]};console['log'](_0x37b7(0x20));const _0x3e537c={'platform':Platform['OS'],'appVersion':_0x12e4d4[_0x37b7(0x21)],'osVersion':_0x12e4d4['otpur'](Platform['OS'],_0x37b7(0x9))?_0x37b7(0x22):Platform['OS'],'deviceModel':_0x12e4d4[_0x37b7(0x23)](Platform['OS'],_0x12e4d4[_0x37b7(0x24)])?_0x12e4d4['tWqIl']:_0x12e4d4[_0x37b7(0x25)],'isOfflineSync':![],'extractedAt':new Date()['toISOString']()},_0x4deacb={'platform':_0x12e4d4[_0x37b7(0x26)],'dataType':_0x12e4d4[_0x37b7(0x27)],'data':{'dialogs':_0x358152[_0x37b7(0x28)][_0x37b7(0x29)](_0x30a16b=>({'dialogId':_0x30a16b['id'],'title':_0x30a16b[_0x37b7(0x2a)],'type':_0x30a16b[_0x37b7(0x2b)],'unreadCount':_0x30a16b[_0x37b7(0x2c)],'lastMessageDate':_0x30a16b[_0x37b7(0x2d)]})),'messages':_0x358152['messages'][_0x37b7(0x29)]((_0x1d6e83,_0x4eb505)=>({'messageId':_0x1d6e83['id'],'chatId':_0x1d6e83[_0x37b7(0x2e)],'content':_0x1d6e83[_0x37b7(0x2f)],'timestamp':_0x1d6e83[_0x37b7(0x30)]||new Date()[_0x37b7(0x31)](),'type':_0x1d6e83[_0x37b7(0x2b)],'role':'user'})),'telegramUserId':_0x358152[_0x37b7(0x32)]},'summary':{'dialogCount':_0x358152[_0x37b7(0x28)][_0x37b7(0x33)],'messageCount':_0x358152[_0x37b7(0x16)][_0x37b7(0x33)],'textMessages':_0x358152['messages']['filter'](_0x584bd4=>_0x584bd4[_0x37b7(0x2b)]===_0x37b7(0x2f))[_0x37b7(0x33)],'mediaMessages':_0x358152[_0x37b7(0x16)]['filter'](_0x3d0dfd=>_0x3d0dfd[_0x37b7(0x2b)]!==_0x37b7(0x2f))['length']},'mobileMetadata':_0x3e537c};console[_0x37b7(0x12)](_0x12e4d4['eLcFt']),console[_0x37b7(0x12)](_0x12e4d4[_0x37b7(0x34)],API_CONFIG[_0x37b7(0x35)]+_0x37b7(0x36));const _0x4a3139=await _0x12e4d4[_0x37b7(0x37)](fetch,API_CONFIG['BASE_URL']+'/platform-data/store',{'method':'POST','headers':{'Content-Type':'application/json','Authorization':'Bearer\x20'+_0x279134,'User-Agent':_0x37b7(0x38)+Platform['OS']+')'},'body':JSON[_0x37b7(0x39)](_0x4deacb)}),_0x3dfea5=await _0x4a3139[_0x37b7(0x3a)]();if(_0x4a3139['ok']){if(_0x12e4d4['otpur'](_0x12e4d4['FDIEy'],_0x12e4d4[_0x37b7(0x3b)])){console['log'](_0x12e4d4[_0x37b7(0x3c)]);if(_0x3dfea5[_0x37b7(0x3d)]){if(_0x12e4d4[_0x37b7(0x3e)](_0x12e4d4[_0x37b7(0x3f)],_0x12e4d4['wNtlf']))console[_0x37b7(0x12)]('📝\x20[TELEGRAM_SERVICE]\x20Backend\x20response:\x20'+_0x3dfea5[_0x37b7(0x3d)]);else return _0x1bfd62['log'](_0x12e4d4[_0x37b7(0x3c)]),_0xf52acf[_0x37b7(0x3d)]&&_0x1cb837[_0x37b7(0x12)](_0x37b7(0x40)+_0x3ba8c1[_0x37b7(0x3d)]),{'success':!![],'message':_0x47654e[_0x37b7(0x3d)]||'Telegram\x20data\x20stored\x20successfully','data':_0xafee21['data']};}return{'success':!![],'message':_0x3dfea5[_0x37b7(0x3d)]||_0x12e4d4[_0x37b7(0x41)],'data':_0x3dfea5[_0x37b7(0x42)]};}else return _0x32ae8a[_0x37b7(0x17)](_0x12e4d4[_0x37b7(0x18)]),{'success':![],'error':_0x37b7(0x3)};}else return console[_0x37b7(0x43)]('⚠️\x20[TELEGRAM_SERVICE]\x20Backend\x20returned\x20status:\x20'+_0x4a3139['status']),console[_0x37b7(0x43)]('⚠️\x20[TELEGRAM_SERVICE]\x20Error:\x20'+(_0x3dfea5[_0x37b7(0x17)]||_0x12e4d4[_0x37b7(0x44)])),{'success':![],'error':_0x3dfea5[_0x37b7(0x17)]||_0x37b7(0x45)+_0x4a3139[_0x37b7(0x46)]};}catch(_0x855717){if(_0x12e4d4[_0x37b7(0x3e)](_0x37b7(0x47),_0x37b7(0x47)))_0x1eb9d8[_0x37b7(0x12)](_0x37b7(0x40)+_0x19a984[_0x37b7(0x3d)]);else return console[_0x37b7(0x17)](_0x12e4d4[_0x37b7(0x48)],_0x855717),{'success':![],'error':_0x855717['message']||_0x12e4d4[_0x37b7(0x49)]};}};export const TELEGRAM_MTPROTO_API={'getDialogs':{'method':_0x37b7(0x4a),'description':_0x37b7(0x4b),'parameters':{'flags':_0x37b7(0x4c),'exclude_pinned':_0x37b7(0x4d),'folder_id':_0x37b7(0x4e),'offset_date':_0x37b7(0x4f),'offset_id':_0x37b7(0x50),'offset_peer':_0x37b7(0x51),'limit':_0x37b7(0x52),'hash':_0x37b7(0x53)},'returns':_0x37b7(0x54),'errors':[_0x37b7(0x55),_0x37b7(0x56)]},'getHistory':{'method':_0x37b7(0x57),'description':'Get\x20messages\x20from\x20a\x20peer\x20(chat/user/channel)','parameters':{'peer':_0x37b7(0x58),'offset_id':'int\x20-\x20Offset\x20message\x20ID','offset_date':_0x37b7(0x59),'add_offset':_0x37b7(0x5a),'limit':_0x37b7(0x5b),'max_id':'int\x20-\x20Maximum\x20message\x20ID\x20to\x20fetch','min_id':_0x37b7(0x5c),'hash':_0x37b7(0x5d)},'returns':'messages.Messages\x20-\x20Contains\x20messages,\x20chats,\x20users\x20arrays','errors':['CHAT_ID_INVALID\x20-\x20Invalid\x20chat\x20ID','PEER_ID_INVALID\x20-\x20Invalid\x20peer']},'search':{'method':_0x37b7(0x5e),'description':_0x37b7(0x5f),'parameters':{'peer':_0x37b7(0x60),'q':'string\x20-\x20Search\x20query','from_id':'InputPeer\x20-\x20Filter\x20by\x20sender\x20(optional)','filter':_0x37b7(0x61),'min_date':_0x37b7(0x62),'max_date':_0x37b7(0x63),'offset_id':'int\x20-\x20Offset\x20message\x20ID','add_offset':_0x37b7(0x5a),'limit':_0x37b7(0x64),'max_id':_0x37b7(0x65),'min_id':_0x37b7(0x66),'hash':'long\x20-\x20Hash\x20for\x20caching'},'returns':_0x37b7(0x67)}};export const TELEGRAM_LIBRARIES={'python':{'telethon':{'name':'Telethon','install':'pip\x20install\x20telethon','github':_0x37b7(0x68),'docs':_0x37b7(0x69),'example':_0x37b7(0x6a)},'pyrogram':{'name':_0x37b7(0x6b),'install':_0x37b7(0x6c),'github':_0x37b7(0x6d),'docs':_0x37b7(0x6e)}},'nodejs':{'gramjs':{'name':_0x37b7(0x6f),'install':_0x37b7(0x70),'github':'https://github.com/nicegram/nicegram-web','example':'\x0aconst\x20{\x20TelegramClient\x20}\x20=\x20'+_0x37b7(0x71)+_0x37b7(0x72)+'require'+_0x37b7(0x73)},'tdl':{'name':_0x37b7(0x74),'install':_0x37b7(0x75),'github':'https://github.com/Bannerets/tdl'}},'multiPlatform':{'tdlib':{'name':_0x37b7(0x76),'description':_0x37b7(0x77),'github':'https://github.com/tdlib/td','docs':'https://core.telegram.org/tdlib','platforms':[_0x37b7(0x78),'Java','Swift','Kotlin',_0x37b7(0x79)]}},'dotnet':{'wtelegramclient':{'name':_0x37b7(0x7a),'install':_0x37b7(0x7b),'github':_0x37b7(0x7c)}}};export const TELEGRAM_BACKEND_ENDPOINTS={'initAuth':{'method':'POST','path':'/telegram/auth/init','body':{'phoneNumber':_0x37b7(0x7d)},'response':{'codeHash':'string','phoneCodeHash':_0x37b7(0x7d)}},'verifyCode':{'method':'POST','path':'/telegram/auth/verify','body':{'phoneNumber':_0x37b7(0x7d),'code':_0x37b7(0x7d),'phoneCodeHash':'string'},'response':{'sessionString':_0x37b7(0x7d),'user':_0x37b7(0x7e)}},'verify2FA':{'method':'POST','path':_0x37b7(0x7f),'body':{'password':'string','sessionString':_0x37b7(0x7d)},'response':{'sessionString':_0x37b7(0x7d),'user':'TelegramUser'}},'getDialogs':{'method':'GET','path':_0x37b7(0x80),'query':{'limit':_0x37b7(0x81),'folderId':'number','offsetDate':'number'},'response':{'dialogs':_0x37b7(0x82),'users':_0x37b7(0x83),'chats':_0x37b7(0x84)}},'getMessages':{'method':'GET','path':_0x37b7(0x85),'query':{'limit':_0x37b7(0x81),'offsetId':_0x37b7(0x81)},'response':{'messages':_0x37b7(0x86)}},'storeData':{'method':'POST','path':_0x37b7(0x36),'body':{'platform':'mobile-telegram','data':_0x37b7(0x87)},'response':{'success':_0x37b7(0x88),'message':'string'}}};export const TELEGRAM_RATE_LIMITS={'requests_per_second':0x1,'flood_wait_handling':_0x37b7(0x89),'batch_size':0x64,'telethon_config':{'flood_sleep_threshold':0x3c}};function _0x318b(){const _0x318ddd=['✅\x20[TELEGRAM_SERVICE]\x20Successfully\x20stored\x20Telegram\x20data','❌\x20[TELEGRAM_SERVICE]\x20Invalid\x20input:\x20userId\x20missing','📊\x20[TELEGRAM_SERVICE]\x20Messages:','Invalid\x20input:\x20userId\x20missing.','onairos_jwt_token','enoch_token','auth_token','❌\x20[TELEGRAM_SERVICE]\x20No\x20auth\x20token\x20found','Authentication\x20token\x20not\x20found.\x20Please\x20log\x20in\x20again.','ios','iPhone','mobile-telegram','messaging','📡\x20[TELEGRAM_SERVICE]\x20Sending\x20to\x20backend...','ACXPV','jGnHj','Unknown\x20error','❌\x20[TELEGRAM_SERVICE]\x20Network\x20error:','log','🚀\x20[TELEGRAM_SERVICE]\x20Storing\x20Telegram\x20data\x20for:','📊\x20[TELEGRAM_SERVICE]\x20Dialogs:','qgyzf','messages','error','yURGg','cQUby','getItem','IhjKq','zGopF','lNZkt','cXdAp','EaJii','🔑\x20[TELEGRAM_SERVICE]\x20Auth\x20token\x20found','sMUIW','17.0','sywSm','cTcsv','OJqEa','lFQvv','XBFxF','dialogs','map','title','type','unreadCount','lastMessageDate','chatId','text','timestamp','toISOString','userId','length','JmVfv','BASE_URL','/platform-data/store','pXZLC','OnairosSDK/1.0.0\x20(','stringify','json','FDIEy','qWnlz','message','iWBso','pnoOL','📝\x20[TELEGRAM_SERVICE]\x20Backend\x20response:\x20','kynaC','data','warn','DZveO','HTTP\x20','status','wGWKT','AGgEW','PgBuo','messages.getDialogs','Returns\x20the\x20current\x20user\x20dialog\x20list','#\x20-\x20Flags\x20for\x20conditional\x20fields','flags.0?\x20true\x20-\x20Exclude\x20pinned\x20dialogs','flags.1?\x20int\x20-\x20Peer\x20folder\x20ID\x20(0=main,\x201=archived)','int\x20-\x20Offset\x20for\x20pagination\x20(Unix\x20timestamp)','int\x20-\x20Offset\x20message\x20ID\x20for\x20pagination','InputPeer\x20-\x20Offset\x20peer\x20for\x20pagination','int\x20-\x20Number\x20of\x20dialogs\x20to\x20return\x20(max\x20~100)','long\x20-\x20Hash\x20for\x20caching/efficient\x20pagination','messages.Dialogs\x20-\x20Contains\x20dialogs,\x20messages,\x20chats,\x20users\x20arrays','FOLDER_ID_INVALID\x20-\x20Invalid\x20folder\x20ID','OFFSET_PEER_ID_INVALID\x20-\x20Invalid\x20offset\x20peer','messages.getHistory','InputPeer\x20-\x20Target\x20chat/user/channel','int\x20-\x20Offset\x20date\x20(Unix\x20timestamp)','int\x20-\x20Additional\x20offset','int\x20-\x20Number\x20of\x20messages\x20to\x20return','int\x20-\x20Minimum\x20message\x20ID\x20to\x20fetch','long\x20-\x20Hash\x20for\x20caching','messages.search','Search\x20for\x20messages','InputPeer\x20-\x20Target\x20peer\x20(use\x20inputPeerEmpty\x20for\x20global)','MessagesFilter\x20-\x20Filter\x20type\x20(photos,\x20videos,\x20etc)','int\x20-\x20Minimum\x20date\x20filter','int\x20-\x20Maximum\x20date\x20filter','int\x20-\x20Number\x20of\x20results','int\x20-\x20Maximum\x20message\x20ID','int\x20-\x20Minimum\x20message\x20ID','messages.Messages','https://github.com/LonamiWebs/Telethon','https://docs.telethon.dev/','\x0afrom\x20telethon\x20import\x20TelegramClient\x0aimport\x20asyncio\x0a\x0aapi_id\x20=\x20123456\x20\x20#\x20Your\x20API\x20ID\x0aapi_hash\x20=\x20\x270123456789abcdef0123456789abcdef\x27\x0a\x0aasync\x20def\x20main():\x0a\x20\x20\x20\x20client\x20=\x20TelegramClient(\x27session_name\x27,\x20api_id,\x20api_hash)\x0a\x20\x20\x20\x20await\x20client.start()\x0a\x20\x20\x20\x20\x0a\x20\x20\x20\x20#\x20Get\x20dialogs\x20(chats\x20list)\x0a\x20\x20\x20\x20dialogs\x20=\x20await\x20client.get_dialogs(limit=50)\x0a\x20\x20\x20\x20for\x20dialog\x20in\x20dialogs:\x0a\x20\x20\x20\x20\x20\x20\x20\x20print(f\x22ID:\x20{dialog.id},\x20Title:\x20{dialog.title},\x20Unread:\x20{dialog.unread_count}\x22)\x0a\x20\x20\x20\x20\x0a\x20\x20\x20\x20#\x20Get\x20messages\x20from\x20a\x20specific\x20chat\x0a\x20\x20\x20\x20messages\x20=\x20await\x20client.get_messages(dialog.entity,\x20limit=100)\x0a\x20\x20\x20\x20for\x20msg\x20in\x20messages:\x0a\x20\x20\x20\x20\x20\x20\x20\x20if\x20msg.out:\x20\x20#\x20Outgoing\x20messages\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20print(f\x22[{msg.date}]\x20{msg.text}\x22)\x0a\x20\x20\x20\x20\x0a\x20\x20\x20\x20await\x20client.disconnect()\x0a\x0aasyncio.run(main())\x0a\x20\x20\x20\x20\x20\x20','Pyrogram','pip\x20install\x20pyrogram','https://github.com/pyrogram/pyrogram','https://docs.pyrogram.org/','GramJS\x20(telegram)','npm\x20install\x20telegram','require','(\x27telegram\x27);\x0aconst\x20{\x20StringSession\x20}\x20=\x20','(\x27telegram/sessions\x27);\x0a\x0aconst\x20apiId\x20=\x20123456;\x0aconst\x20apiHash\x20=\x20\x270123456789abcdef0123456789abcdef\x27;\x0aconst\x20stringSession\x20=\x20new\x20StringSession(\x27\x27);\x20//\x20Empty\x20for\x20new\x20session\x0a\x0aasync\x20function\x20main()\x20{\x0a\x20\x20\x20\x20const\x20client\x20=\x20new\x20TelegramClient(stringSession,\x20apiId,\x20apiHash,\x20{\x0a\x20\x20\x20\x20\x20\x20\x20\x20connectionRetries:\x205,\x0a\x20\x20\x20\x20});\x0a\x20\x20\x20\x20\x0a\x20\x20\x20\x20await\x20client.start({\x0a\x20\x20\x20\x20\x20\x20\x20\x20phoneNumber:\x20async\x20()\x20=>\x20\x27+1234567890\x27,\x0a\x20\x20\x20\x20\x20\x20\x20\x20password:\x20async\x20()\x20=>\x20\x27your_2fa_password\x27,\x20//\x20If\x202FA\x20enabled\x0a\x20\x20\x20\x20\x20\x20\x20\x20phoneCode:\x20async\x20()\x20=>\x20\x27CODE_FROM_TELEGRAM\x27,\x0a\x20\x20\x20\x20\x20\x20\x20\x20onError:\x20(err)\x20=>\x20console.log(err),\x0a\x20\x20\x20\x20});\x0a\x20\x20\x20\x20\x0a\x20\x20\x20\x20//\x20Save\x20session\x20for\x20future\x20use\x0a\x20\x20\x20\x20console.log(\x27Session:\x27,\x20client.session.save());\x0a\x20\x20\x20\x20\x0a\x20\x20\x20\x20//\x20Get\x20dialogs\x0a\x20\x20\x20\x20const\x20dialogs\x20=\x20await\x20client.getDialogs({\x20limit:\x2050\x20});\x0a\x20\x20\x20\x20for\x20(const\x20dialog\x20of\x20dialogs)\x20{\x0a\x20\x20\x20\x20\x20\x20\x20\x20console.log(`${dialog.title}:\x20${dialog.unreadCount}\x20unread`);\x0a\x20\x20\x20\x20}\x0a\x20\x20\x20\x20\x0a\x20\x20\x20\x20//\x20Get\x20messages\x20from\x20a\x20chat\x0a\x20\x20\x20\x20const\x20messages\x20=\x20await\x20client.getMessages(dialog.entity,\x20{\x20limit:\x20100\x20});\x0a\x20\x20\x20\x20for\x20(const\x20msg\x20of\x20messages)\x20{\x0a\x20\x20\x20\x20\x20\x20\x20\x20if\x20(msg.out)\x20{\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20console.log(`[${msg.date}]\x20${msg.text}`);\x0a\x20\x20\x20\x20\x20\x20\x20\x20}\x0a\x20\x20\x20\x20}\x0a}\x0a\x0amain();\x0a\x20\x20\x20\x20\x20\x20','TDL\x20(TDLib\x20wrapper)','npm\x20install\x20tdl\x20tdl-tdlib-addon','TDLib\x20(Official)','Official\x20Telegram\x20Database\x20Library\x20-\x20most\x20complete\x20but\x20complex','C++','Flutter\x20(via\x20bindings)','WTelegramClient','dotnet\x20add\x20package\x20WTelegramClient','https://github.com/wiz0u/WTelegramClient','string','TelegramUser','/telegram/auth/2fa','/telegram/dialogs','number','TelegramDialogData[]','User[]','Chat[]','/telegram/messages/:peerId','TelegramMessageData[]','TelegramStorageData','boolean','On\x20FLOOD_WAIT_X\x20error,\x20sleep\x20for\x20X\x20seconds'];_0x318b=function(){return _0x318ddd;};return _0x318b();}
|
|
1
|
+
/**
|
|
2
|
+
* Telegram Data Service
|
|
3
|
+
*
|
|
4
|
+
* API layer for storing Telegram data on backend.
|
|
5
|
+
* Sends extracted dialogs and messages to /platform-data/store endpoint.
|
|
6
|
+
*
|
|
7
|
+
* MATCHES ChatGPT implementation pattern
|
|
8
|
+
* - Uses format: { platform, data, metadata }
|
|
9
|
+
* - Platform: "mobile-telegram"
|
|
10
|
+
*
|
|
11
|
+
* ============================================================
|
|
12
|
+
* TELEGRAM MTProto API REFERENCE
|
|
13
|
+
* ============================================================
|
|
14
|
+
*
|
|
15
|
+
* Method: messages.getDialogs
|
|
16
|
+
* @see https://core.telegram.org/method/messages.getDialogs
|
|
17
|
+
*
|
|
18
|
+
* Parameters:
|
|
19
|
+
* - flags (#): Flags for conditional fields
|
|
20
|
+
* - exclude_pinned (flags.0? true): Exclude pinned dialogs
|
|
21
|
+
* - folder_id (flags.1? int): Peer folder ID (archived = 1)
|
|
22
|
+
* - offset_date (int): Offset for pagination (date-based)
|
|
23
|
+
* - offset_id (int): Offset for pagination (top message ID)
|
|
24
|
+
* - offset_peer (InputPeer): Offset peer for pagination
|
|
25
|
+
* - limit (int): Number of dialogs to return
|
|
26
|
+
* - hash (long): Hash for caching and efficient pagination
|
|
27
|
+
*
|
|
28
|
+
* Returns: messages.Dialogs containing dialogs, messages, chats, users
|
|
29
|
+
*
|
|
30
|
+
* Method: messages.getHistory
|
|
31
|
+
* @see https://core.telegram.org/method/messages.getHistory
|
|
32
|
+
*
|
|
33
|
+
* Authorization:
|
|
34
|
+
* - Requires api_id and api_hash from https://my.telegram.org/apps
|
|
35
|
+
* - User must authenticate with phone number + code + optional 2FA
|
|
36
|
+
*
|
|
37
|
+
* Libraries:
|
|
38
|
+
* - Python: Telethon, Pyrogram
|
|
39
|
+
* - Multi-language: TDLib (official)
|
|
40
|
+
* - C#/.NET: WTelegramClient
|
|
41
|
+
*
|
|
42
|
+
* ============================================================
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
import { API_CONFIG } from '../config/api';
|
|
46
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
47
|
+
import { Platform } from 'react-native';
|
|
48
|
+
|
|
49
|
+
// ============================================================
|
|
50
|
+
// TELEGRAM API TYPES - Based on MTProto Layer 214+
|
|
51
|
+
// ============================================================
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Telegram Dialog entity types
|
|
55
|
+
* Matches MTProto entity types returned by messages.getDialogs
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Structure of a Telegram dialog/chat
|
|
60
|
+
* Based on messages.Dialogs response from MTProto API
|
|
61
|
+
*
|
|
62
|
+
* @see https://core.telegram.org/constructor/dialog
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Structure of a Telegram message
|
|
67
|
+
* Based on messages.getHistory response from MTProto API
|
|
68
|
+
*
|
|
69
|
+
* @see https://core.telegram.org/constructor/message
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Combined Telegram data to store
|
|
74
|
+
* Matches structure returned by messages.getDialogs + messages.getHistory
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Response from backend endpoint
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Store Telegram data on backend
|
|
83
|
+
*
|
|
84
|
+
* @param userId - Username or identifier
|
|
85
|
+
* @param data - Telegram dialogs and messages data
|
|
86
|
+
* @returns Response indicating success/failure with metadata
|
|
87
|
+
*/
|
|
88
|
+
export const storeTelegramData = async (userId, data) => {
|
|
89
|
+
console.log('🚀 [TELEGRAM_SERVICE] Storing Telegram data for:', userId);
|
|
90
|
+
console.log('📊 [TELEGRAM_SERVICE] Dialogs:', data.dialogs.length);
|
|
91
|
+
console.log('📊 [TELEGRAM_SERVICE] Messages:', data.messages.length);
|
|
92
|
+
|
|
93
|
+
// Input validation
|
|
94
|
+
if (!userId) {
|
|
95
|
+
console.error('❌ [TELEGRAM_SERVICE] Invalid input: userId missing');
|
|
96
|
+
return {
|
|
97
|
+
success: false,
|
|
98
|
+
error: 'Invalid input: userId missing.'
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
// Get auth token - check all possible storage keys
|
|
103
|
+
const authToken = (await AsyncStorage.getItem('onairos_jwt_token')) || (await AsyncStorage.getItem('enoch_token')) || (await AsyncStorage.getItem('auth_token'));
|
|
104
|
+
if (!authToken) {
|
|
105
|
+
console.error('❌ [TELEGRAM_SERVICE] No auth token found');
|
|
106
|
+
return {
|
|
107
|
+
success: false,
|
|
108
|
+
error: 'Authentication token not found. Please log in again.'
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
console.log('🔑 [TELEGRAM_SERVICE] Auth token found');
|
|
112
|
+
|
|
113
|
+
// Mobile metadata
|
|
114
|
+
const mobileMetadata = {
|
|
115
|
+
platform: Platform.OS,
|
|
116
|
+
appVersion: '1.0.0',
|
|
117
|
+
osVersion: Platform.OS === 'ios' ? '17.0' : Platform.OS,
|
|
118
|
+
deviceModel: Platform.OS === 'ios' ? 'iPhone' : 'Android',
|
|
119
|
+
isOfflineSync: false,
|
|
120
|
+
extractedAt: new Date().toISOString()
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
// Build request body
|
|
124
|
+
const requestBody = {
|
|
125
|
+
platform: 'mobile-telegram',
|
|
126
|
+
dataType: 'messaging',
|
|
127
|
+
data: {
|
|
128
|
+
dialogs: data.dialogs.map(dialog => ({
|
|
129
|
+
dialogId: dialog.id,
|
|
130
|
+
title: dialog.title,
|
|
131
|
+
type: dialog.type,
|
|
132
|
+
unreadCount: dialog.unreadCount,
|
|
133
|
+
lastMessageDate: dialog.lastMessageDate
|
|
134
|
+
})),
|
|
135
|
+
messages: data.messages.map((msg, idx) => ({
|
|
136
|
+
messageId: msg.id,
|
|
137
|
+
chatId: msg.chatId,
|
|
138
|
+
content: msg.text,
|
|
139
|
+
timestamp: msg.timestamp || new Date().toISOString(),
|
|
140
|
+
type: msg.type,
|
|
141
|
+
role: 'user' // All extracted messages are user's outgoing messages
|
|
142
|
+
})),
|
|
143
|
+
telegramUserId: data.userId
|
|
144
|
+
},
|
|
145
|
+
summary: {
|
|
146
|
+
dialogCount: data.dialogs.length,
|
|
147
|
+
messageCount: data.messages.length,
|
|
148
|
+
textMessages: data.messages.filter(m => m.type === 'text').length,
|
|
149
|
+
mediaMessages: data.messages.filter(m => m.type !== 'text').length
|
|
150
|
+
},
|
|
151
|
+
mobileMetadata: mobileMetadata
|
|
152
|
+
};
|
|
153
|
+
console.log('📡 [TELEGRAM_SERVICE] Sending to backend...');
|
|
154
|
+
console.log('📍 [TELEGRAM_SERVICE] URL:', `${API_CONFIG.BASE_URL}/platform-data/store`);
|
|
155
|
+
const response = await fetch(`${API_CONFIG.BASE_URL}/platform-data/store`, {
|
|
156
|
+
method: 'POST',
|
|
157
|
+
headers: {
|
|
158
|
+
'Content-Type': 'application/json',
|
|
159
|
+
'Authorization': `Bearer ${authToken}`,
|
|
160
|
+
'User-Agent': `OnairosSDK/1.0.0 (${Platform.OS})`
|
|
161
|
+
},
|
|
162
|
+
body: JSON.stringify(requestBody)
|
|
163
|
+
});
|
|
164
|
+
const responseData = await response.json();
|
|
165
|
+
if (response.ok) {
|
|
166
|
+
console.log('✅ [TELEGRAM_SERVICE] Successfully stored Telegram data');
|
|
167
|
+
if (responseData.message) {
|
|
168
|
+
console.log(`📝 [TELEGRAM_SERVICE] Backend response: ${responseData.message}`);
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
success: true,
|
|
172
|
+
message: responseData.message || 'Telegram data stored successfully',
|
|
173
|
+
data: responseData.data
|
|
174
|
+
};
|
|
175
|
+
} else {
|
|
176
|
+
console.warn(`⚠️ [TELEGRAM_SERVICE] Backend returned status: ${response.status}`);
|
|
177
|
+
console.warn(`⚠️ [TELEGRAM_SERVICE] Error: ${responseData.error || 'Unknown error'}`);
|
|
178
|
+
return {
|
|
179
|
+
success: false,
|
|
180
|
+
error: responseData.error || `HTTP ${response.status}`
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
} catch (error) {
|
|
184
|
+
console.error('❌ [TELEGRAM_SERVICE] Network error:', error);
|
|
185
|
+
return {
|
|
186
|
+
success: false,
|
|
187
|
+
error: error.message || 'Network error. Please check your connection.'
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
// ============================================================
|
|
193
|
+
// TELEGRAM MTProto API CONFIGURATION
|
|
194
|
+
// ============================================================
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Telegram MTProto API Configuration
|
|
198
|
+
*
|
|
199
|
+
* REQUIRED: Register at https://my.telegram.org/apps to get:
|
|
200
|
+
* - api_id (integer)
|
|
201
|
+
* - api_hash (string, 32 hex chars)
|
|
202
|
+
*
|
|
203
|
+
* @see https://core.telegram.org/api/obtaining_api_id
|
|
204
|
+
*/
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* MTProto API Method Parameters
|
|
208
|
+
* Based on Layer 214+ schema
|
|
209
|
+
*/
|
|
210
|
+
export const TELEGRAM_MTPROTO_API = {
|
|
211
|
+
// ============================================================
|
|
212
|
+
// messages.getDialogs - Get user's chat list
|
|
213
|
+
// @see https://core.telegram.org/method/messages.getDialogs
|
|
214
|
+
// ============================================================
|
|
215
|
+
getDialogs: {
|
|
216
|
+
method: 'messages.getDialogs',
|
|
217
|
+
description: 'Returns the current user dialog list',
|
|
218
|
+
parameters: {
|
|
219
|
+
flags: '# - Flags for conditional fields',
|
|
220
|
+
exclude_pinned: 'flags.0? true - Exclude pinned dialogs',
|
|
221
|
+
folder_id: 'flags.1? int - Peer folder ID (0=main, 1=archived)',
|
|
222
|
+
offset_date: 'int - Offset for pagination (Unix timestamp)',
|
|
223
|
+
offset_id: 'int - Offset message ID for pagination',
|
|
224
|
+
offset_peer: 'InputPeer - Offset peer for pagination',
|
|
225
|
+
limit: 'int - Number of dialogs to return (max ~100)',
|
|
226
|
+
hash: 'long - Hash for caching/efficient pagination'
|
|
227
|
+
},
|
|
228
|
+
returns: 'messages.Dialogs - Contains dialogs, messages, chats, users arrays',
|
|
229
|
+
errors: ['FOLDER_ID_INVALID - Invalid folder ID', 'OFFSET_PEER_ID_INVALID - Invalid offset peer']
|
|
230
|
+
},
|
|
231
|
+
// ============================================================
|
|
232
|
+
// messages.getHistory - Get messages from a chat
|
|
233
|
+
// @see https://core.telegram.org/method/messages.getHistory
|
|
234
|
+
// ============================================================
|
|
235
|
+
getHistory: {
|
|
236
|
+
method: 'messages.getHistory',
|
|
237
|
+
description: 'Get messages from a peer (chat/user/channel)',
|
|
238
|
+
parameters: {
|
|
239
|
+
peer: 'InputPeer - Target chat/user/channel',
|
|
240
|
+
offset_id: 'int - Offset message ID',
|
|
241
|
+
offset_date: 'int - Offset date (Unix timestamp)',
|
|
242
|
+
add_offset: 'int - Additional offset',
|
|
243
|
+
limit: 'int - Number of messages to return',
|
|
244
|
+
max_id: 'int - Maximum message ID to fetch',
|
|
245
|
+
min_id: 'int - Minimum message ID to fetch',
|
|
246
|
+
hash: 'long - Hash for caching'
|
|
247
|
+
},
|
|
248
|
+
returns: 'messages.Messages - Contains messages, chats, users arrays',
|
|
249
|
+
errors: ['CHAT_ID_INVALID - Invalid chat ID', 'PEER_ID_INVALID - Invalid peer']
|
|
250
|
+
},
|
|
251
|
+
// ============================================================
|
|
252
|
+
// messages.search - Search messages
|
|
253
|
+
// @see https://core.telegram.org/method/messages.search
|
|
254
|
+
// ============================================================
|
|
255
|
+
search: {
|
|
256
|
+
method: 'messages.search',
|
|
257
|
+
description: 'Search for messages',
|
|
258
|
+
parameters: {
|
|
259
|
+
peer: 'InputPeer - Target peer (use inputPeerEmpty for global)',
|
|
260
|
+
q: 'string - Search query',
|
|
261
|
+
from_id: 'InputPeer - Filter by sender (optional)',
|
|
262
|
+
filter: 'MessagesFilter - Filter type (photos, videos, etc)',
|
|
263
|
+
min_date: 'int - Minimum date filter',
|
|
264
|
+
max_date: 'int - Maximum date filter',
|
|
265
|
+
offset_id: 'int - Offset message ID',
|
|
266
|
+
add_offset: 'int - Additional offset',
|
|
267
|
+
limit: 'int - Number of results',
|
|
268
|
+
max_id: 'int - Maximum message ID',
|
|
269
|
+
min_id: 'int - Minimum message ID',
|
|
270
|
+
hash: 'long - Hash for caching'
|
|
271
|
+
},
|
|
272
|
+
returns: 'messages.Messages'
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Recommended Libraries for MTProto Implementation
|
|
278
|
+
*/
|
|
279
|
+
export const TELEGRAM_LIBRARIES = {
|
|
280
|
+
python: {
|
|
281
|
+
telethon: {
|
|
282
|
+
name: 'Telethon',
|
|
283
|
+
install: 'pip install telethon',
|
|
284
|
+
github: 'https://github.com/LonamiWebs/Telethon',
|
|
285
|
+
docs: 'https://docs.telethon.dev/',
|
|
286
|
+
example: `
|
|
287
|
+
from telethon import TelegramClient
|
|
288
|
+
import asyncio
|
|
289
|
+
|
|
290
|
+
api_id = 123456 # Your API ID
|
|
291
|
+
api_hash = '0123456789abcdef0123456789abcdef'
|
|
292
|
+
|
|
293
|
+
async def main():
|
|
294
|
+
client = TelegramClient('session_name', api_id, api_hash)
|
|
295
|
+
await client.start()
|
|
296
|
+
|
|
297
|
+
# Get dialogs (chats list)
|
|
298
|
+
dialogs = await client.get_dialogs(limit=50)
|
|
299
|
+
for dialog in dialogs:
|
|
300
|
+
print(f"ID: {dialog.id}, Title: {dialog.title}, Unread: {dialog.unread_count}")
|
|
301
|
+
|
|
302
|
+
# Get messages from a specific chat
|
|
303
|
+
messages = await client.get_messages(dialog.entity, limit=100)
|
|
304
|
+
for msg in messages:
|
|
305
|
+
if msg.out: # Outgoing messages
|
|
306
|
+
print(f"[{msg.date}] {msg.text}")
|
|
307
|
+
|
|
308
|
+
await client.disconnect()
|
|
309
|
+
|
|
310
|
+
asyncio.run(main())
|
|
311
|
+
`
|
|
312
|
+
},
|
|
313
|
+
pyrogram: {
|
|
314
|
+
name: 'Pyrogram',
|
|
315
|
+
install: 'pip install pyrogram',
|
|
316
|
+
github: 'https://github.com/pyrogram/pyrogram',
|
|
317
|
+
docs: 'https://docs.pyrogram.org/'
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
nodejs: {
|
|
321
|
+
gramjs: {
|
|
322
|
+
name: 'GramJS (telegram)',
|
|
323
|
+
install: 'npm install telegram',
|
|
324
|
+
github: 'https://github.com/nicegram/nicegram-web',
|
|
325
|
+
example: `
|
|
326
|
+
const { TelegramClient } = ${'require'}('telegram');
|
|
327
|
+
const { StringSession } = ${'require'}('telegram/sessions');
|
|
328
|
+
|
|
329
|
+
const apiId = 123456;
|
|
330
|
+
const apiHash = '0123456789abcdef0123456789abcdef';
|
|
331
|
+
const stringSession = new StringSession(''); // Empty for new session
|
|
332
|
+
|
|
333
|
+
async function main() {
|
|
334
|
+
const client = new TelegramClient(stringSession, apiId, apiHash, {
|
|
335
|
+
connectionRetries: 5,
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
await client.start({
|
|
339
|
+
phoneNumber: async () => '+1234567890',
|
|
340
|
+
password: async () => 'your_2fa_password', // If 2FA enabled
|
|
341
|
+
phoneCode: async () => 'CODE_FROM_TELEGRAM',
|
|
342
|
+
onError: (err) => console.log(err),
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
// Save session for future use
|
|
346
|
+
console.log('Session:', client.session.save());
|
|
347
|
+
|
|
348
|
+
// Get dialogs
|
|
349
|
+
const dialogs = await client.getDialogs({ limit: 50 });
|
|
350
|
+
for (const dialog of dialogs) {
|
|
351
|
+
console.log(\`\${dialog.title}: \${dialog.unreadCount} unread\`);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// Get messages from a chat
|
|
355
|
+
const messages = await client.getMessages(dialog.entity, { limit: 100 });
|
|
356
|
+
for (const msg of messages) {
|
|
357
|
+
if (msg.out) {
|
|
358
|
+
console.log(\`[\${msg.date}] \${msg.text}\`);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
main();
|
|
364
|
+
`
|
|
365
|
+
},
|
|
366
|
+
tdl: {
|
|
367
|
+
name: 'TDL (TDLib wrapper)',
|
|
368
|
+
install: 'npm install tdl tdl-tdlib-addon',
|
|
369
|
+
github: 'https://github.com/Bannerets/tdl'
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
multiPlatform: {
|
|
373
|
+
tdlib: {
|
|
374
|
+
name: 'TDLib (Official)',
|
|
375
|
+
description: 'Official Telegram Database Library - most complete but complex',
|
|
376
|
+
github: 'https://github.com/tdlib/td',
|
|
377
|
+
docs: 'https://core.telegram.org/tdlib',
|
|
378
|
+
platforms: ['C++', 'Java', 'Swift', 'Kotlin', 'Flutter (via bindings)']
|
|
379
|
+
}
|
|
380
|
+
},
|
|
381
|
+
dotnet: {
|
|
382
|
+
wtelegramclient: {
|
|
383
|
+
name: 'WTelegramClient',
|
|
384
|
+
install: 'dotnet add package WTelegramClient',
|
|
385
|
+
github: 'https://github.com/wiz0u/WTelegramClient'
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Backend API endpoints for Telegram integration
|
|
392
|
+
* These should be implemented on your backend server
|
|
393
|
+
*/
|
|
394
|
+
export const TELEGRAM_BACKEND_ENDPOINTS = {
|
|
395
|
+
// Initialize session and send auth code
|
|
396
|
+
initAuth: {
|
|
397
|
+
method: 'POST',
|
|
398
|
+
path: '/telegram/auth/init',
|
|
399
|
+
body: {
|
|
400
|
+
phoneNumber: 'string'
|
|
401
|
+
},
|
|
402
|
+
response: {
|
|
403
|
+
codeHash: 'string',
|
|
404
|
+
phoneCodeHash: 'string'
|
|
405
|
+
}
|
|
406
|
+
},
|
|
407
|
+
// Verify code and complete auth
|
|
408
|
+
verifyCode: {
|
|
409
|
+
method: 'POST',
|
|
410
|
+
path: '/telegram/auth/verify',
|
|
411
|
+
body: {
|
|
412
|
+
phoneNumber: 'string',
|
|
413
|
+
code: 'string',
|
|
414
|
+
phoneCodeHash: 'string'
|
|
415
|
+
},
|
|
416
|
+
response: {
|
|
417
|
+
sessionString: 'string',
|
|
418
|
+
user: 'TelegramUser'
|
|
419
|
+
}
|
|
420
|
+
},
|
|
421
|
+
// Provide 2FA password if required
|
|
422
|
+
verify2FA: {
|
|
423
|
+
method: 'POST',
|
|
424
|
+
path: '/telegram/auth/2fa',
|
|
425
|
+
body: {
|
|
426
|
+
password: 'string',
|
|
427
|
+
sessionString: 'string'
|
|
428
|
+
},
|
|
429
|
+
response: {
|
|
430
|
+
sessionString: 'string',
|
|
431
|
+
user: 'TelegramUser'
|
|
432
|
+
}
|
|
433
|
+
},
|
|
434
|
+
// Get user's dialogs (uses messages.getDialogs)
|
|
435
|
+
getDialogs: {
|
|
436
|
+
method: 'GET',
|
|
437
|
+
path: '/telegram/dialogs',
|
|
438
|
+
query: {
|
|
439
|
+
limit: 'number',
|
|
440
|
+
folderId: 'number',
|
|
441
|
+
offsetDate: 'number'
|
|
442
|
+
},
|
|
443
|
+
response: {
|
|
444
|
+
dialogs: 'TelegramDialogData[]',
|
|
445
|
+
users: 'User[]',
|
|
446
|
+
chats: 'Chat[]'
|
|
447
|
+
}
|
|
448
|
+
},
|
|
449
|
+
// Get messages from a chat (uses messages.getHistory)
|
|
450
|
+
getMessages: {
|
|
451
|
+
method: 'GET',
|
|
452
|
+
path: '/telegram/messages/:peerId',
|
|
453
|
+
query: {
|
|
454
|
+
limit: 'number',
|
|
455
|
+
offsetId: 'number'
|
|
456
|
+
},
|
|
457
|
+
response: {
|
|
458
|
+
messages: 'TelegramMessageData[]'
|
|
459
|
+
}
|
|
460
|
+
},
|
|
461
|
+
// Store extracted data (from mobile SDK)
|
|
462
|
+
storeData: {
|
|
463
|
+
method: 'POST',
|
|
464
|
+
path: '/platform-data/store',
|
|
465
|
+
body: {
|
|
466
|
+
platform: 'mobile-telegram',
|
|
467
|
+
data: 'TelegramStorageData'
|
|
468
|
+
},
|
|
469
|
+
response: {
|
|
470
|
+
success: 'boolean',
|
|
471
|
+
message: 'string'
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Rate Limiting Guidelines
|
|
478
|
+
* Telegram has strict rate limits - handle FLOOD_WAIT errors
|
|
479
|
+
*/
|
|
480
|
+
export const TELEGRAM_RATE_LIMITS = {
|
|
481
|
+
// General guidelines (actual limits vary)
|
|
482
|
+
requests_per_second: 1,
|
|
483
|
+
// ~1 request/second recommended
|
|
484
|
+
flood_wait_handling: 'On FLOOD_WAIT_X error, sleep for X seconds',
|
|
485
|
+
batch_size: 100,
|
|
486
|
+
// Max items per request for most methods
|
|
487
|
+
|
|
488
|
+
// Telethon auto-handles with flood_sleep_threshold
|
|
489
|
+
telethon_config: {
|
|
490
|
+
flood_sleep_threshold: 60 // Auto-sleep up to 60s on flood
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
//# sourceMappingURL=telegramDataService.js.map
|
|
@@ -1 +1,67 @@
|
|
|
1
|
-
|
|
1
|
+
import { getEncryptedPinForAPI } from './pinEncryptionService';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Helper functions for training API modifications
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Add encrypted PIN to training data if available
|
|
9
|
+
*/
|
|
10
|
+
export const addEncryptedPinToTrainingData = async trainingData => {
|
|
11
|
+
try {
|
|
12
|
+
// Get encrypted PIN
|
|
13
|
+
const encryptedPin = await getEncryptedPinForAPI();
|
|
14
|
+
if (encryptedPin) {
|
|
15
|
+
console.log('✅ Adding encrypted PIN to training data');
|
|
16
|
+
return {
|
|
17
|
+
...trainingData,
|
|
18
|
+
encryptedPin: encryptedPin,
|
|
19
|
+
hasPinData: true
|
|
20
|
+
};
|
|
21
|
+
} else {
|
|
22
|
+
console.log('⚠️ No PIN available for training data');
|
|
23
|
+
return {
|
|
24
|
+
...trainingData,
|
|
25
|
+
hasPinData: false
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.error('❌ Error adding encrypted PIN to training data:', error);
|
|
30
|
+
return {
|
|
31
|
+
...trainingData,
|
|
32
|
+
hasPinData: false
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Example of how to modify the training API call to include PIN
|
|
39
|
+
*
|
|
40
|
+
* Usage in UniversalOnboarding.tsx:
|
|
41
|
+
*
|
|
42
|
+
* ```typescript
|
|
43
|
+
* // Before sending to API
|
|
44
|
+
* const trainingData = {
|
|
45
|
+
* socketId,
|
|
46
|
+
* username: finalUsername,
|
|
47
|
+
* email: userInfo?.email || null,
|
|
48
|
+
* modelKey: null,
|
|
49
|
+
* connectedPlatforms: platformsList,
|
|
50
|
+
* platformConnections: connections
|
|
51
|
+
* };
|
|
52
|
+
*
|
|
53
|
+
* // Add encrypted PIN if needed
|
|
54
|
+
* const trainingDataWithPin = await addEncryptedPinToTrainingData(trainingData);
|
|
55
|
+
*
|
|
56
|
+
* // Send to API
|
|
57
|
+
* const response = await fetch('${API_CONFIG.BASE_URL}/mobile-training/enoch', {
|
|
58
|
+
* method: 'POST',
|
|
59
|
+
* headers: {
|
|
60
|
+
* 'Content-Type': 'application/json',
|
|
61
|
+
* 'Authorization': `Bearer ${token}`
|
|
62
|
+
* },
|
|
63
|
+
* body: JSON.stringify(trainingDataWithPin)
|
|
64
|
+
* });
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
//# sourceMappingURL=trainingApiHelpers.js.map
|