Compare commits

..

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

494 changed files with 11146 additions and 31197 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 }}

6
.gitignore vendored
View file

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

View file

@ -24,7 +24,6 @@ before_script:
- cd .. && rm -rf ncc - cd .. && rm -rf ncc
build: build:
stage: build
script: script:
- ncc build --config release --log-level debug - ncc build --config release --log-level debug
artifacts: artifacts:
@ -37,8 +36,6 @@ release:
stage: deploy stage: deploy
script: script:
- ncc build --config release --log-level debug - ncc build --config release --log-level debug
- >
curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file build/release/net.nosial.tgbotlib.ncc "$CI_API_V4_URL/projects/$CI_PROJECT_ID/packages/generic/net.nosial.tgbotlib/$CI_COMMIT_REF_NAME/net.nosial.tgbotlib.ncc"
artifacts: artifacts:
paths: paths:
- build/ - build/

View file

@ -1,11 +1,6 @@
<component name="InspectionProjectProfileManager"> <component name="InspectionProjectProfileManager">
<profile version="1.0"> <profile version="1.0">
<option name="myName" value="Project Default" /> <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"> <inspection_tool class="IncorrectHttpHeaderInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="customHeaders"> <option name="customHeaders">
<set> <set>
@ -24,9 +19,6 @@
<option value="X-Args-3" /> <option value="X-Args-3" />
<option value="X-Args-4" /> <option value="X-Args-4" />
<option value="X-Args-5" /> <option value="X-Args-5" />
<option value="X-Temperature" />
<option value="X-Model" />
<option value="X-OPENAI-API-KEY" />
</set> </set>
</option> </option>
</inspection_tool> </inspection_tool>

14
.idea/php.xml generated
View file

@ -9,25 +9,21 @@
<component name="PHPCodeSnifferOptionsConfiguration"> <component name="PHPCodeSnifferOptionsConfiguration">
<option name="transferred" value="true" /> <option name="transferred" value="true" />
</component> </component>
<component name="PhpAnalysisConfiguration" call_tree_analysis_depth="3" />
<component name="PhpIncludePathManager"> <component name="PhpIncludePathManager">
<include_path> <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="/usr/share/php" />
<path value="/etc/ncc" />
<path value="/var/ncc/packages/net.nosial.tamerlib=1.0.0" />
<path value="/var/ncc/packages/net.nosial.loglib=1.0.2" />
<path value="/var/ncc/packages/net.nosial.tempfile=1.1.0" />
</include_path> </include_path>
</component> </component>
<component name="PhpProjectSharedConfiguration" php_language_level="8.3"> <component name="PhpProjectSharedConfiguration" php_language_level="8.0">
<option name="suggestChangeDefaultLanguageLevel" value="false" /> <option name="suggestChangeDefaultLanguageLevel" value="false" />
</component> </component>
<component name="PhpStanOptionsConfiguration"> <component name="PhpStanOptionsConfiguration">
<option name="transferred" value="true" /> <option name="transferred" value="true" />
</component> </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"> <component name="PsalmOptionsConfiguration">
<option name="transferred" value="true" /> <option name="transferred" value="true" />
</component> </component>

View file

@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager"> <component name="ProjectRunConfigurationManager">
<configuration default="false" name="Build" type="MAKEFILE_TARGET_RUN_CONFIGURATION" factoryName="Makefile" activateToolWindowBeforeRun="false"> <configuration default="false" name="Build" type="MAKEFILE_TARGET_RUN_CONFIGURATION" factoryName="Makefile">
<makefile filename="$PROJECT_DIR$/Makefile" target="build" workingDirectory="" arguments=""> <makefile filename="$PROJECT_DIR$/Makefile" target="build" workingDirectory="" arguments="">
<envs /> <envs />
</makefile> </makefile>

View file

@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager"> <component name="ProjectRunConfigurationManager">
<configuration default="false" name="Clean" type="MAKEFILE_TARGET_RUN_CONFIGURATION" factoryName="Makefile" activateToolWindowBeforeRun="false"> <configuration default="false" name="Clean" type="MAKEFILE_TARGET_RUN_CONFIGURATION" factoryName="Makefile">
<makefile filename="$PROJECT_DIR$/Makefile" target="clean" workingDirectory="" arguments=""> <makefile filename="$PROJECT_DIR$/Makefile" target="clean" workingDirectory="" arguments="">
<envs /> <envs />
</makefile> </makefile>

View file

@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager"> <component name="ProjectRunConfigurationManager">
<configuration default="false" name="Install" type="MAKEFILE_TARGET_RUN_CONFIGURATION" factoryName="Makefile" activateToolWindowBeforeRun="false"> <configuration default="false" name="Install" type="MAKEFILE_TARGET_RUN_CONFIGURATION" factoryName="Makefile">
<makefile filename="$PROJECT_DIR$/Makefile" target="install" workingDirectory="" arguments=""> <makefile filename="$PROJECT_DIR$/Makefile" target="install" workingDirectory="" arguments="">
<envs /> <envs />
</makefile> </makefile>

View file

@ -1,176 +1,67 @@
# Changelog # Changelog
All notable changes to this project will be documented in this file. 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/), 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). 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).
Additionally, this update includes some bug fixes and improvements such as the ability for some objects to be treated as
input objects for methods that require input objects.
### Added
* Added object `\TgBotLib\Objects\Telegram\InputMessageContent\InputTextMessageContent` to represent the content of a text message to be sent as the result of an inline query.
* Added object `\TgBotLib\Objects\Telegram\InputMessageContent\InputLocationMessageContent` to represent the content of a location message to be sent as the result of an inline query.
* Added object `\TgBotLib\Objects\Telegram\InputMessageContent\InputVenueMessageContent` to represent the content of a venue message to be sent as the result of an inline query.
* Added object `\TgBotLib\Objects\Telegram\InputMessageContent\InputContactMessageContent` to represent the content of a contact message to be sent as the result of an inline query.
* Added object `\TgBotLib\Objects\Telegram\InputMessageContent\InputInvoiceMessageContent` to represent the content of an invoice message to be sent as the result of an inline query.
* Added new exception class `NotImplementedException` to represent the case when a method is not implemented yet or the method is not applicable to the current object.
* Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultArticle`, see [InlineQueryResultArticle](https://core.telegram.org/bots/api#inlinequeryresultarticle) for more information.
* Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultPhoto`, see [InlineQueryResultPhoto](hthttps://git.n64.cc/nosial/libs/tgbot/-/issues/3https://git.n64.cc/nosial/libs/tgbot/-/issues/3tps://core.telegram.org/bots/api#inlinequeryresultphoto) for more information.
* Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultGif`, see [InlineQueryResultGif](https://core.telegram.org/bots/api#inlinequeryresultgif) for more information.
* Added abstract class `\TgBotLib\Abstracts\ThumbnailMimeType` to represent the mime type of thumbnail, photo, or a file / sticker thumbnail.
* Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultMpeg4Gif`, see [InlineQueryResultMpeg4Gif](https://core.telegram.org/bots/api#inlinequeryresultmpeg4gif) for more information.
* Added field `via_chat_folder_invite_link` to `\TgBotLib\Objects\Telegram\ChatMemberUpdated` to represent the invite link, which was used by the user to join the chat; for joining by invite link events only.
* Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultVideo`, see [InlineQueryResultVideo](https://core.telegram.org/bots/api#inlinequeryresultvideo) for more information.
* Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultAudio`, see [InlineQueryResultAudio](https://core.telegram.org/bots/api#inlinequeryresultaudio) for more information.
* Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultVoice`, see [InlineQueryResultVoice](https://core.telegram.org/bots/api#inlinequeryresultvoice) for more information.
* Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultDocument`, see [InlineQueryResultDocument](https://core.telegram.org/bots/api#inlinequeryresultdocument) for more information.
* Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultLocation`, see [InlineQueryResultLocation](https://core.telegram.org/bots/api#inlinequeryresultlocation) for more information.
* Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultVenue`, see [InlineQueryResultVenue](https://core.telegram.org/bots/api#inlinequeryresultvenue) for more information.
* Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultContact`, see [InlineQueryResultContact](https://core.telegram.org/bots/api#inlinequeryresultcontact) for more information.
* Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultGame`, see [InlineQueryResultGame](https://core.telegram.org/bots/api#inlinequeryresultgame) for more information.
* Added class `\TgBotLib\Objects\Telegram\InlineQueryResult` which is the base class for all inline query results, additionally added `\TgBotLib\Abstracts\InlineQueryResultType` to represent the type of inline query result object.
* Added method `\TgBotLib\Bot::answerWebAppQuery` to answer a callback query sent from a web app, which returns the newly added `\TgBotLib\Objects\Telegram\SentWebAppMessage` object on success.
* Implemented Telegram's currency API `\TgBotLib\Classes\Utilities::getCurrency` to get basic information about the currency of the specified country, see [Telegram's currency API](https://core.telegram.org/bots/payments) for more information.
### Changed
* Refactored InputMessageContent types to its own namespace so InputMessageContent can always return the correct InputMessageContent object type when calling `fromArray()`
* Added methods `\TgBotLib\Objects\Telegram\InlineKeyboardButton::setUrl`, `\TgBotLib\Objects\Telegram\InlineKeyboardButton::setText`, `\TgBotLib\Objects\Telegram\InlineKeyboardButton::setCallbackData`,
`\TgBotLib\Objects\Telegram\InlineKeyboardButton::setWebApp`, `\TgBotLib\Objects\Telegram\InlineKeyboardButton::setLoginUrl`,
`\TgBotLib\Objects\Telegram\InlineKeyboardButton::setSwitchInlineQuery`, `\TgBotLib\Objects\Telegram\InlineKeyboardButton::setSwitchInlineQueryCurrentChat`,
`\TgBotLib\Objects\Telegram\InlineKeyboardButton::setCallbackGame`, `\TgBotLib\Objects\Telegram\InlineKeyboardButton::setPay`
to `\TgBotLib\Objects\Telegram\InlineKeyboardButton`
* Added methods `\TgBotLib\Objects\Telegram\InlineKeyboardMarkup::removeRow` & `\TgBotLib\Objects\Telegram\InlineKeyboardMarkup::addRow` to `\TgBotLib\Objects\Telegram\InlineKeyboardMarkup`
* Added method `\TgBotLib\Objects\Telegram\WebAppInfo::setUrl` to `\TgBotLib\Objects\Telegram\WebAppInfo`
* Added methods `\TgBotLib\Classes\Validate::url`, `\TgBotLib\Classes\Validate::length`, & `\TgBotLib\Classes\Validate::isHttps` to `\TgBotLib\Classes\Validate`
* Updated documentation for `\TgBotLib\Bot::editMessageMedia`
* Renamed namespace from `\TgBotLib\Abstracts` to `\TgBotLib\Enums`
* Updated class type to `final class` in `\TgBotLib\Enums > BotCommandScopeType`
* Updated class type to `final class` in `\TgBotLib\Enums > ChatActionType`
* Updated class type to `final class` in `\TgBotLib\Enums > ChatMemberStatus`
* Updated class type to `final class` in `\TgBotLib\Enums > ChatType`
* Updated class type to `final class` in `\TgBotLib\Enums > EventType`
* Updated class type to `final class` in `\TgBotLib\Enums > InlineQueryResultType`
* Updated class type to `final class` in `\TgBotLib\Enums > InputMediaType`
* Updated class type to `final class` in `\TgBotLib\Enums > InputButtonType`
* Updated class type to `final class` in `\TgBotLib\Enums > MessageEntityType`
* Updated class type to `final class` in `\TgBotLib\Enums > PassportElementType`
* Updated class type to `final class` in `\TgBotLib\Enums > PollType`
* Updated class type to `final class` in `\TgBotLib\Enums > StickerFormat`
* Updated class type to `final class` in `\TgBotLib\Enums > StickerType`
* Updated class type to `final class` in `\TgBotLib\Enums > ThumbnailMimeType`
* Updated class type to `final class` in `\TgBotLib\Enums > UpdateEventType`
* Updated method `\TgBotLib > Bot > handleGetUpdates()` to handle exceptions
* Updated README.md to reflect the new changes with TamerLib 2.+
### Fixed
* Fixed type in `\TgBotLib\Objects\Telegram > Message > fromArray()` where `forum_topic_created` is being parsed for
forum_topic_edited instead of `forum_topic_edited`
## [6.6.0] - 2023-04-10 ## [6.6.0] - 2023-04-10
This update accompanies the release of the [Telegram Bot API 6.6](https://core.telegram.org/bots/api#march-9-2023). This update accompanies the release of the [Telegram Bot API 6.6](https://core.telegram.org/bots/api#march-9-2023).
### Added ### Added
* Added the ability to set different bot descriptions for different user languages using the method `\TgBotLib\Bot\setMyDescription()` * Added the ability to set different bot descriptions for different user languages using the method `\TgBotLib\Bot > setMyDescription()`
see [setMyDescription](https://core.telegram.org/bots/api#setmydescription) for more information. see [setMyDescription](https://core.telegram.org/bots/api#setmydescription) for more information.
* Added the ability to get the current bot description in the given language as the class [BotDescription](https://core.telegram.org/bots/api#botdescription) * Added the ability to get the current bot description in the given language as the class [BotDescription](https://core.telegram.org/bots/api#botdescription)
using the method `\TgBotLib\Bot\getMyDescription()` see [getMyDescription](https://core.telegram.org/bots/api#getmydescription) for more information. using the method `\TgBotLib\Bot > getMyDescription()` see [getMyDescription](https://core.telegram.org/bots/api#getmydescription) for more information.
* Added the ability to set different bot short descriptions for different user languages using the method `\TgBotLib\Bot\setMyShortDescription()` * Added the ability to set different bot short descriptions for different user languages using the method `\TgBotLib\Bot > setMyShortDescription()`
see [setMyShortDescription](https://core.telegram.org/bots/api#setmyshortdescription) for more information. see [setMyShortDescription](https://core.telegram.org/bots/api#setmyshortdescription) for more information.
* Added the ability to get the current bot short description in the given language as the class [BotShortDescription](https://core.telegram.org/bots/api#botshortdescription) * Added the ability to get the current bot short description in the given language as the class [BotShortDescription](https://core.telegram.org/bots/api#botshortdescription)
using the method `\TgBotLib\Bot\getMyShortDescription()` see [getMyShortDescription](https://core.telegram.org/bots/api#getmyshortdescription) for more information. using the method `\TgBotLib\Bot > getMyShortDescription()` see [getMyShortDescription](https://core.telegram.org/bots/api#getmyshortdescription) for more information.
* Added method `\TgBotLib\Bot\sendSticker()` to send a sticker to a chat. See [sendSticker](https://core.telegram.org/bots/api#sendsticker) for more information. * Added method `\TgBotLib\Bot > sendSticker()` to send a sticker to a chat. See [sendSticker](https://core.telegram.org/bots/api#sendsticker) for more information.
* Added method `\TgBotLib\Bot\createNewStickerSet()` to create a new sticker set owned by a user. See [createNewStickerSet](https://core.telegram.org/bots/api#createnewstickerset) for more information. * Added method `\TgBotLib\Bot > createNewStickerSet()` to create a new sticker set owned by a user. See [createNewStickerSet](https://core.telegram.org/bots/api#createnewstickerset) for more information.
* Added the field _needs_repainting_ to the [Sticker](https://core.telegram.org/bots/api#sticker) class * Added the field _needs_repainting_ to the [Sticker](https://core.telegram.org/bots/api#sticker) class
which can be obtained via `TgBotLib\Objects\Telegram\Sticker\needsRepainting()` which can be obtained via `TgBotLib\Objects\Telegram > Sticker > needsRepainting()`
* Added method `\TgBotLib\Bot\addStickerToSet()` to add a new sticker to a set created by the bot. * Added method `\TgBotLib\Bot > addStickerToSet()` to add a new sticker to a set created by the bot.
See [addStickerToSet](https://core.telegram.org/bots/api#addstickertoset) for more information. See [addStickerToSet](https://core.telegram.org/bots/api#addstickertoset) for more information.
* Added abstract class `\TgBotLib\Abstracts\StickerFormat` to represent a sticker format ("`static`", "`animated`" or "`video`") * Added abstract class `\TgBotLib\Abstracts > StickerFormat` to represent a sticker format ("`static`", "`animated`" or "`video`")
* Added method `\TgBotLib\Bot\uploadStickerFile()` to upload a sticker file with a sticker for later use in `createNewStickerSet` and `addStickerToSet` methods (can be used multiple times). * Added method `\TgBotLib\Bot > uploadStickerFile()` to upload a sticker file with a sticker for later use in `createNewStickerSet` and `addStickerToSet` methods (can be used multiple times).
See [uploadStickerFile](https://core.telegram.org/bots/api#uploadstickerfile) for more information. See [uploadStickerFile](https://core.telegram.org/bots/api#uploadstickerfile) for more information.
* Added method `\TgBotLib\Bot\setCustomEmojiStickerSetThumbnail()` to set the thumbnail of a sticker set. * Added method `\TgBotLib\Bot > setCustomEmojiStickerSetThumbnail()` to set the thumbnail of a sticker set.
See [setCustomEmojiStickerSetThumbnail](https://core.telegram.org/bots/api#setcustomemojistickersetthumbnail) for more information. See [setCustomEmojiStickerSetThumbnail](https://core.telegram.org/bots/api#setcustomemojistickersetthumbnail) for more information.
* Added object `\TgBotLib\Objects\Telegram\StickerSet` to represent a sticker set. * Added object `\TgBotLib\Objects\Telegram > StickerSet` to represent a sticker set.
* Added method `\TgBotLib\Bot\setStickerSetThumbnail()` to set the thumbnail of a sticker set. * Added method `\TgBotLib\Bot > setStickerSetThumbnail()` to set the thumbnail of a sticker set.
See [setStickerSetThumbnail](https://core.telegram.org/bots/api#setstickersetthumbnail) for more information. See [setStickerSetThumbnail](https://core.telegram.org/bots/api#setstickersetthumbnail) for more information.
* Added method `\TgBotLib\Bot\setStickerSetTitle()` to set the title of a sticker set. * Added method `\TgBotLib\Bot > setStickerSetTitle()` to set the title of a sticker set.
See [setStickerSetTitle](https://core.telegram.org/bots/api#setstickersettitle) for more information. See [setStickerSetTitle](https://core.telegram.org/bots/api#setstickersettitle) for more information.
* Added method `\TgBotLib\Bot\deleteStickerSet()` to delete a sticker set. * Added method `\TgBotLib\Bot > deleteStickerSet()` to delete a sticker set.
See [deleteStickerSet](https://core.telegram.org/bots/api#deletestickerset) for more information. See [deleteStickerSet](https://core.telegram.org/bots/api#deletestickerset) for more information.
* Added method `\TgBotLib\Bot\setStickerEmojiList()` to set the list of emojis for a sticker set. * Added method `\TgBotLib\Bot > setStickerEmojiList()` to set the list of emojis for a sticker set.
See [setStickerEmojiList](https://core.telegram.org/bots/api#setstickeremojilist) for more information. See [setStickerEmojiList](https://core.telegram.org/bots/api#setstickeremojilist) for more information.
* Added method `\TgBotLib\Bot\setStickerKeywords()` to set the list of emojis for a sticker set. * Added method `\TgBotLib\Bot > setStickerKeywords()` to set the list of emojis for a sticker set.
See [setStickerKeywords](https://core.telegram.org/bots/api#setstickerkeywords) for more information. See [setStickerKeywords](https://core.telegram.org/bots/api#setstickerkeywords) for more information.
* Added method `\TgBotLib\Bot\setStickerMaskPosition()` to change the mask position of a mask sticker. * Added method `\TgBotLib\Bot > setStickerMaskPosition()` to change the mask position of a mask sticker.
See [setStickerMaskPosition](https://core.telegram.org/bots/api#setstickermaskposition) for more information. See [setStickerMaskPosition](https://core.telegram.org/bots/api#setstickermaskposition) for more information.
### Changed ### Changed
* Removed unused `__destruct()` method from `\TgBotLib\Bot` * Removed unused `__destruct()` method from `\TgBotLib\Bot`
* Added proper construction for `PollOption[]` objects in `TgBotLib\Objects\Telegram\Poll` * Added proper construction for `PollOption[]` objects in `TgBotLib\Objects\Telegram > Poll`
* Renamed `thumb` field in `TgBotLib\Objects\Telegram\Animation` to `thumbnail` * Renamed `thumb` field in `TgBotLib\Objects\Telegram > Animation` to `thumbnail`
* Renamed `thumb` field in `TgBotLib\Objects\Telegram\Audio` to `thumbnail` * Renamed `thumb` field in `TgBotLib\Objects\Telegram > Audio` to `thumbnail`
* Renamed `thumb` field in `TgBotLib\Objects\Telegram\Document` to `thumbnail` * Renamed `thumb` field in `TgBotLib\Objects\Telegram > Document` to `thumbnail`
* Renamed `thumb` field in `TgBotLib\Objects\Telegram\Sticker` to `thumbnail` * Renamed `thumb` field in `TgBotLib\Objects\Telegram > Sticker` to `thumbnail`
* Renamed `thumb` field in `TgBotLib\Objects\Telegram\Video` to `thumbnail` * Renamed `thumb` field in `TgBotLib\Objects\Telegram > Video` to `thumbnail`
* Renamed `thumb` field in `TgBotLib\Objects\Telegram\VideoNote` to `thumbnail` * Renamed `thumb` field in `TgBotLib\Objects\Telegram > VideoNote` to `thumbnail`
### Fixed ## Fixed
* Fixed `TgBotLib\Objects\Telegram\Sticker\toArray()` to properly return the `premium_animation` field * Fixed `TgBotLib\Objects\Telegram > Sticker > toArray()` to properly return the `premium_animation` field
## [6.5.2] - 2023-02-26 ## [6.5.2] - 2023-02-26
### Added ### Added
* Added dependency `net.nosial.tempfile` to create temporary files when uploading content from memory. * Added dependency `net.nosial.tempfile` to create temporary files when uploading content from memory.
* Added `\TgBotLib\Abstracts\ChatActionType` * Added `\TgBotLib\Abstracts > ChatActionType`
* Added logging events to `\TgBotLib\Bot\handleUpdate()` * Added logging events to `\TgBotLib\Bot > handleUpdate()`
### Fixed ### Fixed
* Fixed file uploads when trying to upload content from memory. * Fixed file uploads when trying to upload content from memory.

View file

@ -1,33 +1,8 @@
# Variables build:
DEFAULT_CONFIGURATION ?= release ncc build --config="release" --log-level debug
LOG_LEVEL = debug
# Default Target install:
all: release release-compressed release-executable release-executable-compressed debug debug-compressed sudo ncc package install --package="build/release/net.nosial.tgbotlib.ncc" --skip-dependencies --reinstall -y --log-level debug
# 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
clean: clean:
rm -rf build rm -rf build
.PHONY: all install test clean release release-compressed release-executable release-executable-compressed debug debug-compressed

295
README.md
View file

@ -12,7 +12,17 @@ native around the API.
* [TgBotLib](#tgbotlib) * [TgBotLib](#tgbotlib)
* [Table of contents](#table-of-contents) * [Table of contents](#table-of-contents)
* [Versioning](#versioning) * [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) * [License](#license)
<!-- TOC --> <!-- TOC -->
@ -26,9 +36,288 @@ version is `4`. Library patches are used to fix bugs or add improvements in the
Telegram Bot API version. 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
```
## 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');
// Set the command handlers
$bot->setCommandHandler('start', new \commands\StartCommand());
$bot->setCommandHandler('hash', new \commands\HashCommand());
// Initialize the worker & register the handle_update function
TamerLib\Tamer::initWorker();
TamerLib\Tamer::addFunction('handle_update', function (\TamerLib\Objects\Job $job) use ($bot)
{
$bot->handleUpdate(\TgBotLib\Objects\Telegram\Update::fromArray(json_decode($job->getData(), true)));
});
// Work forever
TamerLib\Tamer::work();
```
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');
// Require commands
require 'commands' . DIRECTORY_SEPARATOR . 'StartCommand.php';
require 'commands' . DIRECTORY_SEPARATOR . 'HashCommand.php';
// Initialize the bot
$bot = new TgBotLib\Bot('bot_token');
// Initialize the master & add the worker
TamerLib\Tamer::init(\TamerLib\Abstracts\ProtocolType::Gearman, [
'127.0.0.1:4730'
]);
TamerLib\Tamer::addWorker('handle_update', 4);
// Start the workers
TamerLib\Tamer::startWorkers();
// Handle updates forever
while(true)
{
/** @var \TgBotLib\Objects\Telegram\Update $update */
foreach ($bot->getUpdates() as $update)
{
TamerLib\Tamer::do('handle_update', json_encode($update->toArray()));
}
}
```
## 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 # 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", "package": "net.nosial.tgbotlib",
"description": "TgBotLib is a library for interacting with the Telegram Bot API", "description": "TgBotLib is a library for interacting with the Telegram Bot API",
"company": "Nosial", "company": "Nosial",
"version": "8.0.2", "version": "6.6.0",
"uuid": "b409e036-ab04-11ed-b32e-9d3f57a644ae" "uuid": "b409e036-ab04-11ed-b32e-9d3f57a644ae"
}, },
"build": { "build": {
@ -30,68 +30,12 @@
"version": "latest", "version": "latest",
"source_type": "remote", "source_type": "remote",
"source": "nosial/libs.tempfile=latest@n64" "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": [ "configurations": [
{ {
"name": "release", "name": "release",
"build_type": "ncc", "output_path": "build/release"
"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"
}
} }
] ]
} }

View file

@ -0,0 +1,14 @@
<?php
namespace TgBotLib\Abstracts;
abstract class BotCommandScopeType
{
const Default = 'default';
const AllPrivateChats = 'all_private_chats';
const AllGroupChats = 'all_group_chats';
const AllChatAdministrators = 'all_chat_administrators';
const Chat = 'chat';
const ChatAdministrators = 'chat_administrators';
const ChatMember = 'chat_member';
}

View file

@ -0,0 +1,17 @@
<?php
namespace TgBotLib\Abstracts;
abstract class ChatActionType
{
const Typing = 'typing';
const UploadPhoto = 'upload_photo';
const RecordVideo = 'record_video';
const UploadVideo = 'upload_video';
const RecordAudio = 'record_audio';
const UploadAudio = 'upload_audio';
const UploadDocument = 'upload_document';
const FindLocation = 'find_location';
const RecordVideoNote = 'record_video_note';
const UploadVideoNote = 'upload_video_note';
}

View file

@ -0,0 +1,13 @@
<?php
namespace TgBotLib\Abstracts;
abstract class ChatMemberStatus
{
const Creator = 'creator';
const Administrator = 'administrator';
const Member = 'member';
const Restricted = 'restricted';
const Left = 'left';
const Kicked = 'kicked';
}

View file

@ -0,0 +1,11 @@
<?php
namespace TgBotLib\Abstracts;
abstract class ChatType
{
const Private = 'private';
const Group = 'group';
const Supergroup = 'supergroup';
const Channel = 'channel';
}

View file

@ -0,0 +1,43 @@
<?php
namespace TgBotLib\Abstracts;
abstract class EventType
{
const GenericUpdate = 'generic_update';
const Message = 'message';
const EditedMessage = 'edited_message';
const GenericCommandMessage = 'generic_command_message';
const ChatMemberJoined = 'chat_member_joined';
const ChatMemberLeft = 'chat_member_left';
const ChatMemberKicked = 'chat_member_kicked';
const ChatMemberBanned = 'chat_member_banned';
const ChatMemberUnbanned = 'chat_member_unbanned';
const ChatMemberPromoted = 'chat_member_promoted';
const ChatMemberDemoted = 'chat_member_demoted';
const ChatMemberRestricted = 'chat_member_restricted';
const ChatMemberUnrestricted = 'chat_member_unrestricted';
const ChatTitleChanged = 'chat_title_changed';
const ChatPhotoChanged = 'chat_photo_changed';
Const CallbackQuery = 'callback_query';
const All = [
self::GenericUpdate,
self::Message,
self::EditedMessage,
self::GenericCommandMessage,
self::ChatMemberJoined,
self::ChatMemberLeft,
self::ChatMemberKicked,
self::ChatMemberBanned,
self::ChatMemberUnbanned,
self::ChatMemberPromoted,
self::ChatMemberDemoted,
self::ChatMemberRestricted,
self::ChatMemberUnrestricted,
self::ChatTitleChanged,
self::ChatPhotoChanged,
self::CallbackQuery,
];
}

View file

@ -0,0 +1,12 @@
<?php
namespace TgBotLib\Abstracts;
abstract class InputMediaType
{
const Photo = 'photo';
const Video = 'video';
const Animation = 'animation';
const Audio = 'audio';
const Document = 'document';
}

View file

@ -0,0 +1,11 @@
<?php
namespace TgBotLib\Abstracts;
abstract class MenuButtonType
{
const Commands = 'commands';
const WebApp = 'web_app';
const Default = 'default';
}

View file

@ -0,0 +1,41 @@
<?php
namespace TgBotLib\Abstracts;
abstract class MessageEntityType
{
const Mention = 'mention';
const Hashtag = 'hashtag';
const CashTag = 'cashtag';
const BotCommand = 'bot_command';
const Url = 'url';
const Email = 'email';
const PhoneNumber = 'phone_number';
const Bold = 'bold';
const Italic = 'italic';
const Underline = 'underline';
const Strikethrough = 'strikethrough';
const Spoiler = 'spoiler';
const Code = 'code';
const Pre = 'pre';
const TextLink = 'text_link';
const TextMention = 'text_mention';
const CustomEmoji = 'custom_emoji';
}

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'];
}
}

View file

@ -0,0 +1,20 @@
<?php
namespace TgBotLib\Abstracts;
abstract class PassportElementType
{
const PersonalDetails = 'personal_details';
const Passport = 'passport';
const DriverLicense = 'driver_license';
const IdentityCard = 'identity_card';
const InternalPassport = 'internal_passport';
const Address = 'address';
const UtilityBill = 'utility_bill';
const BankStatement = 'bank_statement';
const RentalAgreement = 'rental_agreement';
const PassportRegistration = 'passport_registration';
const TemporaryRegistration = 'temporary_registration';
const PhoneNumber = 'phone_number';
const Email = 'email';
}

View file

@ -0,0 +1,10 @@
<?php
namespace TgBotLib\Abstracts;
abstract class PollType
{
const Regular = 'regular';
const Quiz = 'quiz';
}

View file

@ -0,0 +1,10 @@
<?php
namespace TgBotLib\Abstracts;
abstract class StickerFormat
{
const Static = 'static';
const Animated = 'animated';
const Video = 'video';
}

View file

@ -0,0 +1,12 @@
<?php
namespace TgBotLib\Abstracts;
abstract class StickerType
{
const Regular = 'regular';
const Mask = 'mask';
const CustomEmoji = 'custom_emoji';
}

View file

@ -0,0 +1,12 @@
<?php
namespace TgBotLib\Abstracts;
abstract class UpdateEventType
{
const GenericUpdate = 'generic_update';
const Message = 'message';
const EditedMessage = 'edited_message';
}

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,53 +1,8 @@
<?php <?php
namespace TgBotLib\Classes; namespace TgBotLib\Classes;
use Exception;
use LogLib\Log;
use TgBotLib\Objects\Currency;
class Utilities class Utilities
{ {
/**
* @var Currency[]|null
*/
private static ?array $currencies_cache = null;
/**
* Retrieves the currency object associated with the given currency code.
*
* @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
*/
public static function getCurrency(string $code): Currency
{
if (self::$currencies_cache === null)
{
$source = "https://core.telegram.org/bots/payments/currencies.json";
Log::verbose('net.nosial.tgbotlib', "Fetching currencies from $source");
$data = json_decode(file_get_contents($source), true);
if ($data === null)
throw new Exception("Failed to fetch currencies");
self::$currencies_cache = [];
foreach ($data as $currency)
{
self::$currencies_cache[strtolower($currency['code'])] = Currency::fromArray($currency);
}
Log::verbose('net.nosial.tgbotlib', "Fetched " . count(self::$currencies_cache) . " supported currencies");
}
if(!isset(self::$currencies_cache[strtolower($code)]))
{
throw new Exception("Currency $code not found");
}
return self::$currencies_cache[strtolower($code)];
}
} }

View file

@ -4,39 +4,5 @@
class Validate class Validate
{ {
/**
* Validates if a URL is valid or not
*
* @param string $url
* @return bool
*/
public static function url(string $url): bool
{
return filter_var($url, FILTER_VALIDATE_URL) !== false;
}
/**
* Returns true if the given input is within the specified length range
*
* @param string $input
* @param int $min_length
* @param int $max_length
* @return bool
*/
public static function length(string $input, int $min_length, int $max_length): bool
{
$length = strlen($input);
return $length >= $min_length && $length <= $max_length;
}
/**
* Determines if the given URL is an HTTPS URL
*
* @param string $url
* @return bool
*/
public static function isHttps(string $url): bool
{
return strpos($url, 'https://') === 0;
}
} }

View file

@ -1,180 +0,0 @@
<?php
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
{
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;
/**
* 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;
}
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,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

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

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

@ -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

@ -1,13 +0,0 @@
<?php
namespace TgBotLib\Exceptions;
use Throwable;
class NotImplementedException extends \Exception
{
public function __construct(string $message = "", int $code = 0, ?Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
}

View file

@ -16,6 +16,6 @@
*/ */
public function __construct(string $message = "", int $code = 0, ?Throwable $previous = null) 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; namespace TgBotLib\Interfaces;
use TgBotLib\BotOld; use TgBotLib\Bot;
use TgBotLib\Objects\Update; use TgBotLib\Objects\Telegram\Update;
interface CommandInterface interface CommandInterface
{ {
/** /**
* Execute the command * Execute the command
* *
* @param BotOld $bot * @param Bot $bot
* @param Update $update * @param Update $update
* @return void * @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; namespace TgBotLib\Interfaces;
use TgBotLib\BotOld; use TgBotLib\Bot;
use TgBotLib\Objects\Update; use TgBotLib\Objects\Telegram\Update;
interface EventInterface interface EventInterface
{ {
/** /**
* Execute the command * Execute the command
* *
* @param BotOld $bot * @param Bot $bot
* @param Update $update * @param Update $update
* @return void * @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 * 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 * Reconstruction of the object from an array
* *
* @param array|null $data * @param array $data
* @return ObjectTypeInterface|null * @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;
}
}

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