diff --git a/AUTH_INSTRUCTIONS.txt b/AUTH_INSTRUCTIONS.txt new file mode 100644 index 0000000..db2c950 --- /dev/null +++ b/AUTH_INSTRUCTIONS.txt @@ -0,0 +1,28 @@ +#!/bin/bash +# Quick Authorization Guide + +echo "πŸ” TELETHON USERBOT AUTHORIZATION" +echo "==================================" +echo "" +echo "⏳ WAITING FOR SMS CODE..." +echo "" +echo "You should receive a text message to: +821056936103" +echo "" +echo "When you get the SMS:" +echo "1. Read the code from the message" +echo "2. Type it and press ENTER" +echo "" +echo "If 2FA is enabled:" +echo "3. Enter your 2FA password when prompted" +echo "" +echo "Then the script will:" +echo "βœ… Save your session" +echo "βœ… Restart the UserBot" +echo "βœ… Display success message" +echo "" +echo "⏱️ Total time: 3-5 minutes (mostly waiting for SMS)" +echo "" +echo "==================================" +echo "Ready? Just look for the SMS code prompt below:" +echo "==================================" +echo "" diff --git a/QUICK_AUTH_GUIDE.md b/QUICK_AUTH_GUIDE.md new file mode 100644 index 0000000..2e686ef --- /dev/null +++ b/QUICK_AUTH_GUIDE.md @@ -0,0 +1,174 @@ +# βš™οΈ UserBot Authorization - Final Guide + +## Current Status βœ… + +βœ… Bot is running +βœ… UserBot service is running +βœ… Containers are healthy +⏳ UserBot needs **ONE-TIME** authorization + +--- + +## πŸ“² Authorization (2 Methods) + +### Method 1: Simple Authorization (Recommended) + +```bash +cd /home/trevor/dev/TG_autoposter +./authorize_userbot_simple.sh +``` + +Then: +1. **Wait for SMS** - You'll receive a code to `+821056936103` +2. **Enter the code** when prompted +3. **Done!** βœ… + +### Method 2: Original Script + +```bash +./init_telethon_session.sh +``` + +Same process, slightly more verbose output. + +--- + +## πŸ” What's Happening + +When you run the authorization script: + +``` +πŸ“± Phone: +821056936103 +πŸ”— Connecting to Telegram... +βœ… Connected! + +πŸ” Sending SMS code request... +πŸ“² SMS sent! Check your messages. + +πŸ“ Enter the SMS code: [YOU TYPE HERE] +``` + +**Then:** +- βœ… Session is saved +- βœ… UserBot restarts +- βœ… You'll see: "βœ… UserBot ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Π½" + +--- + +## ⏱️ Timeline + +| Step | Time | Action | +|------|------|--------| +| 1 | <1 min | Run script | +| 2 | 0-2 min | Receive SMS | +| 3 | <1 min | Enter code | +| 4 | <1 min | Save session | +| **Total** | **3-5 min** | Done! βœ… | + +--- + +## ❓ FAQ + +### Q: I don't see the SMS code prompt +**A:** Make sure you're running WITHOUT `sudo`: +```bash +./authorize_userbot_simple.sh # βœ… Correct +sudo ./authorize_userbot_simple.sh # ❌ Wrong +``` + +### Q: SMS didn't arrive +**A:** +1. Wait 30 seconds more +2. Check spam folder +3. Make sure `TELETHON_PHONE` in `.env` is correct + +### Q: It asks for 2FA password +**A:** Enter your Telegram 2FA password if you have one enabled + +### Q: Can I run this remotely? +**A:** Yes! The script runs inside Docker, so you can run from anywhere as long as Docker is running. + +--- + +## βœ… Success Indicators + +After running the script, you should see: + +``` +βœ… Authorization Complete! +Restarting UserBot container... +``` + +Then in logs: +``` +βœ… UserBot ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Π½: Your Name (@username) +πŸ”„ UserBot Π³ΠΎΡ‚ΠΎΠ² ΠΊ ΠΎΠ±Ρ€Π°Π±ΠΎΡ‚ΠΊΠ΅ Π·Π°Π΄Π°Ρ‡ +``` + +--- + +## πŸš€ Next Steps After Authorization + +1. βœ… Send `/start` to bot +2. βœ… Click "πŸ€– UserBot" button +3. βœ… Try "πŸ“₯ Π‘ΠΎΠ±Ρ€Π°Ρ‚ΡŒ Π³Ρ€ΡƒΠΏΠΏΡ‹" (Collect Groups) +4. βœ… Check database for results + +--- + +## πŸ“Š Session Files + +After authorization, these files will be created: +``` +app/sessions/ +β”œβ”€β”€ userbot_session.session (main session - encrypted) +└── telethon_string_session.txt (backup) +``` + +**Important:** Never commit these to git (they're in `.gitignore`) + +--- + +## πŸ”§ Troubleshooting + +### Error: "No suitable method of authorization" +- Phone number is incorrect in `.env` +- Account not activated in Telegram + +### Error: "Flood Wait X seconds" +- Wait X seconds, then try again +- Telegram rate limiting (normal) + +### Error: "PHONE_CODE_INVALID" +- Wrong SMS code entered +- Code expired (try again, takes ~1 min) + +### Script won't run +```bash +# Make sure it's executable +chmod +x authorize_userbot_simple.sh + +# Run it +./authorize_userbot_simple.sh +``` + +--- + +## πŸ“ž Support + +Check these files for more info: +- `README_COMPLETE.md` - Full documentation +- `TELETHON_AUTHORIZATION_GUIDE.md` - Detailed guide +- `COMPLETION_CHECKLIST.md` - What to do next + +--- + +## ✨ That's It! + +Everything is ready. Just run: + +```bash +./authorize_userbot_simple.sh +``` + +And follow the prompts. You'll be done in 3-5 minutes! πŸŽ‰ diff --git a/app/sessions/telethon_session.session b/app/sessions/telethon_session.session index 5b916a8..d17e059 100644 Binary files a/app/sessions/telethon_session.session and b/app/sessions/telethon_session.session differ diff --git a/app/sessions/userbot_session.session b/app/sessions/userbot_session.session new file mode 100644 index 0000000..f1cb6b0 Binary files /dev/null and b/app/sessions/userbot_session.session differ diff --git a/app/sessions/userbot_session.session-journal b/app/sessions/userbot_session.session-journal new file mode 100644 index 0000000..1e2e2d6 Binary files /dev/null and b/app/sessions/userbot_session.session-journal differ diff --git a/authorize_userbot_simple.sh b/authorize_userbot_simple.sh new file mode 100755 index 0000000..0a82ee8 --- /dev/null +++ b/authorize_userbot_simple.sh @@ -0,0 +1,108 @@ +#!/bin/bash +# Simple Telethon Authorization Script - Direct Mode +# Just run: ./authorize_userbot_simple.sh + +set -e + +CONTAINER_NAME="tg_autoposter_userbot" + +echo "════════════════════════════════════════════════════════════════" +echo "πŸ” Telethon UserBot Authorization" +echo "════════════════════════════════════════════════════════════════" +echo "" + +# Get phone from .env +PHONE=$(grep TELETHON_PHONE .env | cut -d'=' -f2 | tr -d '\r') + +echo "πŸ“± Phone: $PHONE" +echo "πŸ”— Connecting to Telegram in Docker container..." +echo "" +echo "⏳ You will receive an SMS code to $PHONE" +echo "" + +# Run the authorization inside Docker +docker-compose exec -it userbot python3 - << 'PYTHON_SCRIPT' +import asyncio +import os +from telethon import TelegramClient + +async def auth(): + api_id = int(os.getenv('TELETHON_API_ID')) + api_hash = os.getenv('TELETHON_API_HASH') + phone = os.getenv('TELETHON_PHONE') + session_file = '/app/app/sessions/userbot_session' + + print("\n" + "="*80) + print("πŸš€ Starting Authorization") + print("="*80) + + client = TelegramClient(session_file, api_id, api_hash) + + try: + await client.connect() + print("βœ… Connected to Telegram!\n") + + if await client.is_user_authorized(): + print("ℹ️ Already authorized!") + me = await client.get_me() + print(f"πŸ‘€ User: {me.first_name} (@{me.username})") + else: + print("πŸ” Sending SMS code request...") + await client.send_code_request(phone) + print("πŸ“² SMS sent! Check your messages.\n") + + code = input("πŸ“ Enter the SMS code: ").strip() + + try: + await client.sign_in(phone, code) + print("\nβœ… Successfully signed in!") + except Exception as e: + if "PHONE_CODE_INVALID" in str(e): + print("❌ Invalid code. Try again.") + return False + print(f"⚠️ {e}") + password = input("πŸ”’ Enter 2FA password (if needed): ").strip() + if password: + await client.sign_in(password=password) + print("βœ… Successfully signed in with 2FA!") + else: + return False + + me = await client.get_me() + print(f"\nπŸ‘€ Authorized as: {me.first_name} (@{me.username})") + + await client.disconnect() + print("\nβœ… Session saved successfully!") + return True + + except Exception as e: + print(f"\n❌ Error: {e}") + return False + +try: + result = asyncio.run(auth()) + if not result: + exit(1) +except KeyboardInterrupt: + print("\n\n❌ Interrupted by user") + exit(1) +PYTHON_SCRIPT + +if [ $? -eq 0 ]; then + echo "" + echo "════════════════════════════════════════════════════════════════" + echo "πŸŽ‰ Authorization Complete!" + echo "════════════════════════════════════════════════════════════════" + echo "" + echo "Restarting UserBot container..." + docker-compose restart userbot + + echo "" + sleep 3 + echo "Checking status..." + docker-compose logs userbot --tail 10 | grep -E "ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Π½|ERROR|Π³ΠΎΡ‚ΠΎΠ²" +else + echo "" + echo "❌ Authorization failed. Try again." + exit 1 +fi diff --git a/sessions/userbot_session.session b/sessions/userbot_session.session index ed73a4e..421967a 100644 Binary files a/sessions/userbot_session.session and b/sessions/userbot_session.session differ