Skip to main content
Version: 3.x

Available Methods & Examples

The library supports all the methods listed on Telegram Bot API docs page.

Send a Message

See sendMessage docs for a list of supported parameters and other info.

$response = $telegram->sendMessage([
'chat_id' => 'CHAT_ID',
'text' => 'Hello World'
]);

$messageId = $response->getMessageId();

Forward a Message

See forwardMessage docs for a list of supported parameters and other info.

$response = $telegram->forwardMessage([
'chat_id' => 'CHAT_ID',
'from_chat_id' => 'FROM_CHAT_ID',
'message_id' => 'MESSAGE_ID'
]);

$messageId = $response->getMessageId();

Send a Photo

See sendPhoto docs for a list of supported parameters and other info.

$response = $telegram->sendPhoto([
'chat_id' => 'CHAT_ID',
'photo' => 'path/to/photo.jpg',
'caption' => 'Some caption'
]);

$messageId = $response->getMessageId();

The ability to send an image directly from an URL has now been added to the library. Instead of supplying a local path and filename, you may now pass the image URL.

$response = $telegram->sendPhoto([
'chat_id' => 'CHAT_ID',
'photo' => 'http://example.com/photos/image.jpg',
'caption' => 'Some caption'
]);

$messageId = $response->getMessageId();

Send a Chat Action

See sendChatAction docs for a list of supported actions and other info.

$telegram->sendChatAction([
'chat_id' => 'CHAT_ID',
'action' => 'upload_photo'
]);

There is also a new helper method for supplying the chat action. This is especially useful with code completion with your IDE.

use Telegram\Bot\Actions;

$telegram->sendChatAction([
'chat_id' => 'CHAT_ID',
'action' => Actions::RECORD_VIDEO
]);

Get User Profile Photos

See getUserProfilePhotos docs for a list of supported parameters and other info.

$response = $telegram->getUserProfilePhotos(['user_id' => 'USER_ID']);

$photos_count = $response->getTotalCount();
$photos = $response->getPhotos();

Get Updates

See getUpdates docs for a list of supported parameters and other info.

$updates = $telegram->getUpdates();