Skip to content

Mateodioev/telegram-bot-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telegram bot api

Install

composer require mateodioev/tgbot
git clone https://github.com/Mateodioev/tgbot

First step

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

Create new Api instance

use Mateodioev\Bots\Telegram\Api;

$api = new Api($bot_token);

Send method to telegram api

use Mateodioev\Bots\Telegram\Types\Message;

$message = $api->sendMessage('chat_id', 'Text', $others_params);

var_dump($message->get());
var_dump($message instanceof Message::class);

Enable async mode

Note: This use amphp/http-client

$api->setAsync(true);

Create new telegram types

use Mateodioev\Bots\Telegram\Types\baseType;

class MyCustomType extends baseType
{
    protected array $fields = [
        'field1' => 'valueType',
        'id'     => 'integer', // only accept integer values
        'user'   => User::class, // only accept arrays or instances of the User class
    ];
}

Create new instance

// from array
$customType = MyCustomType::createFromArray(['field1' => 'Type', 'id' => 1111, 'user' => $user]);
// From stdClass
$customType = MyCustomType::create((object) ['field1' => 'Type', 'id' => 1111, 'user' => $user]);
// Create from constructor
$customType = new MyCustomType(field1: 'Type', id: 1111, user: $user); // maybe this cause linter errors