This project provides a Telegram bot for job seekers to manage their profiles, browse jobs, and apply, coupled with a Flask-based web administration portal for recruiters/admins to manage job postings, view applications, and communicate with users.
- Overview
- Features Implemented
- Features Not Implemented (and Why)
- Project Structure
- Setup Instructions
- Running the Applications
- Usage Guide
- Security Considerations
- Troubleshooting
This system is designed to streamline the job application process for job seekers through a Telegram bot and provide a robust management interface for administrators.
Key Components:
- Telegram Bot (
tg_bot/bot.py): Allows users to create profiles, browse active job listings, apply with pre-filled information, and track application status. Supports resume file uploads. - Flask Web Portal (
web/app.py): A secure web interface for administrators to post/manage jobs, view detailed applications, review user profiles, and send direct messages to Telegram users. - SQLite Database (
db/jobs_bot.db): A single database file shared by both the bot and the web portal for data persistence.
Here's a detailed list of features that have been implemented in this project:
- User Profile Management:
- Users can create and update their professional profiles (full name, email, phone, experience, skills, resume text).
- Email Validation: Basic regex validation for email addresses during profile creation.
- Resume File Upload: Users can upload their resume as a document (PDF, DOCX, etc.) during profile creation. The bot stores the Telegram
file_id. - Resume Forwarding to Admin Group: Uploaded resume files are automatically forwarded to a configured Telegram admin group/channel for easy access by recruiters.
- Job Browse & Application:
- Users can view active job listings via an inline keyboard menu.
- One-click application using their saved profile data.
- Unique Application ID: Each application is assigned a short, unique public ID (e.g.,
A1B2C3D4) which is displayed to the user upon successful application.
- Application Tracking: Users can view a list of their submitted applications with their current status and unique application ID.
- Help & Navigation: Clear menu buttons and a
/helpcommand for guidance.
- Admin Authentication: Secure login for administrators to access the portal.
- Credentials managed via
.envfor security.
- Credentials managed via
- Job Management:
- Admins can post new job roles with detailed descriptions, requirements, location, and salary.
- Admins can edit existing job postings.
- Jobs can be marked as active/inactive.
- Job Deactivation/Deletion Logic: If a job has existing applications, it is deactivated instead of deleted to preserve historical application data.
- Job Filtering: Filter jobs by active/inactive status and search by title, description, or location.
- Application Management:
- View a list of all job applications.
- Application Filtering: Filter applications by status (pending, accepted, rejected, interviewed) and by specific job. Also, search applicants by name, email, or Telegram username.
- View detailed application information, including applicant profile and job details.
- Update application status (pending, accepted, rejected, interviewed).
- Direct Contact Buttons: "Send Email" and "Call Phone" buttons on the "View Application" page to contact applicants directly.
- Download Resume: Direct download link for uploaded resume files from Telegram, accessible from the web portal.
- User Management:
- View a list of all registered Telegram users.
- User Filtering: Search users by full name, Telegram username, or email.
- View detailed user profiles, including their submitted applications.
- Direct Telegram Messaging: A modal popup on both "View Application" and "View User" pages allows admins to send direct Telegram messages to users via the bot.
- Dashboard: Provides an overview of key statistics (total jobs, active jobs, total users, total applications, pending applications, recent applications, popular jobs).
- Environment Variable Integration: All sensitive keys and configurations (Flask secret key, admin credentials, bot token, admin group ID, debug mode) are loaded from a
.envfile.
The following features were discussed but not implemented in this iteration due to their complexity and scope, which would require significant architectural changes:
- Custom User Info Definition (without code changes):
- Why not implemented: This would require dynamic form generation, a flexible database schema (e.g., EAV model or JSON fields), and bot logic capable of interpreting and validating user input based on a runtime-defined schema. This goes beyond the scope of a basic bot and web portal.
- Selective Profile Updates (Bot):
- Why not implemented: Allowing users to update only specific fields (e.g., just their email) without re-entering all information requires a more complex, non-linear conversation flow within the Telegram bot. The current implementation uses a sequential conversation handler.
project\_root/
βββ tg\_bot/
β βββ bot.py \# Telegram bot application logic
βββ web/
β βββ app.py \# Flask web portal application logic
β βββ templates/ \# Jinja2 HTML templates for the web portal
β βββ base.html
β βββ login.html
β βββ dashboard.html
β βββ jobs.html
β βββ add\_job.html
β βββ edit\_job.html
β βββ applications.html
β βββ view\_application.html
β βββ users.html
β βββ view\_user.html
βββ env/
β βββ .env \# Environment variables (secrets, config) - created from .env.sample
β βββ .env.sample \# Template for .env file
βββ db/
β βββ jobs\_bot.db \# SQLite database file (created automatically)
βββ docs/ \# All documentation files are now here
β βββ README.md \# This documentation file
β βββ docs.md \# Original documentation provided by the user
βββ .gitignore \# Specifies files/directories to ignore in Git
βββ requirements.txt \# Python package dependencies
- Python 3.8+: Ensure Python is installed on your system.
- pip: Python's package installer (usually comes with Python).
-
Create
.envfile from sample: In theproject_root/env/directory, copy the.env.samplefile and rename the copy to.env. -
Populate
.env: Open the newly created.envfile and fill in the placeholder values. Replace placeholder values with your actual secrets and configurations.# web portal config FLASK_SECRET_KEY='your_very_strong_and_unique_secret_key_here' # generate using this command `openssl rand -hex 32` FALLBACK_SECRET_KEY='' # backup secret key (optional, can be left empty) ADMIN_USERNAME='' # admin username for web portal (e.g., 'admin') ADMIN_PASSWORD='' # admin pass for web portal (e.g., 'admin123') FLASK_DEBUG='True' # Set to 'True' for development, 'False' for production # bot config BOT_TOKEN='' # Paste your actual token from BotFather here TELEGRAM_ADMIN_GROUP_ID='' # telegram group id for resume forwarding (e.g., '-1234567890123') -
Generate
FLASK_SECRET_KEY:- Open your terminal/command prompt.
- Run
python -c "import secrets; print(secrets.token_hex(32))" - Copy the generated 64-character hexadecimal string and paste it as the
FLASK_SECRET_KEYvalue in your.envfile. (Alternatively,openssl rand -hex 32works too).
-
Get
BOT_TOKEN:- Message
@BotFatheron Telegram. - Send
/newbotand follow the instructions to create your bot. - BotFather will provide you with an API token. Copy this token and paste it as the
BOT_TOKENvalue in your.envfile.
- Message
-
Get
TELEGRAM_ADMIN_GROUP_ID:- Create a private Telegram group.
- Add your newly created bot to this group.
- Send any message to the group (e.g., "Hello").
- In your web browser, go to
https://api.telegram.org/botYOUR_BOT_TOKEN/getUpdates(replaceYOUR_BOT_TOKENwith your bot's actual token). - Look for the
chatobject in the JSON response. Theidfield within thischatobject is yourTELEGRAM_ADMIN_GROUP_ID. It will be a negative number (e.g.,-1001234567890). Copy this ID and paste it into your.envfile.
- Navigate to your
project_rootdirectory in your terminal:cd path/to/your/project_root - Install the required Python packages:
pip install -r requirements.txt
The jobs_bot.db file will be automatically created in the project_root/db/ directory when either the bot or the web portal is run for the first time.
Important: If you have run the project before and are updating from an older version, the database schema might be outdated.
- For development (recommended): Delete the
jobs_bot.dbfile fromproject_root/db/. It will be recreated with the new schema and sample data on the next run. (You will lose old user/application data). - For production (if retaining data): You would need to perform a database migration using
ALTER TABLEstatements to add the new columns (public_application_idtoapplicationsandresume_file_idtousers). This is outside the scope of thisREADME.
You will need two separate terminal windows/tabs to run both the bot and the web portal concurrently.
- Open a new terminal.
- Navigate to the
tg_botdirectory:cd path/to/your/project_root/tg_bot - Run the bot:
You should see
python bot.py
π€ Jobs Bot is starting...in your terminal. Keep this terminal open.
- Open another new terminal.
- Navigate to the
webdirectory:cd path/to/your/project_root/web - Run the Flask app:
You should see output indicating that the Flask development server is running, typically on
python app.py
http://127.0.0.1:5000/. Keep this terminal open.
- Start the Bot: Go to Telegram, search for your bot's username, and send the
/startcommand. - Create/Update Profile: Click "π Create/Update Profile". Follow the prompts to enter your details. You can send your resume as text or upload a document (PDF, DOCX, etc.) at the "Resume" step.
- View Jobs: Click "πΌ View Jobs" to see available job positions. Click on any job to view details.
- Apply for Job: On a job details page, if you have a profile, click "β Apply Now". You will receive a unique Application ID and status.
- My Applications: Click "π My Applications" to see a list of all your submitted applications with their status and Application IDs.
- Help: Click "βΉοΈ Help" or send
/helpfor bot usage instructions.
- Access Portal: Open your web browser and go to
http://127.0.0.1:5000/. - Login: Use the admin credentials configured in your
.envfile (default:admin/admin123). - Dashboard: View key statistics, recent applications, and popular jobs.
- Manage Jobs:
- View Jobs: See all job postings. Use the filters to search by title/description/location or status (active/inactive).
- Add New Job: Click "Add New Job" to create a new posting.
- Edit Job: Click the "Edit" icon (pencil) next to a job to modify its details or activate/deactivate it.
- Delete Job: Click the "Delete" icon (trash can). If the job has applications, it will be deactivated instead of deleted.
- Applications:
- View Applications: See a list of all job applications. Use filters to narrow down by status, job, or search for applicants by name, email, or Telegram username.
- View Details: Click "View" next to an application to see the applicant's full profile, job details, and update the application status.
- Contact Applicant: On the "View Application" page, use the "Send Email", "Call Phone", or "Send Telegram Message" buttons to contact the applicant.
- Download Resume: If a resume file was uploaded, a "Download Resume File" button will appear, allowing you to download it directly from Telegram via the portal.
- Users:
- View Users: See a list of all registered Telegram users. Use the search filter to find users by name, email, or Telegram username.
- View Profile: Click the "Eye" icon next to a user to see their detailed profile and a list of their applications.
- Send Telegram Message: On the "View User" page, use the "Send Telegram Message" button to send a direct message to that user via your bot.
- Change Default Credentials: Immediately change the
ADMIN_USERNAMEandADMIN_PASSWORDin yourproject_root/env/.envfile from their defaults. - Strong
FLASK_SECRET_KEY: Ensure yourFLASK_SECRET_KEYis long, random, and kept secret. Never share it or commit it to version control. - Production Deployment: The Flask development server (
app.run(debug=True)) is not suitable for production. For a production deployment, you must use a production-ready WSGI server like Gunicorn or uWSGI, and disableFLASK_DEBUG(FLASK_DEBUG='False'in.env). - Database Security: For production, consider moving from SQLite to a more robust database (e.g., PostgreSQL) and securing its access credentials.
- Bot Token Security: Keep your
BOT_TOKENstrictly confidential. - Input Sanitization: While some basic validation is in place, comprehensive input sanitization is critical for any public-facing application to prevent SQL injection, XSS, etc.
OSError: File not foundfor.envorjobs_bot.db:- Ensure your
.envfile is inproject_root/env/andjobs_bot.db(if it exists) is inproject_root/db/. - Verify the paths in
tg_bot/bot.pyandweb/app.pyfor loading.envand connecting tojobs_bot.dbare correct as per the latest code. - Make sure you are running the scripts from the correct directories (
tg_bot/forbot.pyandweb/forapp.py).
- Ensure your
sqlite3.OperationalError: unable to open database file:- This often means the database file doesn't exist or there are permission issues.
- If it's the first run or you want to reset data, delete
project_root/db/jobs_bot.dband restart. - Check file permissions for the
dbdirectory andjobs_bot.dbfile.
- Telegram Bot not responding:
- Check your
BOT_TOKENin.envfor typos. - Ensure the
bot.pyscript is running in its terminal. - Check the terminal where
bot.pyis running for any error messages. - Verify your internet connection.
- Check your
- Web Portal not accessible:
- Ensure the
app.pyscript is running in its terminal. - Check the terminal where
app.pyis running for any error messages. - Verify you are accessing the correct URL (
http://127.0.0.1:5000/).
- Ensure the
- Resume forwarding not working:
- Double-check that
TELEGRAM_ADMIN_GROUP_IDis correctly set in your.envfile (remember it's a negative number for groups/channels). - Ensure your bot has been added to the Telegram group and has permission to send messages.
- Check the bot's terminal for any error messages related to
send_document.
- Double-check that
TemplateSyntaxErrorin HTML templates:- This usually means there's a typo or incorrect Jinja2 syntax in your HTML.
- Carefully compare your HTML files with the provided code in the immersives, paying close attention to
{% ... %}and{{ ... }}blocks, especially aroundifstatements and loops. A single misplaced character can cause this.