https://github.com/mateodioev/telegram-bot-api
Telegram bot sdk
https://github.com/mateodioev/telegram-bot-api
php telegram telegram-bot telegram-bot-api
Last synced: 11 months ago
JSON representation
Telegram bot sdk
- Host: GitHub
- URL: https://github.com/mateodioev/telegram-bot-api
- Owner: Mateodioev
- Created: 2022-06-16T14:18:23.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-10-28T03:27:03.000Z (over 1 year ago)
- Last Synced: 2024-10-28T07:02:30.098Z (over 1 year ago)
- Topics: php, telegram, telegram-bot, telegram-bot-api
- Language: PHP
- Homepage:
- Size: 899 KB
- Stars: 4
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Telegram bot api
## Install
```bash
composer require mateodioev/tgbot
```
```bash
git clone https://github.com/Mateodioev/tgbot
```
## First step
```php
require __DIR__ . 'path/to/vendor/autoload.php';
```
## Create new Api instance
```php
use Mateodioev\Bots\Telegram\Api;
$api = new Api($bot_token);
```
## Send method to telegram api
```php
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`
```php
$api->setAsync(true);
```
## Create new telegram types
```php
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*
```php
// 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
```