A sophisticated AI-powered Telegram bot for answering frequently asked questions with intelligent matching and response generation. The bot uses vector embeddings to find the most relevant FAQ entries and can generate contextual responses using OpenAI's language models.
- AI-Powered Responses: Uses OpenAI GPT models for intelligent question answering
- Vector Similarity Search: Leverages Pinecone for accurate FAQ matching using embeddings
- Telegram Integration: Fully functional Telegram bot with message handling
- Web Dashboard: Flask-based admin panel for managing FAQs
- Database Integration: Supabase backend for storing questions and answers
- Admin Authentication: Secure login system for FAQ management
- Multi-language Support: Supports Spanish language interactions
- Chat History: Maintains conversation context for better responses
- CSV Export: Download FAQ data in CSV format
- Real-time Updates: Live FAQ management with instant updates
- Python 3.10.16 or higher
- Telegram Bot Token (from @BotFather)
- OpenAI API Key
- Pinecone Account and API Key
- Supabase Account and API credentials
-
Clone the repository
git clone https://github.com/Hydra-Bolt/FAQBot.git cd FAQBot -
Create a virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Set up environment variables Create a
.envfile in the root directory with the following variables:# Telegram Bot Configuration BOT_TOKEN=your_telegram_bot_token ADMIN_ID=your_telegram_user_id # OpenAI Configuration OPENAI_API_KEY=your_openai_api_key # Pinecone Configuration PINECONE_API_KEY=your_pinecone_api_key # Supabase Configuration SUPABASE_URL=your_supabase_project_url SUPABASE_KEY=your_supabase_anon_key # Flask Configuration SECRET_KEY=your_flask_secret_key ADMIN_USERNAME=your_admin_username ADMIN_PASSWORD=your_admin_password PORT=5000
- Message @BotFather on Telegram
- Create a new bot with
/newbot - Copy the bot token to your
.envfile - Get your Telegram user ID by messaging @userinfobot
- Create an account at Pinecone
- Create a new index named
faq-bot - Use the following settings:
- Dimensions: 1536 (for OpenAI embeddings)
- Metric: cosine
- Copy your API key to the
.envfile
-
Create a project at Supabase
-
Create the following tables:
Questions table:
CREATE TABLE Questions ( id SERIAL PRIMARY KEY, question TEXT NOT NULL, answer_id INTEGER REFERENCES Answers(id) );
Answers table:
CREATE TABLE Answers ( id SERIAL PRIMARY KEY, answer TEXT NOT NULL );
-
Copy your project URL and anon key to the
.envfile
-
Run the Flask server
python server.py
-
Set up webhook for Telegram bot
curl -X POST "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/setWebhook" \ -H "Content-Type: application/json" \ -d '{"url": "https://your-domain.com/"}'
- Start a conversation with your bot on Telegram
- Send
/startto initialize the bot - Ask any question related to your FAQ content
- The bot will respond with relevant answers or generate responses based on available information
- Navigate to
http://localhost:5000/login - Login with your admin credentials
- Manage FAQs from the dashboard:
- View all FAQ entries
- Add new questions and answers
- Edit existing entries
- Delete outdated information
- Export data as CSV
- POST
/- Receives Telegram webhook messages
- GET/POST
/login- Admin login page - GET
/logout- Logout endpoint
- GET
/dashboard- FAQ management interface
- POST
/add- Add new FAQ entry - POST
/update- Update existing FAQ - POST
/delete- Delete FAQ entry - POST
/add_questions- Add questions to existing answer
- GET
/download- Export FAQ data as CSV
FAQBot/
├── server.py # Main Flask application
├── requirements.txt # Python dependencies
├── runtime.txt # Python version specification
├── faq.json # Sample FAQ data
├── .env # Environment variables (create this)
├── .gitignore # Git ignore rules
├── utils/ # Utility modules
│ ├── database.py # Supabase database operations
│ ├── faq_embeddings.py # Pinecone vector operations
│ ├── gen_from_embed.py # AI response generation
│ └── telegram_utils.py # Telegram bot utilities
└── templates/ # HTML templates
├── dashboard.html # Admin dashboard
└── login.html # Login page
- Via Web Dashboard: Use the admin interface to add questions and answers
- Via API: Send POST requests to
/addendpoint - Programmatically: Use the database utility functions
Modify the response generation logic in utils/gen_from_embed.py:
- Adjust the similarity threshold in
server.py(currently 0.93) - Customize the prompt templates
- Modify the chat history length (currently 10 messages)
- Update the welcome message in
server.py - Modify response templates in
utils/gen_from_embed.py - Update the dashboard templates if needed
To test the bot functionality:
-
Test Telegram Integration:
# Send a test message to your bot curl -X POST "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/sendMessage" \ -H "Content-Type: application/json" \ -d '{"chat_id": "<YOUR_CHAT_ID>", "text": "Test message"}'
-
Test Web Dashboard:
- Navigate to the login page
- Verify authentication works
- Test FAQ CRUD operations
-
Test API Endpoints:
# Test health check curl http://localhost:5000/
-
Install Heroku CLI and login
-
Create a new Heroku app:
heroku create your-faq-bot
-
Set environment variables:
heroku config:set BOT_TOKEN=your_bot_token heroku config:set OPENAI_API_KEY=your_openai_key # ... set all other environment variables -
Deploy:
git push heroku main
-
Set webhook:
curl -X POST "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/setWebhook" \ -H "Content-Type: application/json" \ -d '{"url": "https://your-faq-bot.herokuapp.com/"}'
Follow similar steps but use the respective platform's deployment guides and environment variable configuration methods.
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature
- Make your changes and commit:
git commit -m 'Add some amazing feature' - Push to the branch:
git push origin feature/amazing-feature
- Open a Pull Request
- Follow PEP 8 coding standards
- Add comments for complex logic
- Update documentation for new features
- Test your changes thoroughly
- Ensure environment variables are properly documented
- Add unit tests
- Implement rate limiting
- Add support for file uploads in FAQs
- Implement multi-language support
- Add analytics and usage statistics
- Improve error handling and logging
- Add Docker containerization
- Implement backup and restore functionality
This project is licensed under the MIT License - see the LICENSE file for details.
For questions, suggestions, or support:
- Project Repository: https://github.com/Hydra-Bolt/FAQBot
- Issues: GitHub Issues
- Telegram: Contact the bot admin for technical support
- OpenAI for providing the language models
- Pinecone for vector search capabilities
- Supabase for the database infrastructure
- LangChain for the AI framework
- Flask for the web framework
- Telegram Bot API for bot integration
⭐ Star this repository if you found it helpful!