PHP Classes

PHP Telegram Bot API Package: Build a bot that can interact with Telegram users

Recommend this page to a friend!
  Info   View files Documentation   View files View files (8)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 108 All time: 9,631 This week: 82Up
Version License PHP version Categories
telegram-bot-api 1.0.0MIT/X Consortium ...5PHP 5, Web services, Logging, Chat


This package can build a bot that can interact with Telegram users.

It can send Web requests to the Web server of the Telegram API to perform several types of operations that developers can use to implement a Telegram bot.

Currently, it can:

- Send generic Telegram API requests

- Define text patterns that the bot will be able to detect to trigger specific response messages

- Define keyboard buttons that can appear to respond to specific telegram messages that the users can send

- Log chatbot messages

Innovation Award
PHP Programming Innovation award nominee
July 2022
Number 8
Telegram is a well-known chat application that provides an API to build powerful bot applications. Those bot applications can interact with users automatically.

Some Telegram features allow users to answer questions using buttons or typing text using only specific keyboard characters.

This package takes advantage of the Telegram features to implement more user-friendly chatbot applications written in PHP quickly.

Manuel Lemos
Picture of Mateo
  Performance   Level  
Name: Mateo <contact>
Classes: 20 packages by
Country: Peru Peru
Age: ???
All time rank: 21244 in Peru Peru
Week rank: 30 Up1 in Peru Peru Up
Innovation award
Innovation award
Nominee: 8x

Winner: 1x


Telegram bot api


composer require mateodioev/tgbot

git clone

First step

require __DIR__ . 'path/to/vendor/autoload.php';


Make request to telegram api

use Mateodioev\Bots\Telegram\Api;
$api = new Api($bot_token, $endpoint);
$api->request('methodName', $params=[]);

$enpoint Is optional parameter, can be telegram bot api url or custom bot api


Add magic methods __call and __callStatic

use Mateodioev\Bots\Telegram\Core;
$core = new Core($bot_token);

If you want to use static methods you need some env vars

$_ENV['BOT_TOKEN']; // Bot token
$_ENV['BOT_API_LINK']; // (optional) Telegram bot api link or custom server


Methods to create results to answer inline query

use Mateodioev\Bots\Telegram\{Inline, Methods};
$methods = new Methods($token);
$inline = new Inline;

$result = $methods->answerInlineQuery($inline_id, [
    'title' => 'The world ends in 2030!!',
    'input_message_content' => $inline->InputMessageContent('This is fake news...'),
    'title' => 'How to create fake news?',
    'input_message_content' => $inline->InputMessageContent("Too easy ..."),
    'reply_markup' => (string) Buttons::create()->addCeil(['text' => 'learn more here', 'url' => ''])


Default methods

use Mateodioev\Bots\Telegram\Methods;
$methods = new Methods($token);


Create keyboards

use Mateodioev\Bots\Telegram\Buttons;
$button = Buttons::create()
->addCeil(['text' => 'Button 1', 'callback_data' => 'test'])
->addCeil(['text' => "I'm link", 'url' => ''])
->AddLine()->addCeil(['text' => 'Button in new line', 'url' => '']);

echo $button; // Return JSON object string


Activate php log and send to telegram channel

use Mateodioev\Bots\Telegram\TelegramLogger as Logger;

Logger::Activate($dir); // Directory where you want a file with the php logs to be stored
Loger::Warning($message); // send to telegram channel

__callStatic needs a $_ENV[CHANNEL_LOG] with the value of a chat_id where logs are send

  Files folder image Files  
File Role Description
Files folder imagesrc (6 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file Doc. Documentation

  Files folder image Files  /  src  
File Role Description
  Plain text file Api.php Class Class source
  Plain text file Buttons.php Class Class source
  Plain text file Core.php Class Class source
  Plain text file Inline.php Class Class source
  Plain text file Methods.php Class Class source
  Plain text file TelegramLogger.php Class Class source

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:9,631
This week:82Up