tsvetkov / telegram_bot
PHP Library for telegram bot API
Installs: 1 158
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
pkg:composer/tsvetkov/telegram_bot
Requires
- php: >=5.6.0
 - ext-curl: *
 - ext-json: *
 - guzzlehttp/guzzle: ^6.3 || ^7.0
 
Requires (Dev)
- phpstan/phpstan: ^0.11.15
 - vimeo/psalm: ^3.5
 
README
Telegram Bot by Tsvetkov
Installation
In order to install extension use Composer. Either run
php composer.phar require tsvetkov/telegram_bot
or add
"tsvetkov/telegram_bot": "*"
to the require section of your composer.json.
Basic Usage
Initialization
use tsvetkov\telegram_bot\TelegramBot;
$bot = new TelegramBot($token); // You can get token of you bots from @BotFather
// With proxy
$requestOptions = [
    'proxy' => 'your_proxy_config',
];
$bot = new TelegramBot($token, $requestOptions);
Send message
$bot->sendMessage($userId, 'Hello world!');
Get updates
$updates = $bot->getUpdates();
Webhooks
$data = json_decode(file_get_contents('php://input'));
$update = new \tsvetkov\telegram_bot\entities\update\Update($data);
How to send media group with a files?
Use attach://file_name_in_post for that
$media = [
    new \tsvetkov\telegram_bot\entities\inputMedia\InputMediaPhoto([
        'media' => 'attach://file-photo',
    ]),
    new \tsvetkov\telegram_bot\entities\inputMedia\InputMediaVideo([
        'media' => 'attach://file-video',
    ]),
];
Don't forget to add your files to request
$files = [
    'file-video' => "path_to_video_for_upload",
    'file-photo' => "path_to_photo_for_upload",
];
And just send your request
$message = $bot->sendMediaGroup($chatId, $media, $files);