Compare commits

..

No commits in common. "master" and "6.7.0" have entirely different histories.

489 changed files with 13091 additions and 25538 deletions

View file

@ -1,555 +0,0 @@
name: CI
on:
push:
branches:
- '**'
release:
types: [created]
workflow_dispatch:
jobs:
release:
runs-on: ubuntu-latest
container:
image: php:8.3
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install dependencies
run: |
apt update -yqq
apt install git libpq-dev libzip-dev zip make wget gnupg -yqq
- name: Install phive
run: |
wget -O phive.phar https://phar.io/releases/phive.phar
wget -O phive.phar.asc https://phar.io/releases/phive.phar.asc
gpg --keyserver hkps://keys.openpgp.org --recv-keys 0x9D8A98B29B2D5D79
gpg --verify phive.phar.asc phive.phar
chmod +x phive.phar
mv phive.phar /usr/local/bin/phive
- name: Install phab
run: |
phive install phpab --global --trust-gpg-keys 0x2A8299CE842DD38C
- name: Install latest version of NCC
run: |
git clone https://git.n64.cc/nosial/ncc.git
cd ncc
make redist
NCC_DIR=$(find build/ -type d -name "ncc_*" | head -n 1)
if [ -z "$NCC_DIR" ]; then
echo "NCC build directory not found"
exit 1
fi
php "$NCC_DIR/INSTALL" --auto
cd .. && rm -rf ncc
- name: Build project
run: |
ncc build --config release --build-source --log-level debug
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: release
path: build/release/net.nosial.tgbotlib.ncc
release-compressed:
runs-on: ubuntu-latest
container:
image: php:8.3
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install dependencies
run: |
apt update -yqq
apt install git libpq-dev libzip-dev zip make wget gnupg -yqq
- name: Install phive
run: |
wget -O phive.phar https://phar.io/releases/phive.phar
wget -O phive.phar.asc https://phar.io/releases/phive.phar.asc
gpg --keyserver hkps://keys.openpgp.org --recv-keys 0x9D8A98B29B2D5D79
gpg --verify phive.phar.asc phive.phar
chmod +x phive.phar
mv phive.phar /usr/local/bin/phive
- name: Install phab
run: |
phive install phpab --global --trust-gpg-keys 0x2A8299CE842DD38C
- name: Install latest version of NCC
run: |
git clone https://git.n64.cc/nosial/ncc.git
cd ncc
make redist
NCC_DIR=$(find build/ -type d -name "ncc_*" | head -n 1)
if [ -z "$NCC_DIR" ]; then
echo "NCC build directory not found"
exit 1
fi
php "$NCC_DIR/INSTALL" --auto
cd .. && rm -rf ncc
- name: Build project
run: |
ncc build --config release-compressed --build-source --log-level debug
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: release-compressed
path: build/release/net.nosial.tgbotlib.gz.ncc
release-executable:
runs-on: ubuntu-latest
container:
image: php:8.3
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install dependencies
run: |
apt update -yqq
apt install git libpq-dev libzip-dev zip make wget gnupg -yqq
- name: Install phive
run: |
wget -O phive.phar https://phar.io/releases/phive.phar
wget -O phive.phar.asc https://phar.io/releases/phive.phar.asc
gpg --keyserver hkps://keys.openpgp.org --recv-keys 0x9D8A98B29B2D5D79
gpg --verify phive.phar.asc phive.phar
chmod +x phive.phar
mv phive.phar /usr/local/bin/phive
- name: Install phab
run: |
phive install phpab --global --trust-gpg-keys 0x2A8299CE842DD38C
- name: Install latest version of NCC
run: |
git clone https://git.n64.cc/nosial/ncc.git
cd ncc
make redist
NCC_DIR=$(find build/ -type d -name "ncc_*" | head -n 1)
if [ -z "$NCC_DIR" ]; then
echo "NCC build directory not found"
exit 1
fi
php "$NCC_DIR/INSTALL" --auto
cd .. && rm -rf ncc
- name: Build project
run: |
ncc build --config release-executable --build-source --log-level debug
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: release-executable
path: build/release/TgBotLib
release-executable-compressed:
runs-on: ubuntu-latest
container:
image: php:8.3
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install dependencies
run: |
apt update -yqq
apt install git libpq-dev libzip-dev zip make wget gnupg -yqq
- name: Install phive
run: |
wget -O phive.phar https://phar.io/releases/phive.phar
wget -O phive.phar.asc https://phar.io/releases/phive.phar.asc
gpg --keyserver hkps://keys.openpgp.org --recv-keys 0x9D8A98B29B2D5D79
gpg --verify phive.phar.asc phive.phar
chmod +x phive.phar
mv phive.phar /usr/local/bin/phive
- name: Install phab
run: |
phive install phpab --global --trust-gpg-keys 0x2A8299CE842DD38C
- name: Install latest version of NCC
run: |
git clone https://git.n64.cc/nosial/ncc.git
cd ncc
make redist
NCC_DIR=$(find build/ -type d -name "ncc_*" | head -n 1)
if [ -z "$NCC_DIR" ]; then
echo "NCC build directory not found"
exit 1
fi
php "$NCC_DIR/INSTALL" --auto
cd .. && rm -rf ncc
- name: Build project
run: |
ncc build --config release-executable-compressed --build-source --log-level debug
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: release-executable-compressed
path: build/release/TgBotLib_gz
debug:
runs-on: ubuntu-latest
container:
image: php:8.3
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install dependencies
run: |
apt update -yqq
apt install git libpq-dev libzip-dev zip make wget gnupg -yqq
- name: Install phive
run: |
wget -O phive.phar https://phar.io/releases/phive.phar
wget -O phive.phar.asc https://phar.io/releases/phive.phar.asc
gpg --keyserver hkps://keys.openpgp.org --recv-keys 0x9D8A98B29B2D5D79
gpg --verify phive.phar.asc phive.phar
chmod +x phive.phar
mv phive.phar /usr/local/bin/phive
- name: Install phab
run: |
phive install phpab --global --trust-gpg-keys 0x2A8299CE842DD38C
- name: Install latest version of NCC
run: |
git clone https://git.n64.cc/nosial/ncc.git
cd ncc
make redist
NCC_DIR=$(find build/ -type d -name "ncc_*" | head -n 1)
if [ -z "$NCC_DIR" ]; then
echo "NCC build directory not found"
exit 1
fi
php "$NCC_DIR/INSTALL" --auto
cd .. && rm -rf ncc
- name: Build project
run: |
ncc build --config debug --build-source --log-level debug
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: debug
path: build/debug/net.nosial.tgbotlib.ncc
debug-compressed:
runs-on: ubuntu-latest
container:
image: php:8.3
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install dependencies
run: |
apt update -yqq
apt install git libpq-dev libzip-dev zip make wget gnupg -yqq
- name: Install phive
run: |
wget -O phive.phar https://phar.io/releases/phive.phar
wget -O phive.phar.asc https://phar.io/releases/phive.phar.asc
gpg --keyserver hkps://keys.openpgp.org --recv-keys 0x9D8A98B29B2D5D79
gpg --verify phive.phar.asc phive.phar
chmod +x phive.phar
mv phive.phar /usr/local/bin/phive
- name: Install phab
run: |
phive install phpab --global --trust-gpg-keys 0x2A8299CE842DD38C
- name: Install latest version of NCC
run: |
git clone https://git.n64.cc/nosial/ncc.git
cd ncc
make redist
NCC_DIR=$(find build/ -type d -name "ncc_*" | head -n 1)
if [ -z "$NCC_DIR" ]; then
echo "NCC build directory not found"
exit 1
fi
php "$NCC_DIR/INSTALL" --auto
cd .. && rm -rf ncc
- name: Build project
run: |
ncc build --config debug-compressed --build-source --log-level debug
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: debug-compressed
path: build/debug/net.nosial.tgbotlib.gz.ncc
# Checking for phpunit.xml
check-phpunit:
runs-on: ubuntu-latest
outputs:
phpunit-exists: ${{ steps.check.outputs.phpunit-exists }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check for phpunit.xml
id: check
run: |
if [ -f phpunit.xml ]; then
echo "phpunit-exists=true" >> $GITHUB_OUTPUT
else
echo "phpunit-exists=false" >> $GITHUB_OUTPUT
fi
# Checking for phpdoc.dist.xml
check-phpdoc:
runs-on: ubuntu-latest
outputs:
phpdoc-exists: ${{ steps.check.outputs.phpdoc-exists }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check for phpdoc.dist.xml
id: check
run: |
if [ -f phpdoc.dist.xml ]; then
echo "phpdoc-exists=true" >> $GITHUB_OUTPUT
else
echo "phpdoc-exists=false" >> $GITHUB_OUTPUT
fi
generate-phpdoc:
needs: [release, check-phpdoc]
runs-on: ubuntu-latest
container:
image: php:8.3
if: needs.check-phpdoc.outputs.phpdoc-exists == 'true'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install dependencies
run: |
apt update -yqq
apt install git libpq-dev libzip-dev zip make wget gnupg -yqq
- name: Download PHPDocumentor
run: |
wget https://phpdoc.org/phpDocumentor.phar
chmod +x phpDocumentor.phar
- name: Generate PHPDoc
run: |
php phpDocumentor.phar -d src -t docs
- name: Archive PHPDoc
run: |
zip -r docs.zip docs
- name: Upload PHPDoc
uses: actions/upload-artifact@v4
with:
name: documentation
path: docs.zip
test:
needs: [release, release-compressed, release-executable, release-executable-compressed, debug, debug-compressed, check-phpunit]
runs-on: ubuntu-latest
container:
image: php:8.3
if: needs.check-phpunit.outputs.phpunit-exists == 'true'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: release
path: release
- name: Install dependencies
run: |
apt update -yqq
apt install git libpq-dev libzip-dev zip make wget gnupg -yqq
curl -sSLf -o /usr/local/bin/install-php-extensions https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions
chmod +x /usr/local/bin/install-php-extensions
install-php-extensions zip
- name: Install phive
run: |
wget -O phive.phar https://phar.io/releases/phive.phar
wget -O phive.phar.asc https://phar.io/releases/phive.phar.asc
gpg --keyserver hkps://keys.openpgp.org --recv-keys 0x9D8A98B29B2D5D79
gpg --verify phive.phar.asc phive.phar
chmod +x phive.phar
mv phive.phar /usr/local/bin/phive
- name: Install phab
run: |
phive install phpab --global --trust-gpg-keys 0x2A8299CE842DD38C
- name: Install latest version of NCC
run: |
git clone https://git.n64.cc/nosial/ncc.git
cd ncc
make redist
NCC_DIR=$(find build/ -type d -name "ncc_*" | head -n 1)
if [ -z "$NCC_DIR" ]; then
echo "NCC build directory not found"
exit 1
fi
php "$NCC_DIR/INSTALL" --auto
cd .. && rm -rf ncc
- name: Install NCC packages
run: |
ncc package install --package="release/net.nosial.tgbotlib.ncc" --build-source --reinstall -y --log-level debug
- name: Export token.txt
run: echo "${{ secrets.TELEGRAM_TEST_TOKEN }}" > tests/token.txt
- name: Run PHPUnit tests
run: |
wget https://phar.phpunit.de/phpunit-11.3.phar
php phpunit-11.3.phar --configuration phpunit.xml --log-junit reports/junit.xml --log-teamcity reports/teamcity --testdox-html reports/testdox.html --testdox-text reports/testdox.txt
- name: Upload test reports
uses: actions/upload-artifact@v4
with:
name: reports
path: reports
release-documentation:
needs: generate-phpdoc
permissions: write-all
runs-on: ubuntu-latest
container:
image: php:8.3
if: github.event_name == 'release'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download documentation artifact
uses: actions/download-artifact@v4
with:
name: documentation
path: documentation
- name: Upload documentation artifact
uses: softprops/action-gh-release@v1
with:
files: |
documentation/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
release-artifacts:
needs: [release, release-compressed, release-executable, release-executable-compressed, debug, debug-compressed]
permissions: write-all
runs-on: ubuntu-latest
container:
image: php:8.3
if: github.event_name == 'release'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download release artifact
uses: actions/download-artifact@v4
with:
name: release
path: release
- name: Upload release artifact to release
uses: softprops/action-gh-release@v1
with:
files: |
release/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Download release-compressed artifact
uses: actions/download-artifact@v4
with:
name: release-compressed
path: release-compressed
- name: Upload release-compressed artifact to release
uses: softprops/action-gh-release@v1
with:
files: |
release-compressed/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Download release-executable artifact
uses: actions/download-artifact@v4
with:
name: release-executable
path: release-executable
- name: Upload release-executable artifact to release
uses: softprops/action-gh-release@v1
with:
files: |
release-executable/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Download release-executable-compressed artifact
uses: actions/download-artifact@v4
with:
name: release-executable-compressed
path: release-executable-compressed
- name: Upload release-executable-compressed artifact to release
uses: softprops/action-gh-release@v1
with:
files: |
release-executable-compressed/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Download debug artifact
uses: actions/download-artifact@v4
with:
name: debug
path: debug
- name: Upload debug artifact to release
uses: softprops/action-gh-release@v1
with:
files: |
debug/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Download debug-compressed artifact
uses: actions/download-artifact@v4
with:
name: debug-compressed
path: debug-compressed
- name: Upload debug-compressed artifact to release
uses: softprops/action-gh-release@v1
with:
files: |
debug-compressed/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

8
.gitignore vendored
View file

@ -1,7 +1 @@
build/
tests/token.txt
/.phpunit.result.cache
/.idea/php-test-framework.xml
/.idea/gbrowser_project.xml
/.phpdoc/
!/.github/workflows/ncc_workflow.yml
build/

View file

@ -1,11 +1,6 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<Languages>
<language minSize="102" name="PHP" />
</Languages>
</inspection_tool>
<inspection_tool class="IncorrectHttpHeaderInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="customHeaders">
<set>

13
.idea/php.xml generated
View file

@ -12,22 +12,19 @@
<component name="PhpAnalysisConfiguration" call_tree_analysis_depth="3" />
<component name="PhpIncludePathManager">
<include_path>
<path value="/var/ncc/packages/net.nosial.optslib=1.1.2" />
<path value="/var/ncc/packages/net.nosial.loglib=2.0.2" />
<path value="/usr/share/php" />
<path value="/etc/ncc" />
<path value="/var/ncc/packages/net.nosial.tamerlib=2.1.5" />
<path value="/var/ncc/packages/net.nosial.loglib=1.0.2" />
<path value="/var/ncc/packages/net.nosial.tempfile=1.1.0" />
</include_path>
</component>
<component name="PhpProjectSharedConfiguration" php_language_level="8.3">
<component name="PhpProjectSharedConfiguration" php_language_level="8.1">
<option name="suggestChangeDefaultLanguageLevel" value="false" />
</component>
<component name="PhpStanOptionsConfiguration">
<option name="transferred" value="true" />
</component>
<component name="PhpUnit">
<phpunit_settings>
<PhpUnitSettings load_method="PHPUNIT_PHAR" bootstrap_file_path="$PROJECT_DIR$/bootstrap.php" custom_loader_path="" phpunit_phar_path="$USER_HOME$/phpunit.phar" use_bootstrap_file="true" />
</phpunit_settings>
</component>
<component name="PsalmOptionsConfiguration">
<option name="transferred" value="true" />
</component>

View file

@ -4,48 +4,6 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [8.0.2] - 2024-12-09
This update introduces some quality of life improvements.
### Added
* Added `containsMedia` method to `Message` object to check if the message contains media.
* Add support for handling callback query events
## [8.0.1] - 2024-12-04
This update introduces bug fixes and improvements
### Changed
* Refactor PollingBot to use PsyncLib for updates
* Refactor optional parameters in method signatures
* Improve command check with method existence validation
### Fixed
* Reposition debug log for event handler execution.
* Improve command check with method existence validation
* Allow nullable type for MessageEntity type
* Encode arrays as JSON in SendAudio parameters
* Refactor fromArray method for null data handling
## [8.0.0] - 2024-11-29
This is a new major update which makes the previous versions of this library deprecated
### Added
* Added unit tests
* Added `can_connect_to_business` & `has_main_web_app` to User object
### Changed
* Refactored the way HTTP requests are handled & methods are called
* Refactor enums to use native PHP 8.1 syntax
* Moved Types to their own namespace
* Refactored all Objects & Methods to use a different system
* Refactored the event system to allow for more event types
## [6.7.0] - 2023-08-10
This update accompanies the release of the [Telegram Bot API 6.7](https://core.telegram.org/bots/api#april-21-2023).

View file

@ -1,33 +1,8 @@
# Variables
DEFAULT_CONFIGURATION ?= release
LOG_LEVEL = debug
build:
ncc build --config="release" --log-level debug
# Default Target
all: release release-compressed release-executable release-executable-compressed debug debug-compressed
# Build Steps
release:
ncc build --config=release --log-level $(LOG_LEVEL)
release-compressed:
ncc build --config=release-compressed --log-level $(LOG_LEVEL)
release-executable:
ncc build --config=release-executable --log-level $(LOG_LEVEL)
release-executable-compressed:
ncc build --config=release-executable-compressed --log-level $(LOG_LEVEL)
debug:
ncc build --config=debug --log-level $(LOG_LEVEL)
debug-compressed:
ncc build --config=debug-compressed --log-level $(LOG_LEVEL)
install: release
ncc package install --package=build/release/net.nosial.tgbotlib.ncc --skip-dependencies --build-source --reinstall -y --log-level $(LOG_LEVEL)
test: release
[ -f phpunit.xml ] || { echo "phpunit.xml not found"; exit 1; }
phpunit
install:
sudo ncc package install --package="build/release/net.nosial.tgbotlib.ncc" --skip-dependencies --reinstall -y --log-level debug
clean:
rm -rf build
.PHONY: all install test clean release release-compressed release-executable release-executable-compressed debug debug-compressed
rm -rf build

285
README.md
View file

@ -12,7 +12,17 @@ native around the API.
* [TgBotLib](#tgbotlib)
* [Table of contents](#table-of-contents)
* [Versioning](#versioning)
* [TODO](#todo)
* [Installation](#installation)
* [Compile from source](#compile-from-source)
* [Requirements](#requirements)
* [Usage](#usage)
* [Documentation](#documentation)
* [Single-Threaded & Multi-Threaded Bots](#single-threaded--multi-threaded-bots)
* [Single-Threaded Bots](#single-threaded-bots)
* [Multi-Threaded Bots](#multi-threaded-bots)
* [Commands & Event Handlers](#commands--event-handlers)
* [Commands](#commands)
* [Event Handlers](#event-handlers)
* [License](#license)
<!-- TOC -->
@ -26,9 +36,278 @@ version is `4`. Library patches are used to fix bugs or add improvements in the
Telegram Bot API version.
## TODO
## Installation
Documentation will be redone
The library can be installed using ncc:
```bash
ncc package install -p "nosial/libs.tgbot=latest@n64"
```
or by adding the following to your project.json file under the `build.dependencies` section:
```json
{
"name": "net.nosial.tgbotlib",
"version": "latest",
"source_type": "remote",
"source": "nosial/libs.tgbot=latest@n64"
}
```
If you don't have the n64 source configured, you can add it by running the following command:
```bash
ncc source add --name n64 --type gitlab --host git.n64.cc
```
If you don't have ncc installed, you can refer to the [ncc documentation](https://git.n64.cc/nosial/ncc) for more
information on how to install it. See [Building NCC from source](https://git.n64.cc/nosial/ncc/-/blob/master/DOCUMENTATION.md#building-ncc-from-source)
and [Installing NCC](https://git.n64.cc/nosial/ncc/-/blob/master/DOCUMENTATION.md#installing-ncc) for more information.
## Compile from source
To compile the library from source, you need to have [ncc](https://git.n64.cc/nosial/ncc) installed, then run the
following command:
```bash
ncc build
```
## Requirements
The library requires PHP 8.0 or higher.
## Usage
1. Import the library using `import('net.nosial.tgbotlib');`
2. Create a new instance of the `TgBotLib\Bot` class, passing the bot token as the first argument
3. Profit
```php
require 'ncc';
import('net.nosial.tgbotlib');
$bot = new TgBotLib\Bot('<BOT TOKEN>');
/** @var \TgBotLib\Objects\Telegram\Update $update */
foreach ($bot->getUpdates() as $update)
{
$bot->sendMessage($update->getMessage()->getChat()->getId(), 'Hello World!');
}
```
Each method of the `TgBotLib\Bot` class is named after the corresponding method of the Telegram Bot API, all methods
contains an optional `$parameters` argument that can be used to pass additional parameters to the API method.
But for methods that has required parameters, the library provides a more convenient way to pass them, by using
named parameters. For example, the `sendMessage` method requires the `chat_id` and `text` parameters, but instead
of passing them as an array, you can pass them as named parameters:
```php
$bot->sendMessage(
chat_id: '<CHAT ID>',
text: 'Hello World!',
options: [
'parse_mode' => 'Markdown',
'disable_web_page_preview' => true,
]
);
```
## Documentation
Almost everything in the library has PhpDoc documentation, so you can use your IDE to get documentation for the
library. For example, in PhpStorm, you can press `Ctrl+Q` on a method to get the documentation for it:
![PhpStorm Documentation](assets/documentation.png)
## Single-Threaded & Multi-Threaded Bots
This part will explain how to implement single-threaded and multi-threaded bots using the library.
For more examples see the [tests](tests) directory.
### Single-Threaded Bots
To implement a single-threaded bot, it's very self-explanatory, you just need to create a new instance of the
`TgBotLib\Bot` class and use it to handle the updates:
```php
<?php
// Import ncc
require 'ncc';
import('net.nosial.tgbotlib');
// Require commands & event handlers
require 'commands' . DIRECTORY_SEPARATOR . 'StartCommand.php';
require 'commands' . DIRECTORY_SEPARATOR . 'HashCommand.php';
// Create a new instance of the bot
$bot = new TgBotLib\Bot(getenv('BOT_TOKEN'));
// Loop forever
while(true)
{
/** @var \TgBotLib\Objects\Telegram\Update $update */
foreach ($bot->getUpdates() as $update)
{
$bot->sendMessage($update->getMessage()->getChat()->getId(), 'Hello World!');
}
}
```
This approach is very simple and allows for easier debugging, but it's not recommended for production use, because
it will block the script until the updates are handled, and if the bot receives a lot of updates, it will take a
long time to handle them. So it's recommended to use a multithreaded approach for production bots.
### Multi-Threaded Bots
To implement a multi-threaded bot, you need to install [TamerLib](https://git.n64.cc/nosial/libs/tamer) which will allow
you to run parallel operations using a Message Server
First create a worker process that will handle the updates:
```php
<?php
// Import ncc
require 'ncc';
// Import packages
import('net.nosial.tgbotlib');
import('net.nosial.tamerlib');
// Require commands
require 'commands' . DIRECTORY_SEPARATOR . 'StartCommand.php';
require 'commands' . DIRECTORY_SEPARATOR . 'HashCommand.php';
// Initialize the bot
$bot = new TgBotLib\Bot('<BOT TOKEN>');
// Setup command handlers
$bot->setCommandHandler('start', new \commands\StartCommand());
$bot->setCommandHandler('hash', new \commands\HashCommand());
// Run TamerLib forever.
\TamerLib\tm::initialize(\TamerLib\Enums\TamerMode::WORKER);
\TamerLib\tm::addFunction('handle_update', [$bot, 'handleUpdate']);
\TamerLib\tm::run();
```
Then create a master process that will send the updates to the worker:
```php
<?php
// Import ncc
require 'ncc';
// Import packages
import('net.nosial.tgbotlib');
import('net.nosial.tamerlib');
$bot = new TgBotLib\Bot('<BOT TOKEN>');
\TamerLib\tm::initialize(\TamerLib\Enums\TamerMode::CLIENT);
\TamerLib\tm::createWorker(8, __DIR__ . DIRECTORY_SEPARATOR . 'worker.php');
// Handle updates forever
while(true)
{
// Get updates, push the update object to the worker
foreach ($bot->getUpdates() as $update)
{
\TamerLib\tm::dof('handle_update', [$update]);
}
\TamerLib\tm::wait(3);
}
```
## Commands & Event Handlers
Commands and event handlers are a way to handle commands and events sent by the user, for example, when the user
sends the `/start` command, you can send a welcome message to the user.
### Commands
The library provides a way to handle commands and events using the `TgBotLib\Bot` class, for example, to handle
the `/start` command, you can use the `setCommandHandler` method:
```php
<?php
require 'ncc';
import('net.nosial.tgbotlib');
$bot = new TgBotLib\Bot(getenv('BOT_TOKEN'));
$bot->setCommandHandler('start', new \commands\StartCommand());
```
The `setCommandHandler` method takes two arguments, the first being the command name (without the `/` prefix), and
the second being a class that implements the `TgBotLib\Interfaces\CommandInterface` interface.
The interface has only one method, `handle`, which takes two arguments, the first being an instance of the
`TgBotLib\Bot` class which is used to invoke the API without having to recreate the instance, and the second being
the update object. The update object is an instance of the `TgBotLib\Objects\Telegram\Update` class, which contains
all the information about the update.
```php
<?php
namespace commands;
use TgBotLib\Bot;
use TgBotLib\Interfaces\CommandInterface;
use TgBotLib\Objects\Telegram\Update;
class StartCommand extends CommandInterface
{
public function handle(Bot $bot, Update $update): void
{
$bot->sendMessage($update->getMessage()->getChat()->getId(), 'Hello World!');
}
}
```
### Event Handlers
Event handles are similarly implemented, but instead of using the `setCommandHandler` method, you use the
`setEventHandler` method:
```php
<?php
require __DIR__ . DIRECTORY_SEPARATOR . 'autoload.php';
$bot = new TgBotLib\Bot(getenv('BOT_TOKEN'));
$bot->setEventHandler('message', new \events\MessageEvent());
```
And the interface EventInterface is used instead of CommandInterface:
```php
<?php
namespace events;
use TgBotLib\Bot;
use TgBotLib\Interfaces\EventInterface;
use TgBotLib\Objects\Telegram\Update;
class MessageEvent implements EventInterface
{
public function handle(Bot $bot, Update $update): void
{
$bot->sendMessage($update->getMessage()->getChat()->getId(), 'Hello World!');
}
}
```
# License

View file

@ -1,14 +0,0 @@
<?php
require 'ncc';
$token_path = __DIR__ . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'token.txt';
if(!file_exists($token_path))
{
throw new Exception(sprintf('The token file "%s" does not exist.', $token_path));
}
define('BOT_TOKEN', trim(file_get_contents($token_path)));
const TEST_CHAT_ID = -1001301191379;
import('net.nosial.tgbotlib');

View file

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<phpdocumentor configVersion="3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://www.phpdoc.org" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/phpDocumentor/phpDocumentor/master/data/xsd/phpdoc.xsd">
<paths>
<output>build/docs</output>
<cache>build/cache</cache>
</paths>
<version number="latest">
<api>
<source dsn=".">
<path>src/TgBotLib</path>
</source>
<default-package-name>TgBotLib</default-package-name>
</api>
</version>
</phpdocumentor>

View file

@ -1,11 +0,0 @@
<phpunit bootstrap="bootstrap.php">
<testsuites>
<testsuite name="TgBotLib Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<php>
<ini name="error_reporting" value="-1"/>
<server name="KERNEL_DIR" value="app/"/>
</php>
</phpunit>

View file

@ -12,7 +12,7 @@
"package": "net.nosial.tgbotlib",
"description": "TgBotLib is a library for interacting with the Telegram Bot API",
"company": "Nosial",
"version": "8.0.2",
"version": "6.7.0",
"uuid": "b409e036-ab04-11ed-b32e-9d3f57a644ae"
},
"build": {
@ -30,68 +30,12 @@
"version": "latest",
"source_type": "remote",
"source": "nosial/libs.tempfile=latest@n64"
},
{
"name": "net.nosial.optslib",
"version": "latest",
"source_type": "remote",
"source": "nosial/libs.opts=latest@n64"
},
{
"name": "net.nosial.psynclib",
"version": "latest",
"source_type": "remote",
"source": "nosial/libs.psync=latest@n64"
}
],
"configurations": [
{
"name": "release",
"build_type": "ncc",
"output": "build/release/%ASSEMBLY.PACKAGE%.ncc"
},
{
"name": "release-compressed",
"build_type": "ncc",
"output": "build/release/%ASSEMBLY.PACKAGE%.gz.ncc",
"options": {
"compression": "high"
}
},
{
"name": "release-executable",
"build_type": "executable",
"output": "build/release/%ASSEMBLY.NAME%",
"options": {
"ncc_configuration": "release"
}
},
{
"name": "release-executable-compressed",
"build_type": "executable",
"output": "build/release/%ASSEMBLY.NAME%_gz",
"options": {
"ncc_configuration": "release-compressed"
}
},
{
"name": "debug",
"build_type": "ncc",
"output": "build/debug/%ASSEMBLY.PACKAGE%.ncc",
"define_constants": {
"DEBUG": "1"
}
},
{
"name": "debug-compressed",
"build_type": "ncc",
"output": "build/debug/%ASSEMBLY.PACKAGE%.gz.ncc",
"define_constants": {
"DEBUG": "1"
},
"options": {
"compression": "high"
}
"output_path": "build/release"
}
]
}

View file

@ -1,153 +0,0 @@
<?php
namespace TgBotLib\Abstracts;
use CURLFile;
use CurlHandle;
use InvalidArgumentException;
use TgBotLib\Bot;
use TgBotLib\Exceptions\TelegramException;
use TgBotLib\Interfaces\ObjectTypeInterface;
abstract class Method
{
/**
* Executes a bot command with the given parameters.
*
* @param Bot $bot The bot instance on which the command is to be executed.
* @param array $parameters The parameters required for the bot command.
* @return ObjectTypeInterface|ObjectTypeInterface[]|mixed The result of the bot command.
* @throws TelegramException if the response from the bot command is not valid.
* @throws InvalidArgumentException if the required parameters are not provided.
*/
public abstract static function execute(Bot $bot, array $parameters=[]): mixed;
/**
* Retrieves a list of required parameters for a specific operation.
*
* @return array|null An array of required parameters.
*/
public abstract static function getRequiredParameters(): ?array;
/**
* Retrieves the optional parameters for a request.
*
* @return array|null An array of optional parameters.
*/
public abstract static function getOptionalParameters(): ?array;
/**
* Builds a cURL handle for making a POST request to a bot's endpoint.
*
* @param Bot $bot The bot object containing the endpoint information.
* @param string $method
* @param array|null $parameters An array of parameters to be sent in the POST request.
* @return CurlHandle The configured cURL handle ready for execution.
*/
protected static function buildPost(Bot $bot, string $method, ?array $parameters = null): CurlHandle {
$curl = curl_init(sprintf('%s/bot%s/%s', $bot->getEndpoint(), $bot->getToken(), $method));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
if ($parameters === null)
{
curl_setopt($curl, CURLOPT_POST, false);
}
else
{
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($parameters));
}
return $curl;
}
/**
* Builds a cURL handle for uploading a file to the Telegram API.
*
* @param Bot $bot The bot instance used to get the endpoint.
* @param string $file_param The parameter name for the file to be uploaded.
* @param string $file_path The file path of the file to be uploaded.
* @param array $parameters Additional parameters to be included in the request.
* @return CurlHandle The cURL handle configured for the file upload.
*/
protected static function buildUpload(Bot $bot, string $method, string $file_param, string $file_path, array $parameters): CurlHandle
{
$curl = curl_init(sprintf('%s/bot%s/%s', $bot->getEndpoint(), $bot->getToken(), $method));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: multipart/form-data']);
// Merge file with other parameters
$parameters[$file_param] = new CURLFile($file_path);
curl_setopt($curl, CURLOPT_POSTFIELDS, $parameters);
return $curl;
}
/**
* Builds a cURL handle for a multi-part file upload request to a bot API.
*
* @param Bot $bot The bot instance to configure the request for.
* @param string $method The API method to call.
* @param array $files An associative array of parameter names and file paths to upload.
* @param array $parameters An associative array of additional parameters for the request.
* @return CurlHandle The configured cURL handle.
*/
protected static function buildMultiUpload(Bot $bot, string $method, array $files, array $parameters): CurlHandle
{
$curl = curl_init(sprintf('%s/bot%s/%s', $bot->getEndpoint(), $bot->getToken(), $method));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: multipart/form-data']);
$postFields = [];
foreach ($files as $param => $file)
{
$postFields[$param] = new CURLFile($file);
}
foreach ($parameters as $key => $value)
{
$postFields[$key] = $value;
}
curl_setopt($curl, CURLOPT_POSTFIELDS, $postFields);
return $curl;
}
/**
* Executes a cURL request and processes the response.
*
* @param CurlHandle $curl The cURL handle to be executed.
* @return array The decoded response from the cURL request.
* @throws TelegramException if the response is not a valid array,
* or if the 'ok' field is not set or is false.
*/
protected static function executeCurl(CurlHandle $curl): mixed
{
$response = curl_exec($curl);
curl_close($curl);
$result = json_decode($response, true);
if(!is_array($result))
{
throw new TelegramException('Invalid response from Telegram API');
}
if(!isset($result['ok']))
{
throw new TelegramException('Invalid response from Telegram API');
}
if($result['ok'] === false)
{
throw new TelegramException($result['description'], (int)$result['error_code']);
}
return $result['result'];
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,28 +0,0 @@
<?php
namespace TgBotLib\Classes;
use LogLib\Log;
class Logger
{
private static ?\LogLib\Logger $logger = null;
/**
* Retrieves the instance of the logger. If the logger instance does not
* exist, it initializes a new logger for the application and registers
* the exception handler.
*
* @return \LogLib\Logger The logger instance.
*/
public static function getLogger(): \LogLib\Logger
{
if(self::$logger === null)
{
self::$logger = new \LogLib\Logger('net.nosial.tgbotlib');
Log::registerExceptionHandler();
}
return self::$logger;
}
}

View file

@ -1,5 +1,6 @@
<?php
/** @noinspection PhpMissingFieldTypeInspection */
namespace TgBotLib\Classes;
@ -12,15 +13,14 @@
/**
* @var Currency[]|null
*/
private static ?array $currencies_cache = null;
private static $currencies_cache;
/**
* Retrieves the currency object associated with the given currency code.
* Returns
*
* @param string $code The currency code to look up.
* @return Currency The currency object corresponding to the given code.
* @throws Exception If the currency code is not found or fetching currencies fails.
* @deprecated Not used
* @param string $code
* @return Currency
* @throws Exception
*/
public static function getCurrency(string $code): Currency
{
@ -44,9 +44,7 @@
}
if(!isset(self::$currencies_cache[strtolower($code)]))
{
throw new Exception("Currency $code not found");
}
return self::$currencies_cache[strtolower($code)];
}

View file

@ -0,0 +1,14 @@
<?php
namespace TgBotLib\Enums;
final class BotCommandScopeType
{
public const DEFAULT = 'default';
public const ALL_PRIVATE_CHATS = 'all_private_chats';
public const ALL_CHAT_GROUPS = 'all_group_chats';
public const ALL_CHAT_ADMINISTRATORS = 'all_chat_administrators';
public const CHAT = 'chat';
public const CHAT_ADMINISTRATORS = 'chat_administrators';
public const CHAT_MEMBER = 'chat_member';
}

View file

@ -0,0 +1,17 @@
<?php
namespace TgBotLib\Enums;
final class ChatActionType
{
public const TYPING = 'typing';
public const UPLOAD_PHOTO = 'upload_photo';
public const RECORD_VIDEO = 'record_video';
public const UPLOAD_VIDEO = 'upload_video';
public const RECORD_AUDIO = 'record_audio';
public const UPLOAD_AUDIO = 'upload_audio';
public const UPLOAD_DOCUMENT = 'upload_document';
public const FIND_LOCATION = 'find_location';
public const RECORD_VIDEO_NOTE = 'record_video_note';
public const UPLOAD_VIDEO_NOTE = 'upload_video_note';
}

View file

@ -0,0 +1,13 @@
<?php
namespace TgBotLib\Enums;
final class ChatMemberStatus
{
public const CREATOR = 'creator';
public const ADMINISTRATOR = 'administrator';
public const MEMBER = 'member';
public const RESTRICTED = 'restricted';
public const LEFT = 'left';
public const KICKED = 'kicked';
}

View file

@ -0,0 +1,11 @@
<?php
namespace TgBotLib\Enums;
final class ChatType
{
public const PRIVATE = 'private';
public const GROUP = 'group';
public const SUPERGROUP = 'supergroup';
public const CHANNEL = 'channel';
}

View file

@ -2,179 +2,42 @@
namespace TgBotLib\Enums;
use TgBotLib\Events\BusinessConnectionEvent;
use TgBotLib\Events\BusinessMessageEvent;
use TgBotLib\Events\CallbackQueryEvent;
use TgBotLib\Events\ChannelPostEvent;
use TgBotLib\Events\ChatBoostEvent;
use TgBotLib\Events\ChatJoinRequestEvent;
use TgBotLib\Events\ChatMemberUpdatedEvent;
use TgBotLib\Events\ChosenInlineResultEvent;
use TgBotLib\Events\CommandEvent;
use TgBotLib\Events\DeletedBusinessMessagesEvent;
use TgBotLib\Events\EditedBusinessMessageEvent;
use TgBotLib\Events\EditedChannelPostEvent;
use TgBotLib\Events\EditedMessageEvent;
use TgBotLib\Events\InlineQueryEvent;
use TgBotLib\Events\MessageEvent;
use TgBotLib\Events\MessageReactionCountEvent;
use TgBotLib\Events\MessageReactionEvent;
use TgBotLib\Events\MyChatMemberUpdatedEvent;
use TgBotLib\Events\PaidMediaPurchasedEvent;
use TgBotLib\Events\PollAnswerEvent;
use TgBotLib\Events\PollEvent;
use TgBotLib\Events\PreCheckoutQueryEvent;
use TgBotLib\Events\RemovedChatBoostEvent;
use TgBotLib\Events\ShippingQueryEvent;
use TgBotLib\Events\UpdateEvent;
use TgBotLib\Objects\Update;
enum EventType : string
final class EventType
{
case UPDATE_EVENT = UpdateEvent::class;
case REMOVED_CHAT_BOOST_EVENT = RemovedChatBoostEvent::class;
case CHAT_BOOST_EVENT = ChatBoostEvent::class;
case CHAT_JOIN_REQUEST_EVENT = ChatJoinRequestEvent::class;
case CHAT_MEMBER_UPDATED = ChatMemberUpdatedEvent::class;
case MY_CHAT_MEMBER_UPDATED = MyChatMemberUpdatedEvent::class;
case POLL_ANSWER = PollAnswerEvent::class;
case POLL = PollEvent::class;
case PAID_MEDIA_PURCHASED = PaidMediaPurchasedEvent::class;
case PRE_CHECKOUT_QUERY = PreCheckoutQueryEvent::class;
case SHIPPING_QUERY = ShippingQueryEvent::class;
case CALLBACK_QUERY = CallbackQueryEvent::class;
case CHOSEN_INLINE_RESULT = ChosenInlineResultEvent::class;
case INLINE_QUERY = InlineQueryEvent::class;
case MESSAGE_REACTION_COUNT = MessageReactionCountEvent::class;
case MESSAGE_REACTION = MessageReactionEvent::class;
case DELETED_BUSINESS_MESSAGES = DeletedBusinessMessagesEvent::class;
case EDITED_BUSINESS_MESSAGE = EditedBusinessMessageEvent::class;
case BUSINESS_MESSAGE = BusinessMessageEvent::class;
case BUSINESS_CONNECTION = BusinessConnectionEvent::class;
case EDITED_CHANNEL_POST = EditedChannelPostEvent::class;
case CHANNEL_POST = ChannelPostEvent::class;
case EDITED_MESSAGE = EditedMessageEvent::class;
case MESSAGE = MessageEvent::class;
case COMMAND = CommandEvent::class;
public const GENERIC_UPDATE = 'generic_update';
public const MESSAGE = 'message';
public const EDITED_MESSAGE = 'edited_message';
public const GENERIC_COMMAND_MESSAGE = 'generic_command_message';
public const CHAT_MEMBER_JOINED = 'chat_member_joined';
public const CHAT_MEMBER_LEFT = 'chat_member_left';
public const CHAT_MEMBER_KICKED = 'chat_member_kicked';
public const CHAT_MEMBER_BANNED = 'chat_member_banned';
public const CHAT_MEMBER_UNBANNED = 'chat_member_unbanned';
public const CHAT_MEMBER_PROMOTED = 'chat_member_promoted';
public const CHAT_MEMBER_DEMOTED = 'chat_member_demoted';
public const CHAT_MEMBER_RESTRICTED = 'chat_member_restricted';
public const CHAT_MEMBER_UNRESTRICTED = 'chat_member_unrestricted';
public const CHAT_TITLE_CHANGED = 'chat_title_changed';
public const CHAT_PHOTO_CHANGED = 'chat_photo_changed';
public const CALLBACK_QUERY = 'callback_query';
/**
* Determines the type of event based on the provided Update object.
*
* @param Update $update The update object containing event details.
* @return EventType The type of event detected from the update.
*/
public static function determineEventType(Update $update): EventType
{
if($update->getRemovedChatBoost() !== null)
{
return EventType::REMOVED_CHAT_BOOST_EVENT;
}
public const All = [
self::GENERIC_UPDATE,
self::MESSAGE,
self::EDITED_MESSAGE,
self::GENERIC_COMMAND_MESSAGE,
self::CHAT_MEMBER_JOINED,
self::CHAT_MEMBER_LEFT,
self::CHAT_MEMBER_KICKED,
self::CHAT_MEMBER_BANNED,
self::CHAT_MEMBER_UNBANNED,
self::CHAT_MEMBER_PROMOTED,
self::CHAT_MEMBER_DEMOTED,
self::CHAT_MEMBER_RESTRICTED,
self::CHAT_MEMBER_UNRESTRICTED,
self::CHAT_TITLE_CHANGED,
self::CHAT_PHOTO_CHANGED,
self::CALLBACK_QUERY,
];
if($update->getChatBoost() !== null)
{
return EventType::CHAT_BOOST_EVENT;
}
if($update->getChatJoinRequest() !== null)
{
return EventType::CHAT_JOIN_REQUEST_EVENT;
}
if($update->getChatMember() !== null)
{
return EventType::CHAT_MEMBER_UPDATED;
}
if($update->getMyChatMember() !== null)
{
return EventType::MY_CHAT_MEMBER_UPDATED;
}
if($update->getPollAnswer() !== null)
{
return EventType::POLL_ANSWER;
}
if($update->getPoll() !== null)
{
return EventType::POLL;
}
if($update->getPurchasedPaidMedia() !== null)
{
return EventType::PAID_MEDIA_PURCHASED;
}
if($update->getPreCheckoutQuery() !== null)
{
return EventType::PRE_CHECKOUT_QUERY;
}
if($update->getShippingQuery() !== null)
{
return EventType::SHIPPING_QUERY;
}
if($update->getChosenInlineResult() !== null)
{
return EventType::CHOSEN_INLINE_RESULT;
}
if($update->getInlineQuery() !== null)
{
return EventType::INLINE_QUERY;
}
if($update->getMessageReactionCount() !== null)
{
return EventType::MESSAGE_REACTION_COUNT;
}
if($update->getMessageReaction() !== null)
{
return EventType::MESSAGE_REACTION;
}
if($update->getDeletedBusinessMessages() !== null)
{
return EventType::DELETED_BUSINESS_MESSAGES;
}
if($update->getEditedBusinessMessage() !== null)
{
return EventType::EDITED_BUSINESS_MESSAGE;
}
if($update->getBusinessMessage() !== null)
{
return EventType::BUSINESS_MESSAGE;
}
if($update->getBusinessConnection() !== null)
{
return EventType::BUSINESS_CONNECTION;
}
if($update->getEditedChannelPost() !== null)
{
return EventType::EDITED_CHANNEL_POST;
}
if($update->getChannelPost() !== null)
{
return EventType::CHANNEL_POST;
}
if($update->getEditedMessage() !== null)
{
return EventType::EDITED_MESSAGE;
}
if($update->getMessage() !== null)
{
return EventType::MESSAGE;
}
return EventType::UPDATE_EVENT;
}
}
}

View file

@ -1,66 +1,81 @@
<?php
namespace TgBotLib\Enums\Types;
namespace TgBotLib\Enums;
enum InlineQueryResultType : string
final class InlineQueryResultType
{
/**
* @link https://core.telegram.org/bots/api#inlinequeryresultarticle
*/
case ARTICLE = 'article';
public const ARTICLE = 'article';
/**
* @link https://core.telegram.org/bots/api#inlinequeryresultphoto
*/
case PHOTO = 'photo';
public const PHOTO = 'photo';
/**
* @link https://core.telegram.org/bots/api#inlinequeryresultgif
*/
case GIF = 'gif';
public const GIF = 'gif';
/**
* @link https://core.telegram.org/bots/api#inlinequeryresultmpeg4gif
*/
case MPEG_4_GIF = 'mpeg4_gif';
public const MPEG_4_GIF = 'mpeg4_gif';
/**
* @link https://core.telegram.org/bots/api#inlinequeryresultvideompeg4
*/
case VIDEO = 'video';
public const VIDEO = 'video';
/**
* @link https://core.telegram.org/bots/api#inlinequeryresultaudio
*/
case AUDIO = 'audio';
public const AUDIO = 'audio';
/**
* @link https://core.telegram.org/bots/api#inlinequeryresultvoice
*/
case VOICE = 'voice';
public const VOICE = 'voice';
/**
* @link https://core.telegram.org/bots/api#inlinequeryresultdocument
*/
case DOCUMENT = 'document';
public const DOCUMENT = 'document';
/**
* @link https://core.telegram.org/bots/api#inlinequeryresultlocation
*/
case LOCATION = 'location';
public const LOCATION = 'location';
/**
* @link https://core.telegram.org/bots/api#inlinequeryresultvenue
*/
case VENUE = 'venue';
public const VENUE = 'venue';
/**
* @link https://core.telegram.org/bots/api#inlinequeryresultcontact
*/
case CONTACT = 'contact';
public const CONTACT = 'contact';
/**
* @link https://core.telegram.org/bots/api#inlinequeryresultgame
*/
case GAME = 'game';
public const GAME = 'game';
public const ALL = [
self::ARTICLE,
self::PHOTO,
self::GIF,
self::MPEG_4_GIF,
self::VIDEO,
self::AUDIO,
self::VOICE,
self::DOCUMENT,
self::LOCATION,
self::VENUE,
self::CONTACT,
self::GAME,
];
}

View file

@ -0,0 +1,12 @@
<?php
namespace TgBotLib\Enums;
final class InputMediaType
{
public const PHOTO = 'photo';
public const VIDEO = 'video';
public const ANIMATION = 'animation';
public const AUDIO = 'audio';
public const DOCUMENT = 'document';
}

View file

@ -0,0 +1,10 @@
<?php
namespace TgBotLib\Enums;
final class MenuButtonType
{
public const COMMANDS = 'commands';
public const WEB_APP = 'web_app';
public const DEFAULT = 'default';
}

View file

@ -0,0 +1,41 @@
<?php
namespace TgBotLib\Enums;
final class MessageEntityType
{
public const MENTION = 'mention';
public const HASHTAG = 'hashtag';
public const CASHTAG = 'cashtag';
public const BOT_COMMAND = 'bot_command';
public const URL = 'url';
public const EMAIL = 'email';
public const PHONE_NUMBER = 'phone_number';
public const BOLD = 'bold';
public const ITALIC = 'italic';
public const UNDERLINE = 'underline';
public const STRIKETHROUGH = 'strikethrough';
public const SPOILER = 'spoiler';
public const CODE = 'code';
public const PRE = 'pre';
public const TEXT_LINK = 'text_link';
public const TEXT_MENTION = 'text_mention';
public const CUSTOM_EMOJI = 'custom_emoji';
}

View file

@ -1,407 +0,0 @@
<?php
namespace TgBotLib\Enums;
use TgBotLib\Bot;
use TgBotLib\Exceptions\TelegramException;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Methods\AddStickerToSet;
use TgBotLib\Methods\AnswerCallbackQuery;
use TgBotLib\Methods\AnswerInlineQuery;
use TgBotLib\Methods\AnswerPreCheckoutQuery;
use TgBotLib\Methods\AnswerShippingQuery;
use TgBotLib\Methods\AnswerWebAppQuery;
use TgBotLib\Methods\ApproveChatJoinRequest;
use TgBotLib\Methods\BanChatMember;
use TgBotLib\Methods\BanChatSenderChat;
use TgBotLib\Methods\Close;
use TgBotLib\Methods\CloseForumTopic;
use TgBotLib\Methods\CloseGeneralForumTopic;
use TgBotLib\Methods\CopyMessage;
use TgBotLib\Methods\CopyMessages;
use TgBotLib\Methods\CreateChatInviteLink;
use TgBotLib\Methods\CreateChatSubscriptionInviteLink;
use TgBotLib\Methods\CreateForumTopic;
use TgBotLib\Methods\CreateInvoiceLink;
use TgBotLib\Methods\CreateNewStickerSet;
use TgBotLib\Methods\DeclineChatJoinRequest;
use TgBotLib\Methods\DeleteChatPhoto;
use TgBotLib\Methods\DeleteChatStickerSet;
use TgBotLib\Methods\DeleteForumTopic;
use TgBotLib\Methods\DeleteMessage;
use TgBotLib\Methods\DeleteMessages;
use TgBotLib\Methods\DeleteMyCommands;
use TgBotLib\Methods\DeleteStickerFromSet;
use TgBotLib\Methods\DeleteStickerSet;
use TgBotLib\Methods\DeleteWebhook;
use TgBotLib\Methods\EditChatInviteLink;
use TgBotLib\Methods\EditChatSubscriptionInviteLink;
use TgBotLib\Methods\EditForumTopic;
use TgBotLib\Methods\EditGeneralForumTopic;
use TgBotLib\Methods\EditMessageCaption;
use TgBotLib\Methods\EditMessageLiveLocation;
use TgBotLib\Methods\EditMessageMedia;
use TgBotLib\Methods\EditMessageReplyMarkup;
use TgBotLib\Methods\EditMessageText;
use TgBotLib\Methods\ExportChatInviteLink;
use TgBotLib\Methods\ForwardMessage;
use TgBotLib\Methods\ForwardMessages;
use TgBotLib\Methods\GetAvailableGifts;
use TgBotLib\Methods\GetBusinessConnection;
use TgBotLib\Methods\GetChat;
use TgBotLib\Methods\GetChatAdministrators;
use TgBotLib\Methods\GetChatMember;
use TgBotLib\Methods\GetChatMemberCount;
use TgBotLib\Methods\GetChatMenuButton;
use TgBotLib\Methods\GetCustomEmojiStickers;
use TgBotLib\Methods\GetFile;
use TgBotLib\Methods\GetForumTopicIconStickers;
use TgBotLib\Methods\GetGameHighScores;
use TgBotLib\Methods\GetMe;
use TgBotLib\Methods\GetMyCommands;
use TgBotLib\Methods\GetMyDefaultAdministratorRights;
use TgBotLib\Methods\GetMyDescription;
use TgBotLib\Methods\GetMyName;
use TgBotLib\Methods\GetMyShortDescription;
use TgBotLib\Methods\GetStarTransactions;
use TgBotLib\Methods\GetStickerSet;
use TgBotLib\Methods\GetUpdates;
use TgBotLib\Methods\GetUserChatBoosts;
use TgBotLib\Methods\GetUserProfilePhotos;
use TgBotLib\Methods\GetWebhookInfo;
use TgBotLib\Methods\HideGeneralForumTopic;
use TgBotLib\Methods\LeaveChat;
use TgBotLib\Methods\Logout;
use TgBotLib\Methods\PinChatMessage;
use TgBotLib\Methods\PromoteChatMember;
use TgBotLib\Methods\ReopenForumTopic;
use TgBotLib\Methods\ReopenGeneralForumTopic;
use TgBotLib\Methods\ReplaceStickerInSet;
use TgBotLib\Methods\RestrictChatMember;
use TgBotLib\Methods\RevokeChatInviteLink;
use TgBotLib\Methods\SavePreparedInlineMessage;
use TgBotLib\Methods\SendAnimation;
use TgBotLib\Methods\SendAudio;
use TgBotLib\Methods\SendChatAction;
use TgBotLib\Methods\SendContact;
use TgBotLib\Methods\SendDice;
use TgBotLib\Methods\SendDocument;
use TgBotLib\Methods\SendGame;
use TgBotLib\Methods\SendGift;
use TgBotLib\Methods\SendInvoice;
use TgBotLib\Methods\SendLocation;
use TgBotLib\Methods\SendMediaGroup;
use TgBotLib\Methods\SendMessage;
use TgBotLib\Methods\SendPaidMedia;
use TgBotLib\Methods\SendPhoto;
use TgBotLib\Methods\SendPoll;
use TgBotLib\Methods\SendSticker;
use TgBotLib\Methods\SendVenue;
use TgBotLib\Methods\SendVideo;
use TgBotLib\Methods\SendVideoNote;
use TgBotLib\Methods\SendVoice;
use TgBotLib\Methods\SetChatAdministratorCustomTitle;
use TgBotLib\Methods\SetChatDescription;
use TgBotLib\Methods\SetChatMenuButton;
use TgBotLib\Methods\SetChatPermissions;
use TgBotLib\Methods\SetChatPhoto;
use TgBotLib\Methods\SetChatStickerSet;
use TgBotLib\Methods\SetChatTitle;
use TgBotLib\Methods\SetCustomEmojiStickerSetThumbnail;
use TgBotLib\Methods\SetGameScore;
use TgBotLib\Methods\SetMessageReaction;
use TgBotLib\Methods\SetMyCommands;
use TgBotLib\Methods\SetMyDefaultAdministratorRights;
use TgBotLib\Methods\SetMyDescription;
use TgBotLib\Methods\SetMyName;
use TgBotLib\Methods\SetMyShortDescription;
use TgBotLib\Methods\SetPassportDataErrors;
use TgBotLib\Methods\SetStickerEmojiList;
use TgBotLib\Methods\SetStickerMaskPosition;
use TgBotLib\Methods\SetStickerPositionInSet;
use TgBotLib\Methods\SetStickerSetThumbnail;
use TgBotLib\Methods\SetStickerSetTitle;
use TgBotLib\Methods\SetWebhook;
use TgBotLib\Methods\StopMessageLiveLocation;
use TgBotLib\Methods\StopPoll;
use TgBotLib\Methods\UnbanChatMember;
use TgBotLib\Methods\UnbanChatSenderChat;
use TgBotLib\Methods\UnhideGeneralForumTopic;
use TgBotLib\Methods\UnpinAllChatMessages;
use TgBotLib\Methods\UnpinAllForumTopicMessages;
use TgBotLib\Methods\UnpinAllGeneralForumTopicMessages;
use TgBotLib\Methods\UnpinChatMessage;
use TgBotLib\Methods\UploadStickerFile;
enum Methods : string
{
case GET_UPDATES = 'getUpdates';
case SET_WEBHOOK = 'setWebhook';
case DELETE_WEBHOOK = 'deleteWebhook';
case GET_WEBHOOK_INFO = 'getWebhookInfo';
case GET_ME = 'getMe';
case LOGOUT = 'logOut';
case CLOSE = 'close';
case SEND_MESSAGE = 'sendMessage';
case FORWARD_MESSAGE = 'forwardMessage';
case FORWARD_MESSAGES = 'forwardMessages';
case COPY_MESSAGE = 'copyMessage';
case COPY_MESSAGES = 'copyMessages';
case SEND_PHOTO = 'sendPhoto';
case SEND_AUDIO = 'sendAudio';
case SEND_DOCUMENT = 'sendDocument';
case SEND_VIDEO = 'sendVideo';
case SEND_ANIMATION = 'sendAnimation';
case SEND_VOICE = 'sendVoice';
case SEND_VIDEO_NOTE = 'sendVideoNote';
case SEND_PAID_MEDIA = 'sendPaidMedia';
case SEND_MEDIA_GROUP = 'sendMediaGroup';
case SEND_LOCATION = 'sendLocation';
case SEND_VENUE = 'sendVenue';
case SEND_CONTACT = 'sendContact';
case SEND_POLL = 'sendPoll';
case SEND_DICE = 'sendDice';
case SEND_CHAT_ACTION = 'sendChatAction';
case SET_MESSAGE_REACTION = 'setMessageReaction';
case GET_USER_PROFILE_PHOTOS = 'getUserProfilePhotos';
case GET_FILE = 'getFile';
case BAN_CHAT_MEMBER = 'banChatMember';
case UNBAN_CHAT_MEMBER = 'unbanChatMember';
case RESTRICT_CHAT_MEMBER = 'restrictChatMember';
case PROMOTE_CHAT_MEMBER = 'promoteChatMember';
case SET_CHAT_ADMINISTRATOR_CUSTOM_TITLE = 'setChatAdministratorCustomTitle';
case BAN_CHAT_SENDER_CHAT = 'banChatSenderChat';
case UNBAN_CHAT_SENDER_CHAT = 'unbanChatSenderChat';
case SET_CHAT_PERMISSIONS = 'setChatPermissions';
case EXPORT_CHAT_INVITE_LINK = 'exportChatInviteLink';
case CREATE_CHAT_INVITE_LINK = 'createChatInviteLink';
case EDIT_CHAT_INVITE_LINK = 'editChatInviteLink';
case CREATE_CHAT_SUBSCRIPTION_INVITE_LINK = 'createChatSubscriptionInviteLink';
case EDIT_CHAT_SUBSCRIPTION_INVITE_LINK = 'editChatSubscriptionInviteLink';
case REVOKE_CHAT_INVITE_LINK = 'revokeChatInviteLink';
case APPROVE_CHAT_JOIN_REQUEST = 'approveChatJoinRequest';
case DECLINE_CHAT_JOIN_REQUEST = 'declineChatJoinRequest';
case SET_CHAT_PHOTO = 'setChatPhoto';
case DELETE_CHAT_PHOTO = 'deleteChatPhoto';
case SET_CHAT_TITLE = 'setChatTitle';
case SET_CHAT_DESCRIPTION = 'setChatDescription';
case PIN_CHAT_MESSAGE = 'pinChatMessage';
case UNPIN_CHAT_MESSAGE = 'unpinChatMessage';
case UNPIN_ALL_CHAT_MESSAGES = 'unpinAllChatMessages';
case LEAVE_CHAT = 'leaveChat';
case GET_CHAT = 'getChat';
case GET_CHAT_ADMINISTRATORS = 'getChatAdministrators';
case GET_CHAT_MEMBER_COUNT = 'getChatMemberCount';
case GET_CHAT_MEMBER = 'getChatMember';
case SET_CHAT_STICKER_SET = 'setChatStickerSet';
case DELETE_CHAT_STICKER_SET = 'deleteChatStickerSet';
case GET_FORUM_TOPIC_ICON_STICKERS = 'getForumTopicIconStickers';
case CREATE_FORUM_TOPIC = 'createForumTopic';
case EDIT_FORUM_TOPIC = 'editForumTopic';
case CLOSE_FORUM_TOPIC = 'closeForumTopic';
case REOPEN_FORUM_TOPIC = 'reopenForumTopic';
case DELETE_FORUM_TOPIC = 'deleteForumTopic';
case UNPIN_ALL_FORUM_TOPIC_MESSAGES = 'unpinAllForumTopicMessages';
case EDIT_GENERAL_FORUM_TOPIC = 'editGeneralForumTopic';
case CLOSE_GENERAL_FORUM_TOPIC = 'closeGeneralForumTopic';
case REOPEN_GENERAL_FORUM_TOPIC = 'reopenGeneralForumTopic';
case HIDE_GENERAL_FORUM_TOPIC = 'hideGeneralForumTopic';
case UNHIDE_GENERAL_FORUM_TOPIC = 'unhideGeneralForumTopic';
case UNPIN_ALL_GENERAL_FORUM_TOPIC_MESSAGES = 'unpinAllGeneralForumTopicMessages';
case ANSWER_CALLBACK_QUERY = 'answerCallbackQuery';
case GET_USER_CHAT_BOOSTS = 'getUserChatBoosts';
case GET_BUSINESS_CONNECTION = 'getBusinessConnection';
case SET_MY_COMMANDS = 'setMyCommands';
case DELETE_MY_COMMANDS = 'deleteMyCommands';
case GET_MY_COMMANDS = 'getMyCommands';
case SET_MY_NAME = 'setMyName';
case GET_MY_NAME = 'getMyName';
case SET_MY_DESCRIPTION = 'setMyDescription';
case GET_MY_DESCRIPTION = 'getMyDescription';
case SET_MY_SHORT_DESCRIPTION = 'setMyShortDescription';
case GET_MY_SHORT_DESCRIPTION = 'getMyShortDescription';
case SET_CHAT_MENU_BUTTON = 'setChatMenuButton';
case GET_CHAT_MENU_BUTTON = 'getChatMenuButton';
case SET_MY_DEFAULT_ADMINISTRATOR_RIGHTS = 'setMyDefaultAdministratorRights';
case GET_MY_DEFAULT_ADMINISTRATOR_RIGHTS = 'getMyDefaultAdministratorRights';
case EDIT_MESSAGE_TEXT = 'editMessageText';
case EDIT_MESSAGE_CAPTION = 'editMessageCaption';
case EDIT_MESSAGE_MEDIA = 'editMessageMedia';
case EDIT_MESSAGE_LIVE_LOCATION = 'editMessageLiveLocation';
case STOP_MESSAGE_LIVE_LOCATION = 'stopMessageLiveLocation';
case EDIT_MESSAGE_REPLY_MARKUP = 'editMessageReplyMarkup';
case STOP_POLL = 'stopPoll';
case DELETE_MESSAGE = 'deleteMessage';
case DELETE_MESSAGES = 'deleteMessages';
case SEND_STICKER = 'sendSticker';
case GET_STICKER_SET = 'getStickerSet';
case GET_CUSTOM_EMOJI_STICKERS = 'getCustomEmojiStickers';
case UPLOAD_STICKER_FILE = 'uploadStickerFile';
case CREATE_NEW_STICKER_SET = 'createNewStickerSet';
case ADD_STICKER_TO_SET = 'addStickerToSet';
case SET_STICKER_POSITION_IN_SET = 'setStickerPositionInSet';
case DELETE_STICKER_FROM_SET = 'deleteStickerFromSet';
case REPLACE_STICKER_IN_SET = 'replaceStickerInSet';
case SET_STICKER_EMOJI_LIST = 'setStickerEmojiList';
case SET_STICKER_MASK_POSITION = 'setStickerMaskPosition';
case SET_STICKER_SET_TITLE = 'setStickerSetTitle';
case SET_STICKER_SET_THUMBNAIL = 'setStickerSetThumbnail';
case SET_CUSTOM_EMOJI_STICKER_SET_THUMBNAIL = 'setCustomEmojiStickerSetThumbnail';
case DELETE_STICKER_SET = 'deleteStickerSet';
case GET_AVAILABLE_GIFTS = 'getAvailableGifts';
case SEND_GIFT = 'sendGift';
case ANSWER_INLINE_QUERY = 'answerInlineQuery';
case ANSWER_WEB_APP_QUERY = 'answerWebAppQuery';
case SAVE_PREPARED_INLINE_MESSAGE = 'savePreparedInlineMessage';
case SEND_INVOICE = 'sendInvoice';
case CREATE_INVOICE_LINK = 'createInvoiceLink';
case ANSWER_SHIPPING_QUERY = 'answerShippingQuery';
case ANSWER_PRE_CHECKOUT_QUERY = 'answerPreCheckoutQuery';
case GET_STAR_TRANSACTIONS = 'getStarTransactions';
case SET_PASSPORT_DATA_ERRORS = 'setPassportDataErrors';
case SEND_GAME = 'sendGame';
case SET_GAME_SCORE = 'setGameScore';
case GET_GAME_HIGH_SCORES = 'getGameHighScores';
/**
* Executes a command on the provided bot with the given parameters.
*
* @param Bot $bot The bot instance on which the command will be executed.
* @param array $parameters Optional parameters for the command.
* @return ObjectTypeInterface|mixed The result of the command execution, varies based on the command.
* @throws TelegramException if the command execution fails.
*/
public function execute(Bot $bot, array $parameters=[]): mixed
{
return match($this)
{
self::GET_UPDATES => GetUpdates::execute($bot, $parameters),
self::SET_WEBHOOK => SetWebhook::execute($bot, $parameters),
self::DELETE_WEBHOOK => DeleteWebhook::execute($bot, $parameters),
self::GET_WEBHOOK_INFO => GetWebhookInfo::execute($bot, $parameters),
self::GET_ME => GetMe::execute($bot, $parameters),
self::LOGOUT => LogOut::execute($bot, $parameters),
self::CLOSE => Close::execute($bot, $parameters),
self::SEND_MESSAGE => SendMessage::execute($bot, $parameters),
self::FORWARD_MESSAGE => ForwardMessage::execute($bot, $parameters),
self::FORWARD_MESSAGES => ForwardMessages::execute($bot, $parameters),
self::COPY_MESSAGE => CopyMessage::execute($bot, $parameters),
self::COPY_MESSAGES => CopyMessages::execute($bot, $parameters),
self::SEND_PHOTO => SendPhoto::execute($bot, $parameters),
self::SEND_AUDIO => SendAudio::execute($bot, $parameters),
self::SEND_DOCUMENT => SendDocument::execute($bot, $parameters),
self::SEND_VIDEO => SendVideo::execute($bot, $parameters),
self::SEND_ANIMATION => SendAnimation::execute($bot, $parameters),
self::SEND_VOICE => SendVoice::execute($bot, $parameters),
self::SEND_VIDEO_NOTE => SendVideoNote::execute($bot, $parameters),
self::SEND_PAID_MEDIA => SendPaidMedia::execute($bot, $parameters),
self::SEND_MEDIA_GROUP => SendMediaGroup::execute($bot, $parameters),
self::SEND_LOCATION => SendLocation::execute($bot, $parameters),
self::SEND_VENUE => SendVenue::execute($bot, $parameters),
self::SEND_CONTACT => SendContact::execute($bot, $parameters),
self::SEND_POLL => SendPoll::execute($bot, $parameters),
self::SEND_DICE => SendDice::execute($bot, $parameters),
self::SEND_CHAT_ACTION => SendChatAction::execute($bot, $parameters),
self::SET_MESSAGE_REACTION => SetMessageReaction::execute($bot, $parameters),
self::GET_USER_PROFILE_PHOTOS => GetUserProfilePhotos::execute($bot, $parameters),
self::GET_FILE => GetFile::execute($bot, $parameters),
self::BAN_CHAT_MEMBER => BanChatMember::execute($bot, $parameters),
self::UNBAN_CHAT_MEMBER => UnbanChatMember::execute($bot, $parameters),
self::RESTRICT_CHAT_MEMBER => RestrictChatMember::execute($bot, $parameters),
self::PROMOTE_CHAT_MEMBER => PromoteChatMember::execute($bot, $parameters),
self::SET_CHAT_ADMINISTRATOR_CUSTOM_TITLE => SetChatAdministratorCustomTitle::execute($bot, $parameters),
self::BAN_CHAT_SENDER_CHAT => BanChatSenderChat::execute($bot, $parameters),
self::UNBAN_CHAT_SENDER_CHAT => UnbanChatSenderChat::execute($bot, $parameters),
self::SET_CHAT_PERMISSIONS => SetChatPermissions::execute($bot, $parameters),
self::EXPORT_CHAT_INVITE_LINK => ExportChatInviteLink::execute($bot, $parameters),
self::CREATE_CHAT_INVITE_LINK => CreateChatInviteLink::execute($bot, $parameters),
self::EDIT_CHAT_INVITE_LINK => EditChatInviteLink::execute($bot, $parameters),
self::CREATE_CHAT_SUBSCRIPTION_INVITE_LINK => CreateChatSubscriptionInviteLink::execute($bot, $parameters),
self::EDIT_CHAT_SUBSCRIPTION_INVITE_LINK => EditChatSubscriptionInviteLink::execute($bot, $parameters),
self::REVOKE_CHAT_INVITE_LINK => RevokeChatInviteLink::execute($bot, $parameters),
self::APPROVE_CHAT_JOIN_REQUEST => ApproveChatJoinRequest::execute($bot, $parameters),
self::DECLINE_CHAT_JOIN_REQUEST => DeclineChatJoinRequest::execute($bot, $parameters),
self::SET_CHAT_PHOTO => SetChatPhoto::execute($bot, $parameters),
self::DELETE_CHAT_PHOTO => DeleteChatPhoto::execute($bot, $parameters),
self::SET_CHAT_TITLE => SetChatTitle::execute($bot, $parameters),
self::SET_CHAT_DESCRIPTION => SetChatDescription::execute($bot, $parameters),
self::PIN_CHAT_MESSAGE => PinChatMessage::execute($bot, $parameters),
self::UNPIN_CHAT_MESSAGE => UnpinChatMessage::execute($bot, $parameters),
self::UNPIN_ALL_CHAT_MESSAGES => UnpinAllChatMessages::execute($bot, $parameters),
self::LEAVE_CHAT => LeaveChat::execute($bot, $parameters),
self::GET_CHAT => GetChat::execute($bot, $parameters),
self::GET_CHAT_ADMINISTRATORS => GetChatAdministrators::execute($bot, $parameters),
self::GET_CHAT_MEMBER_COUNT => GetChatMemberCount::execute($bot, $parameters),
self::GET_CHAT_MEMBER => GetChatMember::execute($bot, $parameters),
self::SET_CHAT_STICKER_SET => SetChatStickerSet::execute($bot, $parameters),
self::DELETE_CHAT_STICKER_SET => DeleteChatStickerSet::execute($bot, $parameters),
self::GET_FORUM_TOPIC_ICON_STICKERS => GetForumTopicIconStickers::execute($bot, $parameters),
self::CREATE_FORUM_TOPIC => CreateForumTopic::execute($bot, $parameters),
self::EDIT_FORUM_TOPIC => EditForumTopic::execute($bot, $parameters),
self::CLOSE_FORUM_TOPIC => CloseForumTopic::execute($bot, $parameters),
self::REOPEN_FORUM_TOPIC => ReopenForumTopic::execute($bot, $parameters),
self::DELETE_FORUM_TOPIC => DeleteForumTopic::execute($bot, $parameters),
self::UNPIN_ALL_FORUM_TOPIC_MESSAGES => UnpinAllForumTopicMessages::execute($bot, $parameters),
self::EDIT_GENERAL_FORUM_TOPIC => EditGeneralForumTopic::execute($bot, $parameters),
self::CLOSE_GENERAL_FORUM_TOPIC => CloseGeneralForumTopic::execute($bot, $parameters),
self::REOPEN_GENERAL_FORUM_TOPIC => ReopenGeneralForumTopic::execute($bot, $parameters),
self::HIDE_GENERAL_FORUM_TOPIC => HideGeneralForumTopic::execute($bot, $parameters),
self::UNHIDE_GENERAL_FORUM_TOPIC => UnhideGeneralForumTopic::execute($bot, $parameters),
self::UNPIN_ALL_GENERAL_FORUM_TOPIC_MESSAGES => UnpinAllGeneralForumTopicMessages::execute($bot, $parameters),
self::ANSWER_CALLBACK_QUERY => AnswerCallbackQuery::execute($bot, $parameters),
self::GET_USER_CHAT_BOOSTS => GetUserChatBoosts::execute($bot, $parameters),
self::GET_BUSINESS_CONNECTION => GetBusinessConnection::execute($bot, $parameters),
self::SET_MY_COMMANDS => SetMyCommands::execute($bot, $parameters),
self::DELETE_MY_COMMANDS => DeleteMyCommands::execute($bot, $parameters),
self::GET_MY_COMMANDS => GetMyCommands::execute($bot, $parameters),
self::SET_MY_NAME => SetMyName::execute($bot, $parameters),
self::GET_MY_NAME => GetMyName::execute($bot, $parameters),
self::SET_MY_DESCRIPTION => SetMyDescription::execute($bot, $parameters),
self::GET_MY_DESCRIPTION => GetMyDescription::execute($bot, $parameters),
self::SET_MY_SHORT_DESCRIPTION => SetMyShortDescription::execute($bot, $parameters),
self::GET_MY_SHORT_DESCRIPTION => GetMyShortDescription::execute($bot, $parameters),
self::SET_CHAT_MENU_BUTTON => SetChatMenuButton::execute($bot, $parameters),
self::GET_CHAT_MENU_BUTTON => GetChatMenuButton::execute($bot, $parameters),
self::SET_MY_DEFAULT_ADMINISTRATOR_RIGHTS => SetMyDefaultAdministratorRights::execute($bot, $parameters),
self::GET_MY_DEFAULT_ADMINISTRATOR_RIGHTS => GetMyDefaultAdministratorRights::execute($bot, $parameters),
self::EDIT_MESSAGE_TEXT => EditMessageText::execute($bot, $parameters),
self::EDIT_MESSAGE_CAPTION => EditMessageCaption::execute($bot, $parameters),
self::EDIT_MESSAGE_MEDIA => EditMessageMedia::execute($bot, $parameters),
self::EDIT_MESSAGE_LIVE_LOCATION => EditMessageLiveLocation::execute($bot, $parameters),
self::STOP_MESSAGE_LIVE_LOCATION => StopMessageLiveLocation::execute($bot, $parameters),
self::EDIT_MESSAGE_REPLY_MARKUP => EditMessageReplyMarkup::execute($bot, $parameters),
self::STOP_POLL => StopPoll::execute($bot, $parameters),
self::DELETE_MESSAGE => DeleteMessage::execute($bot, $parameters),
self::DELETE_MESSAGES => DeleteMessages::execute($bot, $parameters),
self::SEND_STICKER => SendSticker::execute($bot, $parameters),
self::GET_STICKER_SET => GetStickerSet::execute($bot, $parameters),
self::GET_CUSTOM_EMOJI_STICKERS => GetCustomEmojiStickers::execute($bot, $parameters),
self::UPLOAD_STICKER_FILE => UploadStickerFile::execute($bot, $parameters),
self::CREATE_NEW_STICKER_SET => CreateNewStickerSet::execute($bot, $parameters),
self::ADD_STICKER_TO_SET => AddStickerToSet::execute($bot, $parameters),
self::SET_STICKER_POSITION_IN_SET => SetStickerPositionInSet::execute($bot, $parameters),
self::DELETE_STICKER_FROM_SET => DeleteStickerFromSet::execute($bot, $parameters),
self::REPLACE_STICKER_IN_SET => ReplaceStickerInSet::execute($bot, $parameters),
self::SET_STICKER_EMOJI_LIST => SetStickerEmojiList::execute($bot, $parameters),
self::SET_STICKER_MASK_POSITION => SetStickerMaskPosition::execute($bot, $parameters),
self::SET_STICKER_SET_TITLE => SetStickerSetTitle::execute($bot, $parameters),
self::SET_STICKER_SET_THUMBNAIL => SetStickerSetThumbnail::execute($bot, $parameters),
self::SET_CUSTOM_EMOJI_STICKER_SET_THUMBNAIL => SetCustomEmojiStickerSetThumbnail::execute($bot, $parameters),
self::DELETE_STICKER_SET => DeleteStickerSet::execute($bot, $parameters),
self::GET_AVAILABLE_GIFTS => GetAvailableGifts::execute($bot, $parameters),
self::SEND_GIFT => SendGift::execute($bot, $parameters),
self::ANSWER_INLINE_QUERY => AnswerInlineQuery::execute($bot, $parameters),
self::ANSWER_WEB_APP_QUERY => AnswerWebAppQuery::execute($bot, $parameters),
self::SAVE_PREPARED_INLINE_MESSAGE => SavePreparedInlineMessage::execute($bot, $parameters),
self::SEND_INVOICE => SendInvoice::execute($bot, $parameters),
self::CREATE_INVOICE_LINK => CreateInvoiceLink::execute($bot, $parameters),
self::ANSWER_SHIPPING_QUERY => AnswerShippingQuery::execute($bot, $parameters),
self::ANSWER_PRE_CHECKOUT_QUERY => AnswerPreCheckoutQuery::execute($bot, $parameters),
self::GET_STAR_TRANSACTIONS => GetStarTransactions::execute($bot, $parameters),
self::SET_PASSPORT_DATA_ERRORS => SetPassportDataErrors::execute($bot, $parameters),
self::SEND_GAME => SendGame::execute($bot, $parameters),
self::SET_GAME_SCORE => SetGameScore::execute($bot, $parameters),
self::GET_GAME_HIGH_SCORES => GetGameHighScores::execute($bot, $parameters)
};
}
}

View file

@ -0,0 +1,20 @@
<?php
namespace TgBotLib\Enums;
final class PassportElementType
{
public const PERSONAL_DETAILS = 'personal_details';
public const PASSPORT = 'passport';
public const DRIVER_LICENSE = 'driver_license';
public const IDENTITY_CARD = 'identity_card';
public const INTERNAL_PASSPORT = 'internal_passport';
public const ADDRESS = 'address';
public const UTILITY_BILL = 'utility_bill';
public const BANK_STATEMENT = 'bank_statement';
public const RENTAL_AGREEMENT = 'rental_agreement';
public const PASSPORT_REGISTRATION = 'passport_registration';
public const TEMPORARY_REGISTRATION = 'temporary_registration';
public const PHONE_NUMBER = 'phone_number';
public const EMAIL = 'email';
}

View file

@ -0,0 +1,10 @@
<?php
namespace TgBotLib\Enums;
final class PollType
{
public const REGULAR = 'regular';
public const QUIZ = 'quiz';
}

View file

@ -0,0 +1,10 @@
<?php
namespace TgBotLib\Enums;
final class StickerFormat
{
public const STATIC = 'static';
public const ANIMATED = 'animated';
public const VIDEO = 'video';
}

View file

@ -0,0 +1,12 @@
<?php
namespace TgBotLib\Enums;
final class StickerType
{
public const REGULAR = 'regular';
public const MASK = 'mask';
public const CUSTOM_EMOJI = 'custom_emoji';
}

View file

@ -0,0 +1,10 @@
<?php
namespace TgBotLib\Enums;
final class ThumbnailMimeType
{
public const IMAGE_JPEG = 'image/jpeg';
public const IMAGE_GIF = 'image/gif';
public const VIDEO_MP4 = 'video/mp4';
}

View file

@ -1,10 +0,0 @@
<?php
namespace TgBotLib\Enums\Types;
enum BackgroundFillType : string
{
case SOLID = 'solid';
case GRADIENT = 'gradient';
case FREEFORM_GRADIENT = 'freeform_gradient';
}

View file

@ -1,11 +0,0 @@
<?php
namespace TgBotLib\Enums\Types;
enum BackgroundType : string
{
case FILL = 'fill';
case WALLPAPER = 'wallpaper';
case PATTERN = 'pattern';
case CHAT_THEME = 'chat_theme';
}

View file

@ -1,14 +0,0 @@
<?php
namespace TgBotLib\Enums\Types;
enum BotCommandScopeType : string
{
case DEFAULT = 'default';
case ALL_PRIVATE_CHATS = 'all_private_chats';
case ALL_CHAT_GROUPS = 'all_group_chats';
case ALL_CHAT_ADMINISTRATORS = 'all_chat_administrators';
case CHAT = 'chat';
case CHAT_ADMINISTRATORS = 'chat_administrators';
case CHAT_MEMBER = 'chat_member';
}

View file

@ -1,16 +0,0 @@
<?php
namespace TgBotLib\Enums\Types;
enum ChatActionType : string
{
case TYPING = 'typing';
case UPLOAD_PHOTO = 'upload_photo';
case RECORD_VIDEO = 'record_video';
case UPLOAD_VIDEO = 'upload_video';
case RECORD_VOICE = 'record_voice';
case CHOOSE_STICKER = 'choose_sticker';
case FIND_LOCATION = 'find_location';
case RECORD_VIDEO_NOTE = 'record_video_note';
case UPLOAD_VIDEO_NOTE = 'upload_video_note';
}

View file

@ -1,10 +0,0 @@
<?php
namespace TgBotLib\Enums\Types;
enum ChatBoostSourceType : string
{
case PREMIUM = 'premium';
case GIFT_CODE = 'gift_code';
case GIVEAWAY = 'giveaway';
}

View file

@ -1,13 +0,0 @@
<?php
namespace TgBotLib\Enums\Types;
enum ChatMemberStatus : string
{
case CREATOR = 'creator';
case ADMINISTRATOR = 'administrator';
case MEMBER = 'member';
case RESTRICTED = 'restricted';
case LEFT = 'left';
case KICKED = 'kicked';
}

View file

@ -1,11 +0,0 @@
<?php
namespace TgBotLib\Enums\Types;
enum ChatType : string
{
case PRIVATE = 'private';
case GROUP = 'group';
case SUPERGROUP = 'supergroup';
case CHANNEL = 'channel';
}

View file

@ -1,12 +0,0 @@
<?php
namespace TgBotLib\Enums\Types;
enum InputMediaType : string
{
case PHOTO = 'photo';
case VIDEO = 'video';
case ANIMATION = 'animation';
case AUDIO = 'audio';
case DOCUMENT = 'document';
}

View file

@ -1,12 +0,0 @@
<?php
namespace TgBotLib\Enums\Types;
enum InputMessageContentType : string
{
case TEXT = 'text';
case LOCATION = 'location';
case VENUE = 'venue';
case CONTACT = 'contact';
case INVOICE = 'invoice';
}

View file

@ -1,9 +0,0 @@
<?php
namespace TgBotLib\Enums\Types;
enum KeyboardButtonPollType : string
{
case QUIZ = 'quiz';
case REGULAR = 'regular';
}

View file

@ -1,10 +0,0 @@
<?php
namespace TgBotLib\Enums\Types;
enum MenuButtonType : string
{
case COMMANDS = 'commands';
case WEB_APP = 'web_app';
case DEFAULT = 'default';
}

View file

@ -1,41 +0,0 @@
<?php
namespace TgBotLib\Enums\Types;
enum MessageEntityType : string
{
case MENTION = 'mention';
case HASHTAG = 'hashtag';
case CASHTAG = 'cashtag';
case BOT_COMMAND = 'bot_command';
case URL = 'url';
case EMAIL = 'email';
case PHONE_NUMBER = 'phone_number';
case BOLD = 'bold';
case ITALIC = 'italic';
case UNDERLINE = 'underline';
case STRIKETHROUGH = 'strikethrough';
case SPOILER = 'spoiler';
case CODE = 'code';
case PRE = 'pre';
case TEXT_LINK = 'text_link';
case TEXT_MENTION = 'text_mention';
case CUSTOM_EMOJI = 'custom_emoji';
}

View file

@ -1,11 +0,0 @@
<?php
namespace TgBotLib\Enums\Types;
enum MessageOriginType : string
{
case USER = 'user';
case HIDDEN_USER = 'hidden_user';
case CHAT = 'chat';
case CHANNEL = 'channel';
}

View file

@ -1,10 +0,0 @@
<?php
namespace TgBotLib\Enums\Types;
enum PaidMediaType : string
{
case PREVIEW = 'preview';
case PHOTO = 'photo';
case VIDEO = 'video';
}

View file

@ -1,10 +0,0 @@
<?php
namespace TgBotLib\Enums\Types;
enum ParseMode : string
{
case HTML = 'HTML';
case MARKDOWN = 'Markdown';
case MARKDOWN_V2 = 'MarkdownV2';
}

View file

@ -1,16 +0,0 @@
<?php
namespace TgBotLib\Enums\Types;
enum PassportElementErrorSourceType : string
{
case DATA = 'data';
case FRONT_SIDE = 'front_side';
case REVERSE_SIDE = 'reverse_side';
case SELFIE = 'selfie';
case FILE = 'file';
case FILES = 'files';
case TRANSLATION_FILE = 'translation_file';
case TRANSLATION_FILES = 'translation_files';
case UNSPECIFIED = 'unspecified';
}

View file

@ -1,13 +0,0 @@
<?php
namespace TgBotLib\Enums\Types;
enum PassportElementErrorType : string
{
case PERSONAL_DETAILS = 'personal_details';
case PASSPORT = 'passport';
case DRIVER_LICENSE = 'driver_license';
case IDENTITY_CARD = 'identity_card';
case INTERNAL_PASSPORT = 'internal_passport';
case ADDRESS = 'address';
}

View file

@ -1,20 +0,0 @@
<?php
namespace TgBotLib\Enums\Types;
enum PassportElementType : string
{
case PERSONAL_DETAILS = 'personal_details';
case PASSPORT = 'passport';
case DRIVER_LICENSE = 'driver_license';
case IDENTITY_CARD = 'identity_card';
case INTERNAL_PASSPORT = 'internal_passport';
case ADDRESS = 'address';
case UTILITY_BILL = 'utility_bill';
case BANK_STATEMENT = 'bank_statement';
case RENTAL_AGREEMENT = 'rental_agreement';
case PASSPORT_REGISTRATION = 'passport_registration';
case TEMPORARY_REGISTRATION = 'temporary_registration';
case PHONE_NUMBER = 'phone_number';
case EMAIL = 'email';
}

View file

@ -1,10 +0,0 @@
<?php
namespace TgBotLib\Enums\Types;
enum PollType : string
{
case REGULAR = 'regular';
case QUIZ = 'quiz';
}

View file

@ -1,10 +0,0 @@
<?php
namespace TgBotLib\Enums\Types;
enum ReactionTypes : string
{
case EMOJI = 'emoji';
case CUSTOM_EMOJI = 'custom_emoji';
case PAID = 'paid';
}

View file

@ -1,10 +0,0 @@
<?php
namespace TgBotLib\Enums\Types;
enum RevenueWithdrawalType : string
{
case PENDING = 'pending';
case SUCCEEDED = 'succeed';
case FAILED = 'failed';
}

View file

@ -1,10 +0,0 @@
<?php
namespace TgBotLib\Enums\Types;
enum StickerFormat : string
{
case STATIC = 'static';
case ANIMATED = 'animated';
case VIDEO = 'video';
}

View file

@ -1,10 +0,0 @@
<?php
namespace TgBotLib\Enums\Types;
enum StickerType : string
{
case REGULAR = 'regular';
case MASK = 'mask';
case CUSTOM_EMOJI = 'custom_emoji';
}

View file

@ -1,10 +0,0 @@
<?php
namespace TgBotLib\Enums\Types;
enum ThumbnailMimeType : string
{
case IMAGE_JPEG = 'image/jpeg';
case IMAGE_GIF = 'image/gif';
case VIDEO_MP4 = 'video/mp4';
}

View file

@ -1,11 +0,0 @@
<?php
namespace TgBotLib\Enums\Types;
enum TransactionPartnerType : string
{
case USER = 'user';
case FRAGMENT = 'fragment';
case TELEGRAM_ADS = 'telegram_ads';
case OTHER = 'other';
}

View file

@ -0,0 +1,12 @@
<?php
namespace TgBotLib\Enums;
final class UpdateEventType
{
public const GENERIC_UPDATE = 'generic_update';
public const MESSAGE = 'message';
public const EDITED_MESSAGE = 'edited_message';
}

View file

@ -1,27 +0,0 @@
<?php
namespace TgBotLib\Events;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\BusinessConnection;
abstract class BusinessConnectionEvent extends UpdateEvent
{
/**
* @inheritDoc
*/
public static function getEventType(): EventType
{
return EventType::BUSINESS_CONNECTION;
}
/**
* Fetches the BusinessConnection instance associated with this update.
*
* @return BusinessConnection The business connection associated with this update.
*/
protected function getBusinessConnection(): BusinessConnection
{
return $this->update->getBusinessConnection();
}
}

View file

@ -1,27 +0,0 @@
<?php
namespace TgBotLib\Events;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\Message;
abstract class BusinessMessageEvent extends UpdateEvent
{
/**
* @inheritDoc
*/
public static function getEventType(): EventType
{
return EventType::BUSINESS_MESSAGE;
}
/**
* New incoming business message
*
* @return Message
*/
protected function getBusinessMessage(): Message
{
return $this->update->getBusinessMessage();
}
}

View file

@ -1,35 +0,0 @@
<?php
namespace TgBotLib\Events;
use LogicException;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\CallbackQuery;
abstract class CallbackQueryEvent extends UpdateEvent
{
/**
* @inheritDoc
*/
public static function getEventType(): EventType
{
return EventType::CALLBACK_QUERY;
}
/**
* Retrieves data associated with the callback.
*
* @return string
*/
public abstract static function getCallbackData(): string;
/**
* New incoming callback query
*
* @return CallbackQuery
*/
protected function getCallbackQuery(): CallbackQuery
{
return $this->update->getCallbackQuery();
}
}

View file

@ -1,27 +0,0 @@
<?php
namespace TgBotLib\Events;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\Message;
abstract class ChannelPostEvent extends UpdateEvent
{
/**
* @inheritDoc
*/
public static function getEventType(): EventType
{
return EventType::CHANNEL_POST;
}
/**
* Retrieves the current channel post.
*
* @return Message The channel post message.
*/
protected function getChannelPost(): Message
{
return $this->update->getChannelPost();
}
}

View file

@ -1,27 +0,0 @@
<?php
namespace TgBotLib\Events;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\ChatBoostUpdated;
abstract class ChatBoostEvent extends UpdateEvent
{
/**
* @inheritDoc
*/
public static function getEventType(): EventType
{
return EventType::CHAT_BOOST_EVENT;
}
/**
* A chat boost was added or changed. The bot must be an administrator in the chat to receive these updates.
*
* @return ChatBoostUpdated The updated chat boost information.
*/
protected function getChatBoost(): ChatBoostUpdated
{
return $this->update->getChatBoost();
}
}

View file

@ -1,28 +0,0 @@
<?php
namespace TgBotLib\Events;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\ChatJoinRequest;
abstract class ChatJoinRequestEvent extends UpdateEvent
{
/**
* @inheritDoc
*/
public static function getEventType(): EventType
{
return EventType::CHAT_JOIN_REQUEST_EVENT;
}
/**
* A request to join the chat has been sent. The bot must have the can_invite_users
* administrator right in the chat to receive these updates.
*
* @return ChatJoinRequest The chat join request data.
*/
protected function getChatJoinRequest(): ChatJoinRequest
{
return $this->update->getChatJoinRequest();
}
}

View file

@ -1,28 +0,0 @@
<?php
namespace TgBotLib\Events;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\ChatMemberUpdated;
abstract class ChatMemberUpdatedEvent extends UpdateEvent
{
/**
* @inheritDoc
*/
public static function getEventType(): EventType
{
return EventType::CHAT_MEMBER_UPDATED;
}
/**
* A chat member's status was updated in a chat. The bot must be an administrator in the chat and must
* explicitly specify "chat_member" in the list of allowed_updates to receive these updates.
*
* @return ChatMemberUpdated The updated chat member instance.
*/
protected function getChatMemberUpdated(): ChatMemberUpdated
{
return $this->update->getChatMember();
}
}

View file

@ -1,27 +0,0 @@
<?php
namespace TgBotLib\Events;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\Inline\ChosenInlineResult;
abstract class ChosenInlineResultEvent extends UpdateEvent
{
/**
* @inheritDoc
*/
public static function getEventType(): EventType
{
return EventType::CHOSEN_INLINE_RESULT;
}
/**
* The result of an inline query that was chosen by a user and sent to their chat partner.
*
* @return ChosenInlineResult The chosen inline result associated with the current update.
*/
protected function getChosenInlineResult(): ChosenInlineResult
{
return $this->update->getChosenInlineResult();
}
}

View file

@ -1,63 +0,0 @@
<?php
namespace TgBotLib\Events;
use OptsLib\Parse;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\Message;
abstract class CommandEvent extends UpdateEvent
{
/**
* @inheritDoc
*/
public static function getEventType(): EventType
{
return EventType::COMMAND;
}
/**
* Retrieve the command to be executed.
*
* In the format of a string, this method should return the command to be executed.
* for example if the command is "/start", this method should return "start".
*
* @return string The command to be executed.
*/
public abstract static function getCommand(): string;
/**
* Retrieves the message from the update.
*
* @return Message The message contained within the update.
*/
protected function getMessage(): Message
{
return $this->update->getAnyMessage();
}
/**
* Extracts and returns the arguments of the command from the message text.
*
* @return string The arguments of the command.
*/
protected function getArguments(): string
{
if(strlen($this->getMessage()->getCommand()) <= strlen(static::getCommand()) + 1)
{
return '';
}
return substr($this->getMessage()->getCommand(), strlen(static::getCommand()) + 1);
}
/**
* Parses and returns the command arguments as an array.
*
* @return array The parsed command arguments.
*/
protected function getParsedArguments(): array
{
return Parse::parseArgument($this->getArguments());
}
}

View file

@ -1,27 +0,0 @@
<?php
namespace TgBotLib\Events;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\BusinessMessagesDeleted;
abstract class DeletedBusinessMessagesEvent extends UpdateEvent
{
/**
* @inheritDoc
*/
public static function getEventType(): EventType
{
return EventType::DELETED_BUSINESS_MESSAGES;
}
/**
* Messages were deleted from a connected business account
*
* @return BusinessMessagesDeleted
*/
protected function getBusinessMessagesDeleted(): BusinessMessagesDeleted
{
return $this->update->getDeletedBusinessMessages();
}
}

View file

@ -1,27 +0,0 @@
<?php
namespace TgBotLib\Events;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\Message;
abstract class EditedBusinessMessageEvent extends UpdateEvent
{
/**
* @inheritDoc
*/
public static function getEventType(): EventType
{
return EventType::EDITED_BUSINESS_MESSAGE;
}
/**
* New incoming edited business message
*
* @return Message
*/
protected function getEditedBusinessMessage(): Message
{
return $this->update->getEditedBusinessMessage();
}
}

View file

@ -1,27 +0,0 @@
<?php
namespace TgBotLib\Events;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\Message;
abstract class EditedChannelPostEvent extends UpdateEvent
{
/**
* @inheritDoc
*/
public static function getEventType(): EventType
{
return EventType::EDITED_CHANNEL_POST;
}
/**
* Retrieves the edited channel post from the update.
*
* @return Message The edited channel post.
*/
protected function getEditedChannelPost(): Message
{
return $this->update->getEditedChannelPost();
}
}

View file

@ -1,27 +0,0 @@
<?php
namespace TgBotLib\Events;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\Message;
abstract class EditedMessageEvent extends UpdateEvent
{
/**
* @inheritDoc
*/
public static function getEventType(): EventType
{
return EventType::EDITED_MESSAGE;
}
/**
* Retrieves the current edited message.
*
* @return Message The edited message.
*/
protected function getEditedMessage(): Message
{
return $this->update->getEditedMessage();
}
}

View file

@ -1,27 +0,0 @@
<?php
namespace TgBotLib\Events;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\Inline\InlineQuery;
abstract class InlineQueryEvent extends UpdateEvent
{
/**
* @inheritDoc
*/
public static function getEventType(): EventType
{
return EventType::INLINE_QUERY;
}
/**C
* New incoming inline query
*
* @return InlineQuery
*/
protected function getInlineQuery(): InlineQuery
{
return $this->update->getInlineQuery();
}
}

View file

@ -1,27 +0,0 @@
<?php
namespace TgBotLib\Events;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\Message;
abstract class MessageEvent extends UpdateEvent
{
/**
* @inheritDoc
*/
public static function getEventType(): EventType
{
return EventType::MESSAGE;
}
/**
* Retrieves the current message.
*
* @return Message The message.
*/
protected function getMessage(): Message
{
return $this->update->getMessage();
}
}

View file

@ -1,29 +0,0 @@
<?php
namespace TgBotLib\Events;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\MessageReactionCountUpdated;
abstract class MessageReactionCountEvent extends UpdateEvent
{
/**
* @inheritDoc
*/
public static function getEventType(): EventType
{
return EventType::MESSAGE_REACTION_COUNT;
}
/**
* Reactions to a message with anonymous reactions were changed. The bot must be an administrator in the chat
* and must explicitly specify "message_reaction_count" in the list of allowed_updates to receive these updates.
* The updates are grouped and can be sent with delay up to a few minutes.
*
* @return MessageReactionCountUpdated
*/
protected function getMessageReactionCount(): MessageReactionCountUpdated
{
return $this->update->getMessageReactionCount();
}
}

View file

@ -1,29 +0,0 @@
<?php
namespace TgBotLib\Events;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\MessageReactionUpdated;
abstract class MessageReactionEvent extends UpdateEvent
{
/**
* @inheritDoc
*/
public static function getEventType(): EventType
{
return EventType::MESSAGE_REACTION;
}
/**
* A reaction to a message was changed by a user. The bot must be an administrator in the chat and must
* explicitly specify "message_reaction" in the list of allowed_updates to receive these updates.
* The update isn't received for reactions set by bots.
*
* @return MessageReactionUpdated
*/
protected function getMessageReactionUpdated(): MessageReactionUpdated
{
return $this->update->getMessageReaction();
}
}

View file

@ -1,29 +0,0 @@
<?php
namespace TgBotLib\Events;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\ChatMemberUpdated;
abstract class MyChatMemberUpdatedEvent extends UpdateEvent
{
/**
* @inheritDoc
*/
public static function getEventType(): EventType
{
return EventType::MY_CHAT_MEMBER_UPDATED;
}
/**
* The bot's chat member status was updated in a chat. For private chats,
* this update is received only when the bot is blocked or unblocked by the user.
*
* @return ChatMemberUpdated The updated chat member information.
*/
protected function getMyChatMemberUpdated(): ChatMemberUpdated
{
return $this->update->getMyChatMember();
}
}

View file

@ -1,27 +0,0 @@
<?php
namespace TgBotLib\Events;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\Payments\PaidMediaPurchased;
abstract class PaidMediaPurchasedEvent extends UpdateEvent
{
/**
* @inheritDoc
*/
public static function getEventType(): EventType
{
return EventType::PAID_MEDIA_PURCHASED;
}
/**
* A user purchased paid media with a non-empty payload sent by the bot in a non-channel chat
*
* @return PaidMediaPurchased
*/
protected function getPurchasedPaidMedia(): PaidMediaPurchased
{
return $this->update->getPurchasedPaidMedia();
}
}

View file

@ -1,28 +0,0 @@
<?php
namespace TgBotLib\Events;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\PollAnswer;
abstract class PollAnswerEvent extends UpdateEvent
{
/**
* @inheritDoc
*/
public static function getEventType(): EventType
{
return EventType::POLL_ANSWER;
}
/**
* A user changed their answer in a non-anonymous poll.
* Bots receive new votes only in polls that were sent by the bot itself.
*
* @return PollAnswer The poll answer associated with the current update.
*/
protected function getPollAnswer(): PollAnswer
{
return $this->update->getPollAnswer();
}
}

View file

@ -1,28 +0,0 @@
<?php
namespace TgBotLib\Events;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\Poll;
abstract class PollEvent extends UpdateEvent
{
/**
* @inheritDoc
*/
public static function getEventType(): EventType
{
return EventType::POLL;
}
/**
* A user changed their answer in a non-anonymous poll.
* Bots receive new votes only in polls that were sent by the bot itself.
*
* @return Poll The poll.
*/
protected function getPoll(): Poll
{
return $this->update->getPoll();
}
}

View file

@ -1,27 +0,0 @@
<?php
namespace TgBotLib\Events;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\Payments\PreCheckoutQuery;
abstract class PreCheckoutQueryEvent extends UpdateEvent
{
/**
* @inheritDoc
*/
public static function getEventType(): EventType
{
return EventType::PRE_CHECKOUT_QUERY;
}
/**
* New incoming pre-checkout query. Contains full information about checkout
*
* @return PreCheckoutQuery
*/
protected function getPreCheckoutQuery(): PreCheckoutQuery
{
return $this->update->getPreCheckoutQuery();
}
}

View file

@ -1,27 +0,0 @@
<?php
namespace TgBotLib\Events;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\ChatBoostRemoved;
abstract class RemovedChatBoostEvent extends UpdateEvent
{
/**
* @inheritDoc
*/
public static function getEventType(): EventType
{
return EventType::REMOVED_CHAT_BOOST_EVENT;
}
/**
* A boost was removed from a chat. The bot must be an administrator in the chat to receive these updates.
*
* @return ChatBoostRemoved The chat boost that was removed.
*/
protected function getChatBoostRemoved(): ChatBoostRemoved
{
return $this->update->getRemovedChatBoost();
}
}

View file

@ -1,27 +0,0 @@
<?php
namespace TgBotLib\Events;
use TgBotLib\Enums\EventType;
use TgBotLib\Objects\Payments\ShippingQuery;
abstract class ShippingQueryEvent extends UpdateEvent
{
/**
* @inheritDoc
*/
public static function getEventType(): EventType
{
return EventType::SHIPPING_QUERY;
}
/**
* New incoming shipping query. Only for invoices with flexible price
*
* @return ShippingQuery
*/
protected function getShippingQuery(): ShippingQuery
{
return $this->update->getShippingQuery();
}
}

View file

@ -1,42 +0,0 @@
<?php
namespace TgBotLib\Events;
use TgBotLib\Bot;
use TgBotLib\Enums\EventType;
use TgBotLib\Exceptions\TelegramException;
use TgBotLib\Objects\Update;
abstract class UpdateEvent
{
protected Update $update;
/**
* Constructor for the class.
*
* @param Update $update The update instance to be used.
* @return void
*/
public function __construct(Update $update)
{
$this->update = $update;
}
/**
* Retrieves the event type.
* @return EventType The event type of the current instance.
*/
public static function getEventType(): EventType
{
return EventType::UPDATE_EVENT;
}
/**
* Abstract method to handle the bot instance.
*
* @param Bot $bot The bot instance to be handled.
* @return void
* @throws TelegramException
*/
public abstract function handle(Bot $bot): void;
}

View file

@ -16,6 +16,6 @@
*/
public function __construct(string $message = "", int $code = 0, ?Throwable $previous = null)
{
parent::__construct(sprintf("%s (Error code %s)", $message, $code), $code, $previous);
parent::__construct($message, $code, $previous);
}
}

View file

@ -2,17 +2,17 @@
namespace TgBotLib\Interfaces;
use TgBotLib\BotOld;
use TgBotLib\Objects\Update;
use TgBotLib\Bot;
use TgBotLib\Objects\Telegram\Update;
interface CommandInterface
{
/**
* Execute the command
*
* @param BotOld $bot
* @param Bot $bot
* @param Update $update
* @return void
*/
public function handle(BotOld $bot, Update $update): void;
public function handle(Bot $bot, Update $update): void;
}

View file

@ -2,17 +2,17 @@
namespace TgBotLib\Interfaces;
use TgBotLib\BotOld;
use TgBotLib\Objects\Update;
use TgBotLib\Bot;
use TgBotLib\Objects\Telegram\Update;
interface EventInterface
{
/**
* Execute the command
*
* @param BotOld $bot
* @param Bot $bot
* @param Update $update
* @return void
*/
public function handle(BotOld $bot, Update $update): void;
public function handle(Bot $bot, Update $update): void;
}

View file

@ -7,15 +7,15 @@
/**
* Returns an array representation of the object
*
* @return array|null
* @return array
*/
public function toArray(): ?array;
public function toArray(): array;
/**
* Reconstruction of the object from an array
*
* @param array|null $data
* @return ObjectTypeInterface|null
* @param array $data
* @return ObjectTypeInterface
*/
public static function fromArray(?array $data): ?ObjectTypeInterface;
public static function fromArray(array $data): ObjectTypeInterface;
}

View file

@ -1,40 +0,0 @@
<?php
namespace TgBotLib\Methods;
use TgBotLib\Abstracts\Method;
use TgBotLib\Bot;
use TgBotLib\Enums\Methods;
use TgBotLib\Exceptions\NotImplementedException;
class AddStickerToSet extends Method
{
/**
* @inheritDoc
*/
public static function execute(Bot $bot, array $parameters = []): true
{
throw new NotImplementedException('Method not implemented yet, check back later');
}
/**
* @inheritDoc
*/
public static function getRequiredParameters(): ?array
{
return [
'user_id',
'name',
'sticker'
];
}
/**
* @inheritDoc
*/
public static function getOptionalParameters(): ?array
{
return null;
}
}

View file

@ -1,42 +0,0 @@
<?php
namespace TgBotLib\Methods;
use TgBotLib\Abstracts\Method;
use TgBotLib\Bot;
use TgBotLib\Enums\Methods;
class AnswerCallbackQuery extends Method
{
/**
* @inheritDoc
*/
public static function execute(Bot $bot, array $parameters = []): true
{
return (bool)(self::executeCurl(self::buildPost($bot, Methods::ANSWER_CALLBACK_QUERY->value, $parameters)));
}
/**
* @inheritDoc
*/
public static function getRequiredParameters(): ?array
{
return [
'callback_query_id'
];
}
/**
* @inheritDoc
*/
public static function getOptionalParameters(): ?array
{
return [
'text',
'show_alert',
'url',
'cache_time'
];
}
}

View file

@ -1,77 +0,0 @@
<?php
namespace TgBotLib\Methods;
use TgBotLib\Abstracts\Method;
use TgBotLib\Bot;
use TgBotLib\Enums\Methods;
use TgBotLib\Interfaces\ObjectTypeInterface;
class AnswerInlineQuery extends Method
{
/**
* @inheritDoc
*/
public static function execute(Bot $bot, array $parameters = []): true
{
if(isset($parameters['results']))
{
$results = [];
foreach($parameters['results'] as $result)
{
if($result instanceof ObjectTypeInterface)
{
$result[] = $result->toArray();
continue;
}
if(is_array($result))
{
$result[] = $result;
}
}
$parameters['results'] = json_encode($results);
}
if(isset($parameters['button']))
{
if($parameters['button'] instanceof ObjectTypeInterface)
{
$parameters['button'] = json_encode($parameters['button']->toArray());
}
if(is_array($parameters['button']))
{
$parameters['button'] = json_encode($parameters['button']);
}
}
return (bool)self::executeCurl(self::buildPost($bot, Methods::ANSWER_INLINE_QUERY->value, $parameters));
}
/**
* @inheritDoc
*/
public static function getRequiredParameters(): ?array
{
return [
'inline_query_id',
'results'
];
}
/**
* @inheritDoc
*/
public static function getOptionalParameters(): ?array
{
return [
'cache_time',
'is_personal',
'next_offset',
'button'
];
}
}

View file

@ -1,40 +0,0 @@
<?php
namespace TgBotLib\Methods;
use TgBotLib\Abstracts\Method;
use TgBotLib\Bot;
use TgBotLib\Enums\Methods;
class AnswerPreCheckoutQuery extends Method
{
/**
* @inheritDoc
*/
public static function execute(Bot $bot, array $parameters = []): true
{
return (bool)self::executeCurl(self::buildPost($bot, Methods::ANSWER_PRE_CHECKOUT_QUERY->value, $parameters));
}
/**
* @inheritDoc
*/
public static function getRequiredParameters(): ?array
{
return [
'pre_checkout_query_id',
'ok'
];
}
/**
* @inheritDoc
*/
public static function getOptionalParameters(): ?array
{
return [
'error_message'
];
}
}

View file

@ -1,50 +0,0 @@
<?php
namespace TgBotLib\Methods;
use TgBotLib\Abstracts\Method;
use TgBotLib\Bot;
use TgBotLib\Enums\Methods;
use TgBotLib\Interfaces\ObjectTypeInterface;
class AnswerShippingQuery extends Method
{
/**
* @inheritDoc
*/
public static function execute(Bot $bot, array $parameters = []): true
{
if(isset($parameters['shipping_options']))
{
if($parameters['shipping_options'] instanceof ObjectTypeInterface)
{
$parameters['shipping_options'] = json_encode($parameters['shipping_options']->toArray());
}
}
return (bool)self::executeCurl(self::buildPost($bot, Methods::ANSWER_SHIPPING_QUERY->value, $parameters));
}
/**
* @inheritDoc
*/
public static function getRequiredParameters(): ?array
{
return [
'shipping_query_id',
'ok'
];
}
/**
* @inheritDoc
*/
public static function getOptionalParameters(): ?array
{
return [
'shipping_options',
'error_message'
];
}
}

View file

@ -1,53 +0,0 @@
<?php
namespace TgBotLib\Methods;
use TgBotLib\Abstracts\Method;
use TgBotLib\Bot;
use TgBotLib\Enums\Methods;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\Inline\SentWebAppMessage;
class AnswerWebAppQuery extends Method
{
/**
* @inheritDoc
*/
public static function execute(Bot $bot, array $parameters = []): SentWebAppMessage
{
if(isset($parameters['result']))
{
if($parameters['result'] instanceof ObjectTypeInterface)
{
$parameters['result'] = json_encode($parameters['result']->toArray());
}
if(is_array($parameters['result']))
{
$parameters['result'] = json_encode($parameters['result']);
}
}
return SentWebAppMessage::fromArray(self::executeCurl(self::buildPost($bot, Methods::ANSWER_WEB_APP_QUERY->value, $parameters)));
}
/**
* @inheritDoc
*/
public static function getRequiredParameters(): ?array
{
return [
'web_app_query_id',
'result'
];
}
/**
* @inheritDoc
*/
public static function getOptionalParameters(): ?array
{
return null;
}
}

View file

@ -1,39 +0,0 @@
<?php
namespace TgBotLib\Methods;
use TgBotLib\Abstracts\Method;
use TgBotLib\Bot;
use TgBotLib\Enums\Methods;
use TgBotLib\Objects\ChatInviteLink;
class ApproveChatJoinRequest extends Method
{
/**
* @inheritDoc
*/
public static function execute(Bot $bot, array $parameters = []): true
{
return (bool)self::executeCurl(self::buildPost($bot, Methods::APPROVE_CHAT_JOIN_REQUEST->value, $parameters));
}
/**
* @inheritDoc
*/
public static function getRequiredParameters(): ?array
{
return [
'chat_id',
'invite_link'
];
}
/**
* @inheritDoc
*/
public static function getOptionalParameters(): ?array
{
return null;
}
}

View file

@ -1,41 +0,0 @@
<?php
namespace TgBotLib\Methods;
use TgBotLib\Abstracts\Method;
use TgBotLib\Bot;
use TgBotLib\Enums\Methods;
class BanChatMember extends Method
{
/**
* @inheritDoc
*/
public static function execute(Bot $bot, array $parameters = []): true
{
return (bool)self::executeCurl(self::buildPost($bot, Methods::BAN_CHAT_MEMBER->value, $parameters));
}
/**
* @inheritDoc
*/
public static function getRequiredParameters(): ?array
{
return [
'chat_id',
'user_id'
];
}
/**
* @inheritDoc
*/
public static function getOptionalParameters(): ?array
{
return [
'until_date',
'revoke_messages'
];
}
}

View file

@ -1,38 +0,0 @@
<?php
namespace TgBotLib\Methods;
use TgBotLib\Abstracts\Method;
use TgBotLib\Bot;
use TgBotLib\Enums\Methods;
class BanChatSenderChat extends Method
{
/**
* @inheritDoc
*/
public static function execute(Bot $bot, array $parameters = []): true
{
return (bool)self::executeCurl(self::buildPost($bot, Methods::BAN_CHAT_SENDER_CHAT->value, $parameters));
}
/**
* @inheritDoc
*/
public static function getRequiredParameters(): ?array
{
return [
'chat_id',
'sender_chat_id'
];
}
/**
* @inheritDoc
*/
public static function getOptionalParameters(): ?array
{
return null;
}
}

View file

@ -1,43 +0,0 @@
<?php
namespace TgBotLib\Methods;
use TgBotLib\Abstracts\Method;
use TgBotLib\Bot;
use TgBotLib\Enums\Methods;
use TgBotLib\Exceptions\TelegramException;
class Close extends Method
{
/**
* Use this method to close the bot instance before moving it from one local server to another.
* You need to delete the webhook before calling this method to ensure that the bot isn't launched again
* after server restart. The method will return error 429 in the first 10 minutes after the bot is launched.
* Returns True on success. Requires no parameters.
*
* @param Bot $bot
* @param array $parameters
* @return bool
* @throws TelegramException
*/
public static function execute(Bot $bot, array $parameters = []): bool
{
return (bool) self::executeCurl(self::buildPost($bot, Methods::CLOSE->value));
}
/**
* @inheritDoc
*/
public static function getRequiredParameters(): ?array
{
return null;
}
/**
* @inheritDoc
*/
public static function getOptionalParameters(): ?array
{
return null;
}
}

View file

@ -1,38 +0,0 @@
<?php
namespace TgBotLib\Methods;
use TgBotLib\Abstracts\Method;
use TgBotLib\Bot;
use TgBotLib\Enums\Methods;
class CloseForumTopic extends Method
{
/**
* @inheritDoc
*/
public static function execute(Bot $bot, array $parameters = []): true
{
return (bool)(self::executeCurl(self::buildPost($bot, Methods::CLOSE_FORUM_TOPIC->value, $parameters)));
}
/**
* @inheritDoc
*/
public static function getRequiredParameters(): ?array
{
return [
'chat_id',
'message_thread_id'
];
}
/**
* @inheritDoc
*/
public static function getOptionalParameters(): ?array
{
return null;
}
}

View file

@ -1,37 +0,0 @@
<?php
namespace TgBotLib\Methods;
use TgBotLib\Abstracts\Method;
use TgBotLib\Bot;
use TgBotLib\Enums\Methods;
class CloseGeneralForumTopic extends Method
{
/**
* @inheritDoc
*/
public static function execute(Bot $bot, array $parameters = []): true
{
return (bool)(self::executeCurl(self::buildPost($bot, Methods::CLOSE_GENERAL_FORUM_TOPIC->value, $parameters)));
}
/**
* @inheritDoc
*/
public static function getRequiredParameters(): ?array
{
return [
'chat_id'
];
}
/**
* @inheritDoc
*/
public static function getOptionalParameters(): ?array
{
return null;
}
}

View file

@ -1,106 +0,0 @@
<?php
namespace TgBotLib\Methods;
use TgBotLib\Abstracts\Method;
use TgBotLib\Bot;
use TgBotLib\Enums\Methods;
use TgBotLib\Enums\Types\ParseMode;
use TgBotLib\Exceptions\TelegramException;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\MessageEntity;
use TgBotLib\Objects\MessageId;
use TgBotLib\Objects\ReplyParameters;
class CopyMessage extends Method
{
/**
* Use this method to copy messages of any kind. Service messages, paid media messages, giveaway messages,
* giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the
* value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessage,
* but the copied message doesn't have a link to the original message.
*
* Returns the MessageId of the sent message on success.
*
* @param Bot $bot
* @param array $parameters
* @return MessageId
* @throws TelegramException
*/
public static function execute(Bot $bot, array $parameters = []): MessageId
{
if(isset($parameters['parse_mode']) && $parameters['parse_mode'] instanceof ParseMode)
{
$parameters['parse_mode'] = $parameters['parse_mode']->value;
}
if(isset($parameters['caption_entities']) && is_array($parameters['caption_entities']))
{
$entities = [];
foreach($parameters['caption_entities'] as $entity)
{
if($entity instanceof MessageEntity)
{
$entities[] = $entity->toArray();
}
else
{
$entities[] = $entity;
}
}
$parameters['caption_entities'] = $entities;
}
if(isset($parameters['reply_parameters']) && $parameters['reply_parameters'] instanceof ReplyParameters)
{
$parameters['reply_parameters'] = $parameters['reply_parameters']->toArray();
}
if (isset($parameters['reply_markup']))
{
if ($parameters['reply_markup'] instanceof ObjectTypeInterface)
{
$parameters['reply_markup'] = json_encode($parameters['reply_markup']->toArray());
}
elseif (is_array($parameters['reply_markup']))
{
$parameters['reply_markup'] = json_encode($parameters['reply_markup']);
}
}
return MessageId::fromArray(self::executeCurl(self::buildPost($bot, Methods::COPY_MESSAGE->value, $parameters)));
}
/**
* @inheritDoc
*/
public static function getRequiredParameters(): ?array
{
return [
'chat_id',
'from_chat_id',
'message_id'
];
}
/**
* @inheritDoc
*/
public static function getOptionalParameters(): ?array
{
return [
'message_thread_id',
'caption',
'parse_mode',
'caption_entities',
'show_caption_above_media',
'disable_notification',
'protect_content',
'reply_parameters',
'reply_markup'
];
}
}

View file

@ -1,57 +0,0 @@
<?php
namespace TgBotLib\Methods;
use TgBotLib\Abstracts\Method;
use TgBotLib\Bot;
use TgBotLib\Enums\Methods;
use TgBotLib\Exceptions\TelegramException;
use TgBotLib\Objects\MessageId;
class CopyMessages extends Method
{
/**
* Use this method to copy messages of any kind. Service messages, paid media messages, giveaway messages,
* giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the
* value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessage,
* but the copied message doesn't have a link to the original message.
*
* Returns the MessageId of the sent message on success.
*
* @param Bot $bot
* @param array $parameters
* @return MessageId[]
* @throws TelegramException
*/
public static function execute(Bot $bot, array $parameters = []): array
{
return array_map(fn($message) => MessageId::fromArray($message),
self::executeCurl(self::buildPost($bot, Methods::COPY_MESSAGES->value, $parameters))
);
}
/**
* @inheritDoc
*/
public static function getRequiredParameters(): ?array
{
return [
'chat_id',
'from_chat_id',
'message_ids'
];
}
/**
* @inheritDoc
*/
public static function getOptionalParameters(): ?array
{
return [
'message_thread_id',
'disable_notification',
'protect_content',
'remove_caption'
];
}
}

View file

@ -1,44 +0,0 @@
<?php
namespace TgBotLib\Methods;
use TgBotLib\Abstracts\Method;
use TgBotLib\Bot;
use TgBotLib\Enums\Methods;
use TgBotLib\Objects\ChatInviteLink;
class CreateChatInviteLink extends Method
{
/**
* @inheritDoc
*/
public static function execute(Bot $bot, array $parameters = []): ChatInviteLink
{
return ChatInviteLink::fromArray(
self::executeCurl(self::buildPost($bot, Methods::CREATE_CHAT_INVITE_LINK->value, $parameters))
);
}
/**
* @inheritDoc
*/
public static function getRequiredParameters(): ?array
{
return [
'chat_id'
];
}
/**
* @inheritDoc
*/
public static function getOptionalParameters(): ?array
{
return [
'name',
'expire_date',
'member_limit',
'creates_join_request'
];
}
}

Some files were not shown because too many files have changed in this diff Show more