A powerful AI image generation web application that works as a Telegram Mini App or standalone web app with Google OAuth authentication for premium features.
- 🔐 Multi-Platform Authentication - Telegram Mini App + Google OAuth support
- 🎨 AI Image Generation - Multiple models (Flux, DALL-E 3) with style options
- ✨ Prompt Enhancement - AI-powered prompt improvement
- 👤 User Management - Premium features and permission-based access
- 💎 Google Premium Access - Automatic premium features for Google users
- 🌙 Theme Support - Dark/Light modes that sync with Telegram
- 📱 Mobile Responsive - Optimized for mobile and desktop
- 🎯 Real-time Generation - Progress tracking and status updates
- Telegram Bot Token - Get from @BotFather (for Telegram integration)
- Google OAuth Credentials - Get from Google Cloud Console (for browser access)
- Pollinations API Key - Get from Pollinations.ai
- Python 3.8+ - For local development
-
Clone and navigate to webapp directory:
cd webapp -
Install dependencies:
pip install -r requirements.txt
-
Configure environment:
cp config.example.py config.py # Edit config.py with your API keys -
Set environment variables:
export BOT_TOKEN="your_telegram_bot_token" export POLLINATIONS_KEY="your_pollinations_api_key" export FLASK_SECRET_KEY="your_secure_secret_key"
-
Run the application:
python app.py
| Variable | Description | Required |
|---|---|---|
BOT_TOKEN | Telegram Bot Token from @BotFather | ⚡ For Telegram |
GOOGLE_CLIENT_ID | Google OAuth Client ID | ⚡ For Google Auth |
GOOGLE_CLIENT_SECRET | Google OAuth Client Secret | ⚡ For Google Auth |
POLLINATIONS_KEY | API key for image generation | ✅ Yes |
FLASK_SECRET_KEY | Secret key for session management | ✅ Yes |
TELEGRAM_MINI_APP_REQUIRED | Enable/disable Telegram auth | ❌ No (default: True) |
SESSION_TIMEOUT | Session timeout in seconds | ❌ No (default: 86400) |
FLASK_DEBUG | Enable debug mode | ❌ No (default: False) |
# config.py # Telegram Integration (optional) BOT_TOKEN = "1234567890:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghi" # Google OAuth (optional - for browser access) GOOGLE_CLIENT_ID = "your_google_client_id.apps.googleusercontent.com" GOOGLE_CLIENT_SECRET = "your_google_client_secret" # Required for all setups POLLINATIONS_KEY = "your_pollinations_api_key" FLASK_SECRET_KEY = "your-cryptographically-secure-secret-key" # Optional settings TELEGRAM_MINI_APP_REQUIRED = True SESSION_TIMEOUT = 24 * 60 * 60 # 24 hours MAX_IMAGES_PER_REQUEST = 4- Message @BotFather on Telegram
- Send
/newbotand follow instructions - Save your bot token securely
- Send
/setmenubuttonto @BotFather - Select your bot
- Provide your webapp URL (e.g.,
https://your-domain.com) - Set button text (e.g., "🎨 Generate Images")
/start - Start the bot /help - Get help information /settings - Open image generator - Open your bot in Telegram
- Tap the menu button or send
/start - The webapp should open with authentication
- Go to Google Cloud Console
- Create a new project or select existing one
- Enable the Google+ API or People API
- Navigate to APIs & Services → Credentials
- Click Create Credentials → OAuth 2.0 Client IDs
- Choose Web application as application type
- Add your domains to Authorized origins:
https://yourdomain.com http://localhost:5000 (for development) - Add callback URLs to Authorized redirect URIs:
https://yourdomain.com/api/auth/google/callback http://localhost:5000/api/auth/google/callback
export GOOGLE_CLIENT_ID="your_client_id.apps.googleusercontent.com" export GOOGLE_CLIENT_SECRET="your_client_secret"- Open your webapp directly in browser (not through Telegram)
- You should see a "Login with Google" option
- After login, users automatically get premium features
-
Fork this repository
-
Set environment variables in Vercel dashboard:
BOT_TOKEN=your_telegram_bot_token GOOGLE_CLIENT_ID=your_google_client_id.apps.googleusercontent.com GOOGLE_CLIENT_SECRET=your_google_client_secret POLLINATIONS_KEY=your_pollinations_api_key FLASK_SECRET_KEY=your_secure_secret_key -
Update bot settings in @BotFather with your Vercel URL
-
Create Heroku app:
heroku create your-app-name
-
Set environment variables:
heroku config:set BOT_TOKEN=your_telegram_bot_token heroku config:set GOOGLE_CLIENT_ID=your_google_client_id.apps.googleusercontent.com heroku config:set GOOGLE_CLIENT_SECRET=your_google_client_secret heroku config:set POLLINATIONS_KEY=your_pollinations_api_key heroku config:set FLASK_SECRET_KEY=your_secure_secret_key
-
Deploy:
git subtree push --prefix webapp heroku main
-
Build Docker image:
docker build -t advai-webapp . -
Run container:
docker run -p 5000:5000 \ -e BOT_TOKEN=your_telegram_bot_token \ -e GOOGLE_CLIENT_ID=your_google_client_id.apps.googleusercontent.com \ -e GOOGLE_CLIENT_SECRET=your_google_client_secret \ -e POLLINATIONS_KEY=your_pollinations_api_key \ -e FLASK_SECRET_KEY=your_secure_secret_key \ advai-webapp
Telegram Users:
- Telegram Verification - Validates initData from Telegram WebApp
- Hash Validation - Ensures data integrity using HMAC-SHA256
Google Users:
- OAuth 2.0 Flow - Secure Google authentication
- ID Token Validation - Verifies Google JWT tokens
- Automatic Premium - Google users get premium features
All Users:
- Session Management - Secure session handling with timeout
- Permission System - Role-based access to features
- ✅ HTTPS required for production
- ✅ Secure session cookies
- ✅ CSRF protection via Telegram authentication
- ✅ Rate limiting on generation endpoints
- ✅ Input validation and sanitization
The app automatically adapts to Telegram's theme:
- 🌙 Dark Mode - For dark Telegram themes
- ☀️ Light Mode - For light Telegram themes
# Example permission system { 'can_generate_images': True, 'can_enhance_prompts': True, 'can_access_premium_models': user.is_premium, 'max_images_per_request': 4 if user.is_premium else 2 }webapp/ ├── app.py # Main Flask application ├── telegram_auth.py # Telegram authentication module ├── config.py # Configuration file ├── requirements.txt # Python dependencies ├── static/ │ ├── css/style.css # Styles with Telegram theme support │ └── js/app.js # Frontend with Telegram WebApp integration ├── index.html # Main webpage └── vercel.json # Vercel deployment config -
Enable debug mode:
export FLASK_DEBUG=True -
Disable Telegram auth for testing:
# config.py TELEGRAM_MINI_APP_REQUIRED = False
-
Run with auto-reload:
python app.py
| Endpoint | Method | Description |
|---|---|---|
/api/auth/config | GET | Get authentication configuration |
/api/auth/telegram | POST | Authenticate with Telegram |
/api/auth/google | GET | Initiate Google OAuth flow |
/api/auth/google/callback | GET | Google OAuth callback |
/api/auth/google/token | POST | Authenticate with Google ID token |
/api/auth/status | GET | Check authentication status |
/api/auth/logout | POST | Logout user |
/api/generate | POST | Generate images |
/api/enhance-prompt | POST | Enhance text prompt |
/api/health | GET | Health check |
Q: Authentication fails with "No initialization data" A: Ensure the app is opened through Telegram, not directly in browser
Q: Images fail to generate A: Check your Pollinations API key and ensure it's valid
Q: Session expires quickly A: Increase SESSION_TIMEOUT in configuration
Q: Mini App doesn't open A: Verify your webapp URL is correct in @BotFather settings
Q: Google login button doesn't appear A: Check if GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET are configured
Q: Google authentication fails A: Ensure your domain is added to authorized origins in Google Cloud Console
Q: "Google authentication not available" error A: Install Google auth dependencies: pip install google-auth google-auth-oauthlib
Enable debug logging:
import logging logging.basicConfig(level=logging.DEBUG)Use browser developer tools to check:
- Telegram WebApp object is available
- initData is being sent correctly
- Authentication API responses
This project is licensed under the MIT License - see the LICENSE file for details.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- 📧 Issues: GitHub Issues
- 💬 Telegram: @TechyCSR
- 🤖 Bot: @AdvChatGptBot
Made with ❤️ by @TechyCSR