Skip to content

A simple Telegram bot that lets students submit questions and receive mentor answers directly in Telegram. Built with PHP, using webhooks and JSON storage.

License

Notifications You must be signed in to change notification settings

arash-ahmadii/mentorq-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MentorQ Telegram Bot

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


Features

For students

  • /start command 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.

For mentors/teachers

  • 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.

Technical

  • Stateless HTTP endpoint (bot.php) suitable for Telegram webhooks.
  • Lightweight JSON storage for user state and pending questions:
    • user_states.json
    • user_questions.json
  • Optional logging to bot.log.

File structure

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

Requirements

  • PHP 7.4+ with allow_url_fopen or cURL‑like HTTP access.
  • A publicly accessible HTTPS endpoint for Telegram webhook:
    • e.g. https://yourdomain.com/mentorq-bot/bot.php

Installation

  1. Create a bot in Telegram

    • Open @BotFather
    • Send /newbot
    • Choose a name and username (for example MentorQBot)
    • Copy the bot token (BOT_TOKEN)
  2. Find your mentor (admin) chat ID

    • Open @userinfobot or similar bot.
    • Send any message.
    • Note the numeric user_id (this will be ADMIN_CHAT_ID).
  3. Prepare configuration

    • Copy config.example.php to config.php:

      cp config.example.php config.php
    • Edit config.php and 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');
  4. Upload files to your server

    • Upload the entire mentorq-bot folder to your web server.
    • Ensure bot.php is reachable at the URL you set in WEBHOOK_URL.
  5. 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
  6. Test the bot

    • Open https://t.me/YourBotUsername in Telegram.
    • Send /start and follow the instructions.

How it works

  • bot.php receives 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.
  • On confirmation:
    • the bot sends a formatted message to ADMIN_CHAT_ID with:
      • name and username
      • User ID: <id> line
      • question text
    • then clears the saved question and resets the state.
  • When the mentor replies to that message:
    • the bot reads the original message text
    • extracts the User ID with a regex
    • takes the reply text and sends it back to the student
    • notifies the mentor that the reply was sent.

Security & privacy

  • Do not commit config.php with real BOT_TOKEN or ADMIN_CHAT_ID:
    • .gitignore already ignores config.php, logs and JSON state files.
  • If you ever leaked a token, revoke it in @BotFather and 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.

Customization

  • 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.

License

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.

About

A simple Telegram bot that lets students submit questions and receive mentor answers directly in Telegram. Built with PHP, using webhooks and JSON storage.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages