This is a customizable Telegram bot built using the python-telegram-bot library and integrated with OpenAI's GPT-4 for intelligent product consultations. It includes features like forced channel membership checks, inline and persistent keyboards, admin notifications for consultation requests, and AI-powered responses.
- Forced Channel Join: Users must join a specified channel to interact with the bot.
- Inline Buttons: Quick links to view products or request phone consultations.
- Persistent Keyboard: Always-visible buttons for consultations, products, and help.
- Admin Notifications: Forwards user contact details to an admin for phone consultations.
- AI Consultation: Uses OpenAI to provide personalized product recommendations based on user queries.
- Logging: Basic logging for errors and info to aid debugging.
- Error Handling: Improved try-except blocks to handle API failures gracefully.
- Python 3.6+
- Install dependencies:
pip install python-telegram-bot openai
-
Tokens and IDs:
- Replace
TELEGRAM_BOT_TOKENwith your bot token from BotFather. - Replace
OPENAI_API_KEYwith your OpenAI API key. - Set
ADMIN_IDto your Telegram user ID (for receiving notifications). - Set
FORCE_JOIN_CHANNELto your channel username (e.g.,@my_channel).
- Replace
-
Customization:
- Update URLs in buttons and messages to point to your website or channel.
- Modify the OpenAI system prompt to fit your product domain (e.g., laptops, gadgets).
- Add more handlers or buttons as needed for expansion.
-
Running the Bot:
python your_bot_script.py
The bot will start polling and log "✅ Bot is running."
- Database Integration: Add SQLite or MongoDB to store user queries or consultation logs.
- More Commands: Implement
/help,/products, or custom commands. - Rate Limiting: Prevent spam by limiting API calls per user.
- Multi-Language Support: Detect user language and respond accordingly.
- Webhooks: Switch from polling to webhooks for production deployment.
- This bot is designed to be general-purpose. Adapt the AI prompt and buttons for any e-commerce or consultation service.
- Ensure compliance with Telegram's and OpenAI's terms of service.
- For production, use environment variables for sensitive keys (e.g., via
os.getenv).
If you encounter issues, check the logs for details. Contributions welcome! 🚀