https://github.com/mostafabaghi/telegram-bot
A full-featured PHP class for interacting with Telegram Bot API
https://github.com/mostafabaghi/telegram-bot
api bot php telegram telegram-bot-api telegrambot
Last synced: 7 months ago
JSON representation
A full-featured PHP class for interacting with Telegram Bot API
- Host: GitHub
- URL: https://github.com/mostafabaghi/telegram-bot
- Owner: mostafabaghi
- License: mit
- Created: 2025-07-24T18:20:25.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-07-24T18:41:14.000Z (11 months ago)
- Last Synced: 2025-08-27T19:15:42.963Z (10 months ago)
- Topics: api, bot, php, telegram, telegram-bot-api, telegrambot
- Language: PHP
- Homepage: https://www.youtube.com/playlist?list=PLdhF00_39aY_c93i79pbaWdY9g_-idWHX
- Size: 75.2 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Telegram Bot Plus

[](https://opensource.org/licenses/MIT)
A modern, fully featured PHP wrapper for the Telegram Bot API โ built for developers who want full control and modern structure with PSR-4 compatibility.
GitHub: [github.com/mostafabaghi/telegram-bot](https://github.com/mostafabaghi/telegram-bot)
---
## ๐ Features
- PSR-4 autoloading
- Full API support (sendMessage, sendMedia, Polls, Payments...)
- Debug logging
- Webhook handler system
- Event Dispatcher system (like Laravel listeners)
- IP validation for Telegram
- File uploads via URL, local, or stream (memory)
---
## ๐ฆ Installation
```bash
composer require mostafabaghi/telegram-bot
```
> Or manually clone:
```bash
git clone https://github.com/mostafabaghi/telegram-bot.git
cd telegram-bot
composer install
```
---
## ๐ง Usage Example
### Basic usage:
```php
use TelegramBot\TelegramBotPlus;
$bot = new TelegramBotPlus('YOUR_BOT_TOKEN');
$bot->sendMessage(123456789, 'Hello world!');
```
### Webhook handling:
```php
$bot->setWebhookHandler(function($update) use ($bot) {
if (isset($update['message']['text'])) {
$chatId = $update['message']['chat']['id'];
$bot->sendMessage($chatId, "Received: " . $update['message']['text']);
}
});
$bot->handleWebhook();
```
---
## ๐ Documentation
### โ
Core Methods
| Method | Description |
|--------|-------------|
| `sendMessage($chatId, $text, $options = [])` | Send text message |
| `sendPhoto($chatId, $photoPath, $caption = '')` | Send image |
| `sendMedia($type, $chatId, $media, $caption = '')` | Send media (photo, video, document, ...) |
| `sendMediaGroup($chatId, $mediaArray)` | Send album (array of media) |
| `sendPoll($chatId, $question, $options)` | Create poll |
| `sendInvoice(...)` | Send payment invoice |
| `answerCallbackQuery(...)` | Answer inline button click |
### โ๏ธ Webhook Management
```php
$bot->setWebhook('https://yourdomain.com/webhook.php');
$bot->deleteWebhook();
$bot->getWebhookInfo();
```
### ๐ก Event System
```php
$bot->on('message.text', function($message) use ($bot) {
$bot->sendMessage($message['chat']['id'], 'Handled via event!');
});
```
### ๐ IP Validation
```php
if (!$bot->isFromTelegram()) {
http_response_code(403);
exit('Access Denied');
}
```
---
## ๐งช Testing
```bash
composer install
vendor/bin/phpunit
```
---
## ๐ License
MIT License ยฉ [mostafabaghi](https://github.com/mostafabaghi)