Commit 13ffcc1e authored by Armando Lüscher's avatar Armando Lüscher Committed by GitHub

Merge pull request #540 from noplanman/hookable_callbacks

Callbacks can be added to be executed when callback queries are called.
parents e50dc960 d7cf9dd3
...@@ -5,6 +5,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c ...@@ -5,6 +5,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
## [Unreleased] ## [Unreleased]
### Added ### Added
- Callbacks can be added to be executed when callback queries are called.
### Changed ### Changed
### Deprecated ### Deprecated
### Removed ### Removed
......
...@@ -18,6 +18,11 @@ use Longman\TelegramBot\Request; ...@@ -18,6 +18,11 @@ use Longman\TelegramBot\Request;
*/ */
class CallbackqueryCommand extends SystemCommand class CallbackqueryCommand extends SystemCommand
{ {
/**
* @var callable[]
*/
protected static $callbacks = [];
/** /**
* @var string * @var string
*/ */
...@@ -46,6 +51,21 @@ class CallbackqueryCommand extends SystemCommand ...@@ -46,6 +51,21 @@ class CallbackqueryCommand extends SystemCommand
//$query_id = $callback_query->getId(); //$query_id = $callback_query->getId();
//$query_data = $callback_query->getData(); //$query_data = $callback_query->getData();
// Call all registered callbacks.
foreach (self::$callbacks as $callback) {
$callback($this->getUpdate()->getCallbackQuery());
}
return Request::answerCallbackQuery(['callback_query_id' => $this->getUpdate()->getCallbackQuery()->getId()]); return Request::answerCallbackQuery(['callback_query_id' => $this->getUpdate()->getCallbackQuery()->getId()]);
} }
/**
* Add a new callback handler for callback queries.
*
* @param $callback
*/
public static function addCallbackHandler($callback)
{
self::$callbacks[] = $callback;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment