Back to rankings

TelegramBot/Api

PHP

Native PHP Wrapper for Telegram BOT API

telegram-botbot-apiapi-wrappersdk
Star Growth
Stars
1.2k
Forks
342
Weekly Growth
Issues
60
5001k
Jun 2015Feb 2019Nov 2022Jul 2026
ArtifactsPackagistcomposer require telegrambot/api
README

PHP Telegram Bot Api

Latest Version on Packagist Software License Total Downloads

An extended native php wrapper for Telegram Bot API without requirements. Supports all methods and types of responses.

Bots: An introduction for developers

Bots are special Telegram accounts designed to handle messages automatically. Users can interact with bots by sending them command messages in private or group chats.

You control your bots using HTTPS requests to bot API.

The Bot API is an HTTP-based interface created for developers keen on building bots for Telegram. To learn how to create and set up a bot, please consult Introduction to Bots and Bot FAQ.

Installation

Via Composer

$ composer require telegram-bot/api

Usage

See example DevAnswerBot (russian).

API Wrapper

Send message

$bot = new \TelegramBot\Api\BotApi('YOUR_BOT_API_TOKEN');

$bot->sendMessage($chatId, $messageText);

Send document

$bot = new \TelegramBot\Api\BotApi('YOUR_BOT_API_TOKEN');

$document = new \CURLFile('document.txt');

$bot->sendDocument($chatId, $document);

Send message with reply keyboard

$bot = new \TelegramBot\Api\BotApi('YOUR_BOT_API_TOKEN');

$keyboard = new \TelegramBot\Api\Types\ReplyKeyboardMarkup(array(array("one", "two", "three")), true); // true for one-time keyboard

$bot->sendMessage($chatId, $messageText, null, false, null, $keyboard);

Send message with inline keyboard

$bot = new \TelegramBot\Api\BotApi('YOUR_BOT_API_TOKEN');

$keyboard = new \TelegramBot\Api\Types\Inline\InlineKeyboardMarkup(
            [
                [
                    ['text' => 'link', 'url' => 'https://core.telegram.org']
                ]
            ]
        );
        
$bot->sendMessage($chatId, $messageText, null, false, null, $keyboard);

Send media group

$bot = new \TelegramBot\Api\BotApi('YOUR_BOT_API_TOKEN');

$media = new \TelegramBot\Api\Types\InputMedia\ArrayOfInputMedia();
$media->addItem(new TelegramBot\Api\Types\InputMedia\InputMediaPhoto('https://avatars3.githubusercontent.com/u/9335727'));
$media->addItem(new TelegramBot\Api\Types\InputMedia\InputMediaPhoto('https://avatars3.githubusercontent.com/u/9335727'));
// Same for video
// $media->addItem(new TelegramBot\Api\Types\InputMedia\InputMediaVideo('http://clips.vorwaerts-gmbh.de/VfE_html5.mp4'));
$bot->sendMediaGroup($chatId, $media);

Client

require_once "vendor/autoload.php";

try {
    $bot = new \TelegramBot\Api\Client('YOUR_BOT_API_TOKEN');

    //Handle /ping command
    $bot->command('ping', function ($message) use ($bot) {
        $bot->sendMessage($message->getChat()->getId(), 'pong!');
    });
    
    //Handle text messages
    $bot->on(function (\TelegramBot\Api\Types\Update $update) use ($bot) {
        $message = $update->getMessage();
        $id = $message->getChat()->getId();
        $bot->sendMessage($id, 'Your message: ' . $message->getText());
    }, function () {
        return true;
    });
    
    $bot->run();

} catch (\TelegramBot\Api\Exception $e) {
    $e->getMessage();
}

Local Bot API Server

For using custom local bot API server

use TelegramBot\Api\Client;
$token = 'YOUR_BOT_API_TOKEN';
$bot = new Client($token, null, null, 'http://localhost:8081');

Third-party Http Client

use Symfony\Component\HttpClient\HttpClient;
use TelegramBot\Api\BotApi;
use TelegramBot\Api\Http\SymfonyHttpClient;
$token = 'YOUR_BOT_API_TOKEN';
$bot = new Client($token, null, new SymfonyHttpClient(HttpClient::create()););

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email mail@igusev.ru instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Related repositories
freqtrade/freqtrade

Free, open source crypto trading bot

PythonPyPIGNU General Public License v3.0pythoncryptocurrencies
freqtrade.io
52.6k10.9k
enescingoz/awesome-n8n-templates

280+ free n8n automation templates — ready-to-use workflows for Gmail, Telegram, Slack, Discord, WhatsApp, Google Drive, Notion, OpenAI, and more. AI agents, RAG chatbots, email automation, social media, DevOps, and document processing. The largest open-source n8n template collection.

Otherautomationintegration
n8n.partnerlinks.io/h1pwwf5m4toe
24.1k6.3k
AZeC4/TelegramGroup

2026最新悄咪咪收集的10000+个Telegram群合集,附全网最有趣好用的机器人BOT🤖【dianbaodaohang.com】

telegramtelegram-bot
dianbaodaohang.com
22.1k1.5k
tgbot-collection/YYeTsBot

🎬 人人影视 机器人和网站,包含人人影视全部资源以及众多网友的网盘分享

PythonPyPIMIT Licenseyyetstelegram-bot
yyets.click
16.2k1.9k
telegraf/telegraf

Modern Telegram Bot Framework for Node.js

TypeScriptnpmMIT Licensebottelegram
telegraf.js.org
9.2k947
jackvale/rectg

Telegram 中文频道、群组与机器人精选索引,结合自动化抓取与人工整理,支持在线搜索与分类浏览。

PythonPyPIApache License 2.0telegramtelegram-bot
rectg.com
9.1k529
eternnoir/pyTelegramBotAPI

Python Telegram bot api.

PythonPyPIGNU General Public License v2.0telegram-bottelegram
8.8k2.1k
iyear/tdl

📥 A Telegram toolkit written in Golang

GoGo ModulesGNU Affero General Public License v3.0telegramdownloader
docs.iyear.me/tdl
7.8k771
nonebot/nonebot2

跨平台 Python 异步聊天机器人框架 / Asynchronous multi-platform chatbot framework written in Python

PythonPyPIMIT Licensenonebotcqhttp
nonebot.dev
7.6k662
aiogram/aiogram

aiogram is a modern and fully asynchronous framework for Telegram Bot API written in Python using asyncio

PythonPyPIMIT Licensepythontelegram-bot
aiogram.dev
5.8k954
rubenlagus/TelegramBots

Java library to create bots using Telegram Bots API

JavaMavenMIT Licensetelegram-bottelegram-bots-api
telegram.me/JavaBotsApi
5.5k1.4k
tangyoha/telegram_media_downloader

基于Dineshkarthik的项目, 电报视频下载,电报资源下载,跨平台,支持web查看下载进度 ,支持bot下发指令下载,支持下载已经加入的私有群但是限制下载的资源, telegram media download,Download media files from a telegram conversation/chat/channel up to 2GiB per file

JavaScriptnpmMIT Licensemedia-downloaderflask
5.4k622