🔐 Add Telethon session initialization tools and authorization guide
NEW FILES: ✅ init_telethon_session.py - Interactive Python script for session initialization ✅ init_telethon_session.sh - Bash wrapper for Docker-based authorization ✅ TELETHON_AUTHORIZATION_GUIDE.md - Comprehensive authorization guide ✅ USERBOT_AUTHORIZATION_README.md - Quick start guide for users FEATURES: ✅ Interactive authorization flow with SMS code verification ✅ 2FA password support ✅ Session persistence to app/sessions/ ✅ Docker container integration ✅ Verification of existing sessions ✅ Clear error messages and troubleshooting USAGE: $ ./init_telethon_session.sh Or: $ python3 init_telethon_session.py This solves the UserBot authorization issue where Telethon requires interactive SMS code verification on first setup.
This commit is contained in:
156
USERBOT_AUTHORIZATION_README.md
Normal file
156
USERBOT_AUTHORIZATION_README.md
Normal file
@@ -0,0 +1,156 @@
|
||||
# ⚠️ UserBot Authorization Required - IMPORTANT
|
||||
|
||||
## 🔐 What's Happening
|
||||
|
||||
You're seeing this message in UserBot logs:
|
||||
```
|
||||
❌ UserBot не авторизован. Требуется повторный вход.
|
||||
```
|
||||
|
||||
This is **normal and expected** ✅
|
||||
|
||||
---
|
||||
|
||||
## ✅ Quick Fix (3 minutes)
|
||||
|
||||
### Step 1: Open a terminal and run
|
||||
|
||||
```bash
|
||||
cd /home/trevor/dev/TG_autoposter
|
||||
|
||||
# Make the script executable
|
||||
chmod +x init_telethon_session.sh
|
||||
|
||||
# Run the interactive authorization
|
||||
./init_telethon_session.sh
|
||||
```
|
||||
|
||||
### Step 2: Follow the prompts
|
||||
|
||||
1. You'll see a message asking for SMS code:
|
||||
```
|
||||
📝 Enter the SMS code: [wait for SMS]
|
||||
```
|
||||
|
||||
2. **You'll receive an SMS** with a code to `+821056936103`
|
||||
|
||||
3. Enter the code and press Enter
|
||||
|
||||
4. If 2FA is enabled, enter your password
|
||||
|
||||
5. Done! ✅
|
||||
|
||||
---
|
||||
|
||||
## 📋 Alternative: Manual Authorization
|
||||
|
||||
If the script doesn't work, try this:
|
||||
|
||||
```bash
|
||||
# Run the Python script directly
|
||||
python3 init_telethon_session.py
|
||||
```
|
||||
|
||||
Or inside Docker:
|
||||
```bash
|
||||
docker-compose exec -it userbot python3 init_telethon_session.py
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🎯 What's Happening Behind the Scenes
|
||||
|
||||
1. **Telethon** (Telegram library) needs to authenticate with your user account
|
||||
2. Telegram sends an SMS code for verification
|
||||
3. The script saves this authentication session to `app/sessions/`
|
||||
4. Docker container uses this saved session to work as your UserBot
|
||||
5. No interaction needed after authorization - fully automated
|
||||
|
||||
---
|
||||
|
||||
## ✅ How to Know It Worked
|
||||
|
||||
After authorization, you'll see in logs:
|
||||
```
|
||||
✅ UserBot инициализирован: Your Name (@username)
|
||||
🔄 UserBot готов к обработке задач
|
||||
```
|
||||
|
||||
And the bot will show "🤖 UserBot" button in the menu.
|
||||
|
||||
---
|
||||
|
||||
## 🐛 Troubleshooting
|
||||
|
||||
### "SMS code not received"
|
||||
- Wait 30 seconds
|
||||
- Check spam folder
|
||||
- Make sure `TELETHON_PHONE` in `.env` is correct
|
||||
|
||||
### "Invalid API credentials"
|
||||
- Verify `TELETHON_API_ID` and `TELETHON_API_HASH` in `.env`
|
||||
- Get them from https://my.telegram.org
|
||||
|
||||
### "Session file already exists"
|
||||
- Delete old session: `rm -rf app/sessions/`
|
||||
- Run authorization again
|
||||
|
||||
### Script timeout
|
||||
- Re-run the script
|
||||
- Make sure you're connected to internet
|
||||
|
||||
---
|
||||
|
||||
## 📁 Files Created After Authorization
|
||||
|
||||
```
|
||||
app/sessions/
|
||||
├── userbot_session.session ← Main session file
|
||||
└── telethon_string_session.txt ← Backup
|
||||
```
|
||||
|
||||
These files are **encrypted** and contain your session data.
|
||||
|
||||
---
|
||||
|
||||
## 🚀 What to Do Next
|
||||
|
||||
After successful authorization:
|
||||
|
||||
1. ✅ Restart the bot: `docker-compose restart bot`
|
||||
|
||||
2. ✅ Test `/start` command to bot
|
||||
|
||||
3. ✅ Click "🤖 UserBot" button
|
||||
|
||||
4. ✅ Collect groups or members
|
||||
|
||||
---
|
||||
|
||||
## ⏱️ Expected Timeline
|
||||
|
||||
| Step | Time |
|
||||
|------|------|
|
||||
| Open terminal | 1 min |
|
||||
| Run script | 1 min |
|
||||
| Receive SMS | 0-2 min |
|
||||
| Enter code | 1 min |
|
||||
| Done | **~5 minutes** |
|
||||
|
||||
---
|
||||
|
||||
## 📞 Still Having Issues?
|
||||
|
||||
1. Check the [detailed guide](./TELETHON_AUTHORIZATION_GUIDE.md)
|
||||
2. Review logs: `docker-compose logs userbot -f`
|
||||
3. Verify `.env` has all TELETHON variables
|
||||
4. Make sure internet connection is stable
|
||||
|
||||
---
|
||||
|
||||
**Start authorization now:**
|
||||
```bash
|
||||
./init_telethon_session.sh
|
||||
```
|
||||
|
||||
✨ **You got this!**
|
||||
Reference in New Issue
Block a user