Compare commits
2 commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ec6e58c8ec | ||
![]() |
9a5a593789 |
6 changed files with 11 additions and 78 deletions
19
CHANGELOG.md
19
CHANGELOG.md
|
@ -4,30 +4,13 @@ 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
|
## [8.0.1] - Ongoing
|
||||||
|
|
||||||
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
|
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
|
### Fixed
|
||||||
* Reposition debug log for event handler execution.
|
* Reposition debug log for event handler execution.
|
||||||
* Improve command check with method existence validation
|
* 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
|
## [8.0.0] - 2024-11-29
|
||||||
|
|
|
@ -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": "8.0.1",
|
||||||
"uuid": "b409e036-ab04-11ed-b32e-9d3f57a644ae"
|
"uuid": "b409e036-ab04-11ed-b32e-9d3f57a644ae"
|
||||||
},
|
},
|
||||||
"build": {
|
"build": {
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
use TgBotLib\Enums\Types\ChatActionType;
|
use TgBotLib\Enums\Types\ChatActionType;
|
||||||
use TgBotLib\Enums\Types\ParseMode;
|
use TgBotLib\Enums\Types\ParseMode;
|
||||||
use TgBotLib\Enums\Types\StickerFormat;
|
use TgBotLib\Enums\Types\StickerFormat;
|
||||||
use TgBotLib\Events\CallbackQueryEvent;
|
|
||||||
use TgBotLib\Events\CommandEvent;
|
use TgBotLib\Events\CommandEvent;
|
||||||
use TgBotLib\Events\UpdateEvent;
|
use TgBotLib\Events\UpdateEvent;
|
||||||
use TgBotLib\Exceptions\TelegramException;
|
use TgBotLib\Exceptions\TelegramException;
|
||||||
|
@ -376,26 +375,6 @@
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @method array getEventHandlersByCallbackQuery(string $callbackData) Retrieves an array of event handlers whose callback data matches the given parameter.
|
|
||||||
* @param string $callbackData The callback data to match against the registered event handlers.
|
|
||||||
* @return array An array of matching event handler instances.
|
|
||||||
*/
|
|
||||||
public function getEventHandlersByCallbackQuery(string $callbackData): array
|
|
||||||
{
|
|
||||||
$results = [];
|
|
||||||
/** @var UpdateEvent $eventHandler */
|
|
||||||
foreach($this->eventHandlers as $eventHandler)
|
|
||||||
{
|
|
||||||
if(method_exists($eventHandler, 'getCallbackData') && $eventHandler::getCallbackData() === $callbackData)
|
|
||||||
{
|
|
||||||
$results[] = $eventHandler;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $results;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes all event handlers.
|
* Removes all event handlers.
|
||||||
*
|
*
|
||||||
|
@ -450,6 +429,7 @@
|
||||||
$command = $update?->getAnyMessage()?->getCommand();
|
$command = $update?->getAnyMessage()?->getCommand();
|
||||||
if($command !== null)
|
if($command !== null)
|
||||||
{
|
{
|
||||||
|
$commandExecuted = false;
|
||||||
Logger::getLogger()->debug(sprintf('Executing command %s for update %s', $command, $update->getUpdateId()));
|
Logger::getLogger()->debug(sprintf('Executing command %s for update %s', $command, $update->getUpdateId()));
|
||||||
|
|
||||||
/** @var CommandEvent $eventHandler */
|
/** @var CommandEvent $eventHandler */
|
||||||
|
@ -458,6 +438,7 @@
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
(new $eventHandler($update))->handle($this);
|
(new $eventHandler($update))->handle($this);
|
||||||
|
$commandExecuted = true;
|
||||||
}
|
}
|
||||||
catch(TelegramException $e)
|
catch(TelegramException $e)
|
||||||
{
|
{
|
||||||
|
@ -468,28 +449,10 @@
|
||||||
Logger::getLogger()->error(sprintf('Exception occurred: %s', $e->getMessage()), $e);
|
Logger::getLogger()->error(sprintf('Exception occurred: %s', $e->getMessage()), $e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$callbackData = $update?->getCallbackQuery()?->getData();
|
if($commandExecuted)
|
||||||
if($callbackData !== null)
|
|
||||||
{
|
{
|
||||||
Logger::getLogger()->debug(sprintf('Executing callback query %s for update %s', $callbackData, $update->getUpdateId()));
|
return;
|
||||||
|
|
||||||
/** @var CallbackQueryEvent $eventHandler */
|
|
||||||
foreach($this->getEventHandlersByCallbackQuery($callbackData) as $eventHandler)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
(new $eventHandler($update))->handle($this);
|
|
||||||
}
|
|
||||||
catch(TelegramException $e)
|
|
||||||
{
|
|
||||||
Logger::getLogger()->error(sprintf('Telegram exception occurred: %s', $e->getMessage()), $e);
|
|
||||||
}
|
|
||||||
catch(Exception $e)
|
|
||||||
{
|
|
||||||
Logger::getLogger()->error(sprintf('Exception occurred: %s', $e->getMessage()), $e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,6 +115,11 @@
|
||||||
return EventType::SHIPPING_QUERY;
|
return EventType::SHIPPING_QUERY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($update->getCallbackQuery() !== null)
|
||||||
|
{
|
||||||
|
return EventType::CALLBACK_QUERY;
|
||||||
|
}
|
||||||
|
|
||||||
if($update->getChosenInlineResult() !== null)
|
if($update->getChosenInlineResult() !== null)
|
||||||
{
|
{
|
||||||
return EventType::CHOSEN_INLINE_RESULT;
|
return EventType::CHOSEN_INLINE_RESULT;
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace TgBotLib\Events;
|
namespace TgBotLib\Events;
|
||||||
|
|
||||||
use LogicException;
|
|
||||||
use TgBotLib\Enums\EventType;
|
use TgBotLib\Enums\EventType;
|
||||||
use TgBotLib\Objects\CallbackQuery;
|
use TgBotLib\Objects\CallbackQuery;
|
||||||
|
|
||||||
|
@ -16,13 +15,6 @@
|
||||||
return EventType::CALLBACK_QUERY;
|
return EventType::CALLBACK_QUERY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves data associated with the callback.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public abstract static function getCallbackData(): string;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* New incoming callback query
|
* New incoming callback query
|
||||||
*
|
*
|
||||||
|
|
|
@ -1061,16 +1061,6 @@
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if any media content is present in the message.
|
|
||||||
*
|
|
||||||
* @return bool True if media content is present, false otherwise.
|
|
||||||
*/
|
|
||||||
public function containsMedia(): bool
|
|
||||||
{
|
|
||||||
return $this->getPhoto() !== null || $this->getAnimation() !== null || $this->getAudio() !== null || $this->getDocument() !== null || $this->getSticker() !== null || $this->getVideo() !== null || $this->getVideoNote() !== null || $this->getVoice() !== null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue