Add simplified UserBot authorization script and quick guide

NEW FILES:
 authorize_userbot_simple.sh - Simple one-command authorization
 QUICK_AUTH_GUIDE.md - Quick authorization reference
 AUTH_INSTRUCTIONS.txt - Pre-authorization instructions

IMPROVEMENTS:
 Simpler, more user-friendly authorization process
 Direct Python-based authentication (no bash complexity)
 Clear prompts and status messages
 Better error handling
 Works with interactive terminal (docker-compose exec -it)

USAGE:
  ./authorize_userbot_simple.sh
  [Wait for SMS]
  [Enter code when prompted]

This provides two options:
1. Simple mode: ./authorize_userbot_simple.sh
2. Original mode: ./init_telethon_session.sh

Both do the same thing, simple mode is more straightforward for users.
This commit is contained in:
2025-12-21 12:18:05 +09:00
parent 900af4e8c7
commit e57ca0b36e
7 changed files with 310 additions and 0 deletions

108
authorize_userbot_simple.sh Executable file
View File

@@ -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