This is the backend for a Todo application, built with Node.js, Express, and Supabase.
- Node.js (v14 or later)
- npm or yarn
- Supabase account
- Clone this repository
- Install dependencies:
cd backend
npm install- Create a
.envfile in the root directory with the following variables:
PORT=3000
SUPABASE_URL=your_supabase_url
SUPABASE_KEY=your_supabase_api_key
JWT_SECRET=your_jwt_secret
TELEGRAM_BOT_TOKEN=your_telegram_bot_token
You need to create the following tables in your Supabase project:
- id (uuid, primary key)
- username (text, unique)
- name (text)
- email (text, unique)
- phone (text)
- password (text)
- profile_picture (text)
- created_at (timestamp with time zone)
- updated_at (timestamp with time zone)
- id (uuid, primary key)
- title (text)
- description (text)
- is_completed (boolean)
- priority (integer)
- deadline (timestamp with time zone)
- user_id (uuid, foreign key to users.id)
- created_at (timestamp with time zone)
- updated_at (timestamp with time zone)
# Development mode with auto-restart
npm run dev
# Production mode
npm start- POST
/api/auth/register - Body:
{ name, email, phone, username, password, profile_picture } - Response:
{ message: 'User registered successfully' }
- POST
/api/auth/login - Body:
{ username, password } - Response:
{ access_token, user: { id, username, name, email } }
- GET
/api/todos - Headers:
Authorization: Bearer {token} - Response: Array of todo objects
- GET
/api/todos/:id - Headers:
Authorization: Bearer {token} - Response: Todo object
- POST
/api/todos - Headers:
Authorization: Bearer {token} - Body:
{ title, description, deadline, priority } - Response:
{ message: 'Todo created successfully', todo: {...} }
- PUT
/api/todos/:id - Headers:
Authorization: Bearer {token} - Body:
{ title, description, is_completed, priority, deadline } - Response:
{ message: 'Todo updated successfully' }
- DELETE
/api/todos/:id - Headers:
Authorization: Bearer {token} - Response:
{ message: 'Todo deleted successfully' }
- GET
/api/users/profile - Headers:
Authorization: Bearer {token} - Response:
{ user: {...}, statistics: { totalTodos, completedTodos, efficiency } }
- PUT
/api/users/profile - Headers:
Authorization: Bearer {token} - Body:
{ name, email, phone, profile_picture } - Response:
{ message: 'Profile updated successfully' }
- PUT
/api/users/change-password - Headers:
Authorization: Bearer {token} - Body:
{ currentPassword, newPassword } - Response:
{ message: 'Password changed successfully' }
This backend includes integration with Telegram, allowing users to manage their todos through a Telegram bot.
- Create a bot on Telegram by talking to @BotFather
- Use the
/newbotcommand and follow the instructions - Copy the API token provided by BotFather
- Add the token to your
.envfile:
TELEGRAM_BOT_TOKEN=your_telegram_bot_token
Run the necessary SQL scripts from src/integrations/telegram/setup.sql in your Supabase SQL editor to create the required tables.
This backend now includes AI-powered natural language processing for managing todos through Telegram.
- Get an API key from OpenAI
- Add the API key to your
.envfile:
OPENAI_API_KEY=your_openai_api_key
- Link your account with the Telegram bot
- Type
/aito activate AI mode - Send natural language requests like "Add buying groceries to my todos" or "Show me all my high priority tasks"
See AI_FEATURES.md for more detailed instructions and examples of how to use natural language to manage your todos.
In production, you need to set up a webhook for your bot:
- Deploy your application to a server with HTTPS
- Set the webhook URL using:
https://api.telegram.org/bot{YOUR_BOT_TOKEN}/setWebhook?url={YOUR_API_URL}/api/telegram/webhook
For local development, the bot uses polling mode. Just start your server with:
npm run dev- Users start a chat with your Telegram bot
- The bot provides a linking code
- Users enter this code in your frontend app
- The backend verifies the code and links the Telegram chat to the user account
/start- Start the bot and get a linking code/help- Show available commands/list- List all your todos/add <text>- Add a new todo/done <number>- Mark a todo as complete/delete <number>- Delete a todo/show <number>- Show a specific todo