This package is abandoned and no longer maintained. The author suggests using the nutgram/nutgram package instead.

Framework for Telegram Bot API

v1.14.1 2021-09-07 00:24 UTC




Latest Stable Version Total Downloads License

A very simple PHP Telegram Bot API for sending messages.


  • PHP ≥ 7.2
  • Curl for PHP must be enabled.
  • Telegram API Key, you can get one simply with @BotFather with simple commands right after creating your bot.

For the WebHook:

  • An SSL certificate (Telegram API requires this). You can use Cloudflare's Free Flexible SSL which crypts the web traffic from end user to their proxies if you're using CloudFlare DNS.
    Since the August 29 update you can use a self-signed ssl certificate.

For the GetUpdates:

  • Some way to execute the script in order to serve messages (for example cronjob)


You can install this library with composer:

composer require lukasss93/telegrambot-php

Configuration (WebHook)

Navigate to Or use the Telegram class setWebhook method.


This simple framework is object-based, all methods return a Telegram Object contained in TelegramBot/Types namespace.


use TelegramBot\TelegramBot;

$bot = new TelegramBot($token);
    'chat_id' => $update->message->chat->id,
    'text' => 'Hello world!'

If you want to get some specific parameter from the Telegram webhook, simply call parameter name in the object:

use TelegramBot\TelegramBot;

$bot = new TelegramBot($token);

To upload a Photo or some other files, you need to load it with CurlFile:

// Load a local file to upload. If is already on Telegram's Servers just pass the resource id
$img = curl_file_create('test.png','image/png');
    'chat_id' => $chat_id, 
    'photo' => $img

To download a file on the Telegram's servers

$file = $bot->getFile($file_id);
$bot->downloadFile($file->file_path, "./my_downloaded_file_on_local_server.png");

If you want to use getUpdates instead of the WebHook you need a for cycle.

for ($i = 0; $i < count($updates); $i++) {
    //single update

Message Object Methods

Message object mainly provide 2 methods:

  • getCommand()

    //$update->message->text => '/test@ExampleBot my args'
    //$command => '/text'
  • getArgs(bool $asString=false)

    //$update->message->text => '/test@ExampleBot my args'
    //$args_array[0] => 'my'
    //$args_array[1] => 'args'
    //$args_string => 'my args'

Build keyboard parameters

Telegram's bots can have two different kind of keyboards: Inline and Reply. The InlineKeyboard is linked to a particular message, while the ReplyKeyboard is linked to the whole chat. They are both an array of array of buttons, which rapresent the rows and columns. For instance you can arrange a ReplyKeyboard using this code:

$buttons = [ 
    //First row
        $bot->buildKeyboardButton("Button 1"),
        $bot->buildKeyboardButton("Button 2")
    //Second row 
        $bot->buildKeyboardButton("Button 3"),
        $bot->buildKeyboardButton("Button 4"),
        $bot->buildKeyboardButton("Button 5")], 
    //Third row
        $bot->buildKeyboardButton("Button 6")]
    'chat_id' => $chat_id, 
    'reply_markup' => $bot->buildKeyBoard($buttons), 
    'text' => 'This is a Keyboard Test'

When a user click on the button, the button text is send back to the bot. For an InlineKeyboard it's pretty much the same (but you need to provide a valid URL or a Callback data)

$buttons = [ 
    //First row
        $bot->buildInlineKeyBoardButton("Button 1", $url=""), 
        $bot->buildInlineKeyBoardButton("Button 2", $url="")
    //Second row 
        $bot->buildInlineKeyBoardButton("Button 3", $url=""),
        $bot->buildInlineKeyBoardButton("Button 4", $url=""),
        $bot->buildInlineKeyBoardButton("Button 5", $url="")
    //Third row
        $bot->buildInlineKeyBoardButton("Button 6", $url="")

    'chat_id' => $chat_id, 
    'reply_markup' => $bot->buildInlineKeyBoard($buttons), 
    'text' => 'This is a Keyboard Test'

This is the list of all the helper functions to make keyboards easily:

$bot->buildKeyBoard(array $options, $onetime=true, $resize=true, $selective=true);

Send a custom keyboard. $option is an array of array KeyboardButton.
Check ReplyKeyBoardMarkUp for more info.

$bot->buildInlineKeyBoard(array $inline_keyboard);

Send a custom keyboard. $inline_keyboard is an array of array InlineKeyboardButton.
Check InlineKeyboardMarkup for more info.

$bot->buildInlineKeyBoardButton($text, $url, $callback_data, $switch_inline_query);

Create an InlineKeyboardButton.
Check InlineKeyBoardButton for more info.

$bot->buildKeyBoardButton($text, $url, $request_contact, $request_location);

Create a KeyboardButton.
Check KeyBoardButton for more info.


Hide a custom keyboard.
Check ReplyKeyBoarHide for more info.


Show a Reply interface to the user.
Check ForceReply for more info.

Contact me

You can contact me via Telegram but if you have an issue please open one.

To-Do list

  • Optional predictive parameters in methods
  • Optimize keyboards
  • Chat conversations
  • Commands listener with callback + events


All notable changes to this project will be documented here.