PHP Classes


Recommend this page to a friend!
  Classes of Mateo   PHP Telegram Bot API Package   Download  
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: PHP Telegram Bot API Package
Build a bot that can interact with Telegram users
Author: By
Last change:
Date: 1 year ago
Size: 2,471 bytes


Class file image Download

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