mostafabaghi/telegram-bot 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mostafabaghi/telegram-bot

最新稳定版本:v1.0.0

Composer 安装命令:

composer require mostafabaghi/telegram-bot

包简介

A full-featured PHP class for interacting with Telegram Bot API

README 文档

README

Telegram Bot Api PHP

License: 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

🚀 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

composer require mostafabaghi/telegram-bot

Or manually clone:

git clone https://github.com/mostafabaghi/telegram-bot.git
cd telegram-bot
composer install

🔧 Usage Example

Basic usage:

use TelegramBot\TelegramBotPlus;

$bot = new TelegramBotPlus('YOUR_BOT_TOKEN');
$bot->sendMessage(123456789, 'Hello world!');

Webhook handling:

$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

$bot->setWebhook('https://yourdomain.com/webhook.php');
$bot->deleteWebhook();
$bot->getWebhookInfo();

💡 Event System

$bot->on('message.text', function($message) use ($bot) {
    $bot->sendMessage($message['chat']['id'], 'Handled via event!');
});

🔐 IP Validation

if (!$bot->isFromTelegram()) {
    http_response_code(403);
    exit('Access Denied');
}

🧪 Testing

composer install
vendor/bin/phpunit

📜 License

MIT License © mostafabaghi

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-24