MentorQ is a simple Telegram bot that lets students send questions and mentors/teachers answer them directly in Telegram.
- Students send a question and confirm before it is submitted.
- Mentors receive a formatted message with the question and user ID.
- Mentors reply by using Telegram's reply feature; the answer is delivered back to the student.
Author: Dashweb.agency
License: MIT
/startcommand with a clear welcome message.- Send a free‑text question.
- Confirmation step with inline buttons:
✅ Send question❌ Cancel
- Ability to start a new Q&A session after each question.
- Receive each question with:
- student username
- numeric Telegram user ID
- timestamp (UTC)
- full question text
- Answer by replying to the question message in Telegram:
- The bot extracts the user ID from the message.
- Sends the reply back to the student.
- Confirms delivery to the mentor.
- Stateless HTTP endpoint (
bot.php) suitable for Telegram webhooks. - Lightweight JSON storage for user state and pending questions:
user_states.jsonuser_questions.json
- Optional logging to
bot.log.
mentorq-bot/
├── bot.php # Main bot logic (webhook endpoint)
├── config.example.php # Example configuration (copy to config.php)
├── config.php # Real configuration (ignored in git)
├── setup_webhook.php # CLI script to set/check webhook
├── user_states.json # Runtime state storage (ignored in git)
├── user_questions.json # Runtime question storage (ignored in git)
├── .gitignore # Ignore secrets and runtime files
├── LICENSE # MIT license
└── README.md # This file
- PHP 7.4+ with
allow_url_fopenor cURL‑like HTTP access. - A publicly accessible HTTPS endpoint for Telegram webhook:
- e.g.
https://yourdomain.com/mentorq-bot/bot.php
- e.g.
-
Create a bot in Telegram
- Open
@BotFather - Send
/newbot - Choose a name and username (for example
MentorQBot) - Copy the bot token (
BOT_TOKEN)
- Open
-
Find your mentor (admin) chat ID
- Open
@userinfobotor similar bot. - Send any message.
- Note the numeric
user_id(this will beADMIN_CHAT_ID).
- Open
-
Prepare configuration
-
Copy
config.example.phptoconfig.php:cp config.example.php config.php
-
Edit
config.phpand set:define('BOT_TOKEN', '123456:ABC...'); // from BotFather define('ADMIN_CHAT_ID', '123456789'); // your numeric Telegram ID define('BOT_USERNAME', 'MentorQBot'); // without @ define('WEBHOOK_URL', 'https://yourdomain.com/mentorq-bot/bot.php');
-
-
Upload files to your server
- Upload the entire
mentorq-botfolder to your web server. - Ensure
bot.phpis reachable at the URL you set inWEBHOOK_URL.
- Upload the entire
-
Set the webhook
-
Run the setup script from the command line:
php setup_webhook.php
-
This will:
- show current webhook info
- set a new webhook to
WEBHOOK_URL - show final webhook info
-
-
Test the bot
- Open
https://t.me/YourBotUsernamein Telegram. - Send
/startand follow the instructions.
- Open
bot.phpreceives updates from Telegram (via webhook).- If a student sends
/start:- the bot sends a welcome message
- sets the user state to
waiting_for_question.
- When the student sends a question:
- the bot stores it in
user_questions.json - asks for confirmation using inline buttons.
- the bot stores it in
- On confirmation:
- the bot sends a formatted message to
ADMIN_CHAT_IDwith:- name and username
User ID: <id>line- question text
- then clears the saved question and resets the state.
- the bot sends a formatted message to
- When the mentor replies to that message:
- the bot reads the original message text
- extracts the
User IDwith a regex - takes the reply text and sends it back to the student
- notifies the mentor that the reply was sent.
- Do not commit
config.phpwith realBOT_TOKENorADMIN_CHAT_ID:.gitignorealready ignoresconfig.php, logs and JSON state files.
- If you ever leaked a token, revoke it in
@BotFatherand set a new one. - JSON files (
user_states.json,user_questions.json) only store:- Telegram user IDs
- pending questions and states
- you can periodically clear them if you prefer.
- You can change the welcome and confirmation texts in
bot.php:mentorq_handle_start()mentorq_handle_question()mentorq_handle_callback()mentorq_send_question_to_admin()
- For more advanced setups (multiple mentors, groups, DB storage), you can:
- replace JSON storage with a database
- send questions to a group chat instead of a single admin chat ID.
This project is licensed under the MIT License.
See the LICENSE file for details.
You are free to use, modify and share MentorQ in your own projects and for your clients.