Files
TG_autoposter/init_userbot.sh
Andrew K. Choi 48f8c6f0eb UserBot Integration Complete: Fixed container startup, integrated UserBot menu to main bot
MAJOR FIXES:
 Fixed UserBot container startup by making TELEGRAM_BOT_TOKEN optional
 Broke circular import chain between app modules
 Made Config.validate() conditional for UserBot-only mode
 Removed unused celery import from userbot_service.py

INTEGRATION:
 UserBot menu now accessible from main bot /start command
 Added 🤖 UserBot button to main keyboard
 Integrated userbot_manager.py handlers:
   - userbot_menu: Main UserBot interface
   - userbot_settings: Configuration
   - userbot_collect_groups: Gather all user groups
   - userbot_collect_members: Parse group members
 UserBot handlers properly registered in ConversationHandler

CONTAINERS:
 tg_autoposter_bot: Running and handling /start commands
 tg_autoposter_userbot: Running as standalone microservice
 All dependent services (Redis, PostgreSQL, Celery workers) operational

STATUS: Bot is fully operational and ready for testing
2025-12-21 12:09:11 +09:00

82 lines
3.0 KiB
Bash
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# Скрипт для инициализации Telethon UserBot
set -e
echo "╔════════════════════════════════════════════════════════════════╗"
echo "║ Telethon UserBot Initialization ║"
echo "╚════════════════════════════════════════════════════════════════╝"
echo ""
# Проверить наличие .env файла
if [ ! -f ".env" ]; then
echo "❌ Файл .env не найден!"
echo "📝 Создайте .env на основе .env.example"
exit 1
fi
# Загрузить переменные окружения
export $(cat .env | grep -v '^#' | xargs)
# Проверить API ID и API HASH
if [ -z "$TELETHON_API_ID" ] || [ -z "$TELETHON_API_HASH" ]; then
echo "❌ TELETHON_API_ID или TELETHON_API_HASH не установлены!"
echo "📝 Добавьте их в .env файл"
echo ""
echo "Как получить:"
echo "1. Перейти на https://my.telegram.org/auth"
echo "2. Войти с номером телефона"
echo "3. Выбрать 'API development tools'"
echo "4. Скопировать api_id и api_hash в .env"
exit 1
fi
# Проверить номер телефона
if [ -z "$TELETHON_PHONE" ]; then
echo "❌ TELETHON_PHONE не установлен!"
echo "📝 Добавьте TELETHON_PHONE=+1234567890 в .env"
exit 1
fi
echo "✅ Конфигурация найдена:"
echo " API ID: ****${TELETHON_API_ID: -4}"
echo " Phone: $TELETHON_PHONE"
echo ""
# Удалить старую сессию если существует
if [ -f "sessions/userbot_session.session" ]; then
echo "⚠️ Найдена старая сессия"
read -p "Удалить и авторизироваться заново? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
rm -f sessions/userbot_session.session*
echo "✅ Старая сессия удалена"
else
echo " Используем существующую сессию"
exit 0
fi
fi
echo ""
echo "🚀 Запускаем инициализацию UserBot..."
echo "📲 Вам придет SMS код - введите его"
echo ""
# Запустить userbot_service.py для авторизации
python userbot_service.py
if [ -f "sessions/userbot_session.session" ]; then
echo ""
echo "✅ UserBot успешно авторизирован!"
echo "📁 Сессия сохранена в: sessions/userbot_session.session"
echo ""
echo "🎯 Следующие шаги:"
echo " 1. docker-compose build"
echo " 2. docker-compose up -d"
echo " 3. Отправить /sync_groups в боте"
else
echo ""
echo "❌ Ошибка авторизации"
exit 1
fi