gfn / telegram-php-sdk
A PHP SDK for the Telegram-API.
Requires
- php: >=8.4
- ext-json: *
- guzzlehttp/guzzle: ^7.9.0
- mlocati/ip-lib: ^1.20.0
Requires (Dev)
- phpunit/phpunit: ^12.1.0
This package is auto-updated.
Last update: 2025-05-11 19:38:06 UTC
README
An SDK written in PHP to communicate with the Telegram Bot API.
Last supportet Bot API Version: 9.0 (2025-04-11)
All useful Information to Telegram Bots can you find on the official Website.
This is only an SDK, not a Bot itself.
Disclaimer
This project and its author are neither associated nor affiliated with Telegram in any way.
License
This project is released under the MIT License.
Requirements
- PHP >= 8.4
Installation
Attention: This software is currently on alpha.
The easiest way is the installation via Composer: composer require gfn/telegram-php-sdk
Alternatively you can add this GIT-Repository to your composer.json:
{
"repositories": [
{
"type": "git",
"url": "https://gitlab.german-furs.net/german-furs/telegram-php-sdk.git",
"no-api": true
}
]
}
Usage
First you need to create a bot via BotFather and authorize it. Save the token and hold it save.
All classes have links to the original documentation. If you are not sure how to use the class, check out the documentation.
Examples requests outgoing
getMe
With the getMe method, you can request all information about your bot.
$bot_token = 'xxx';
$get_me = new \GfnTelegramPhpSdk\Core\Request\GetMe();
try {
$get_me->execute($bot_token)
var_dump($get_me->getResponse());
} catch (\GfnTelegramPhpSdk\Exception\GfnTelegramPhpSdkException $e) {
var_dump($e);
}
sendMessage
With the sendMessage method, you can send a message to a user or chat.
$bot_token = 'xxx';
$chat_id = 000;
$sm = new SendMessage();
$sm->chat_id = $chat_id;
$sm->text = 'Test Message';
// Example with inline buttons.
// Buttons One & Two are on line 1, Button Three is on line 2.
// Each InlineKeyboardButton needs a purpose, so I used the callback_data.
$button_one_data = [
'text' => 'Button One',
'callback_data' => 'callback_one'
];
$button_two_data = [
'text' => 'Button Two',
'callback_data' => 'callback_two'
];
$button_three_data = [
'text' => 'Button Three',
'callback_data' => 'callback_three'
];
$inline_keyboard_markup = new \GfnTelegramPhpSdk\Core\Type\InlineKeyboardMarkup(['inline_keyboard' => [[$button_one_data, $button_two_data],[$button_three_data]]]);
$sm->reply_markup = $inline_keyboard_markup;
try {
$sm->execute($bot_token)
var_dump($sm->getResponse());
} catch (\GfnTelegramPhpSdk\Exception\GfnTelegramPhpSdkException $e) {
var_dump($e);
}
Examples requests incoming
All incoming traffic is checked. If the request does not come from the Telegram network, it will be ignored.