A powerful Telegram bot designed to instantly summarize articles and answer questions about their content using advanced AI. Let artificial intelligence handle long reads for you!
- π Article Summaries - Send a link to any article and receive a concise summary.
- π¬ Post Analysis - Forward any Telegram post to generate a quick summary.
- π Text Processing - Send long texts (>500 characters) to be summarized instantly.
- β Q&A Mode - Ask questions about the read article and get accurate answers based on its context.
- π§ Contextual Memory - The bot remembers previous questions and answers during the conversation.
- π Multilingual Interface - Fully supports both English and Ukrainian languages.
- πΎ Persistent Storage - Securely stores user preferences and session data in a Supabase PostgreSQL database.
- FastAPI - High-performance web framework for webhook handling.
- SQLAlchemy - Robust ORM for seamless database interactions.
- Supabase (PostgreSQL) - Scalable cloud database solution.
- Cerebras AI API - Ultra-fast LLM processing (powered by
llama3.1-8b) for generating summaries and answers. - BeautifulSoup4 - Efficient HTML parsing and text extraction.
- Telegram Bot API - Seamless integration with the Telegram ecosystem.
fastapi>=0.104.0
sqlalchemy>=2.0.0
psycopg2-binary>=2.9.9
requests>=2.31.0
beautifulsoup4>=4.12.0Ensure the following files are present in the root directory:
api/index.py- Core bot logic (Vercel serverless function endpoint)requirements.txt- Python dependenciesvercel.json- Vercel configuration file
{
"version": 2,
"builds": [
{
"src": "api/index.py",
"use": "@vercel/python"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "api/index.py"
}
]
}- Push your code to a GitHub repository.
- Log in to Vercel and click New Project.
- Import your GitHub repository.
- Go to Settings > Environment Variables and add the following keys:
TELEGRAM_TOKEN=your_telegram_bot_tokenCEREBRAS_API_KEY=your_cerebras_api_keyDATABASE_URL=postgresql://user:password@host:port/databaseACCESS_CODE=your_secret_access_code
- Click Deploy.
Once deployed, run this in your terminal to connect the Telegram bot to Vercel:
curl -X POST "https://api.telegram.org/bot<YOUR_TELEGRAM_TOKEN>/setWebhook" \
-H "Content-Type: application/json" \
-d '{"url": "https://your-project.vercel.app/webhook"}'git clone <repository-url>
cd Sum_AIbotpip install -r requirements.txtCreate a .env file in the root directory:
TELEGRAM_TOKEN=your_telegram_bot_token
CEREBRAS_API_KEY=your_cerebras_api_key
DATABASE_URL=postgresql://user:password@host:port/database
ACCESS_CODE=your_secret_access_codeuvicorn api.index:app --reload --port 8000Note: For local Telegram webhooks, you can use ngrok to expose port 8000.
- Register on Supabase.
- Create a new project and copy the
DATABASE_URLfrom the database settings. - The server application will automatically create the required
user_datatable upon its first database connection:
CREATE TABLE user_data (
user_id BIGINT PRIMARY KEY,
language TEXT DEFAULT 'ua',
article_text TEXT,
conversation TEXT,
article_url TEXT,
has_unlimited BOOLEAN DEFAULT FALSE,
code_verified BOOLEAN DEFAULT FALSE,
articles_used INTEGER DEFAULT 0,
last_reset TIMESTAMP
);/start- Start the bot and select a language./help- View instructions and available actions.
- You share a link to a news article.
- Bot: π Processing article...
- Bot: π Summary: [concise summary generated by AI]
- You ask: "What are the main causes mentioned in the text?"
- Bot: π‘ The main causes are...
- β YouTube / Social Media Platforms: Meta (Facebook/Instagram), Notion, and YouTube links are currently blocked due to technical limitations regarding automated text parsing.
- Workaround: Copy the text manually and paste it into the chat.
- β±οΈ Vercel Timeout: Free tier Vercel functions time out after 10 seconds. Heavily loaded prompts or enormous articles might reach this limit.
- Keep your
.envtokens completely private and never commit them to the repository. - Rely on environment variables through the Vercel dashboard.
- The bot utilizes PostgreSQL connection pooling and handles HTML escaping thoroughly.
Designed and developed by Gearberry β available for custom ecosystem architecture and high-performance web development. Feel free to connect with me:
β Enjoying the project? Please consider starring the repository!