PHP Classes


Recommend this page to a friend!
  Classes of David Girón   PHP Telegram Bot   Download  
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: PHP Telegram Bot
Send and receive messages to Telegram users
Author: By
Last change: Update README.
Date: 6 years ago
Size: 2,008 bytes


Class file image Download


Another library to use Telegram bots with PHP.

  • Include the src/Autoloader.php file.
  • Create a Telegram\Bot object.
  • Create a Telegram\Receiver object using the $bot.
$bot = new Telegram\Bot("11111111:AAAAAAAAAAzzzzzzzzzzzzzzzzzzz", "MyUserBot", "The Name of Bot");
$tg  = new Telegram\Receiver($bot);

You can create as many Bots and Receivers or Senders as you want. Using Receiver includes a Sender.


Once the page is loaded (manually or via webhook), you can send or reply the requests.

To send a message to a user or group chat:

  ->text("Hello world!")

To reply a user command:


To reply a user message:

if($tg->text_has("are you alive")){

NEW: To parse a string:

if($tg->text_regex("I'm {N:age}") and $tg->words() <= 4){
  $num = $tg->input->age;
  $str = "So old...";
  if($num < 18){ $str = "You're young!"; }
}elseif($tg->text_regex("My name's {name}")){
    ->text("Nice to meet you, " .$tg->input->name ."!")

Send an Inline Keyboard and parse it:

if($tg->callback == "but 1"){
  $tg->answer_if_callback(""); // Stop loading button.
    ->text("You pressed the first button!")
}elseif($tg->callback == "but 2"){
  $tg->answer_if_callback("You pressed the second button!", TRUE);
  // Display an alert and stop loading button.

if($tg->text_has("matrix") and $tg->words() <= 5){
    ->text("Red or blue. You choose.")
        ->button("Red",  "but 1")
        ->button("Blue", "but 2")