Skip to content

Library for working with Telegram Bot API

License

Notifications You must be signed in to change notification settings

yamilramilev/telegram_bot

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telegram Bot by Tsvetkov

Latest Stable Version Total Downloads

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);

About

Library for working with Telegram Bot API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%