Skip to content

Commit d7cf9dd

Browse files
committed
Callbacks can be added to be executed when callback queries are called.
1 parent e50dc96 commit d7cf9dd

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
55

66
## [Unreleased]
77
### Added
8+
- Callbacks can be added to be executed when callback queries are called.
89
### Changed
910
### Deprecated
1011
### Removed

src/Commands/SystemCommands/CallbackqueryCommand.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
*/
1919
class CallbackqueryCommand extends SystemCommand
2020
{
21+
/**
22+
* @var callable[]
23+
*/
24+
protected static $callbacks = [];
25+
2126
/**
2227
* @var string
2328
*/
@@ -46,6 +51,21 @@ public function execute()
4651
//$query_id = $callback_query->getId();
4752
//$query_data = $callback_query->getData();
4853

54+
// Call all registered callbacks.
55+
foreach (self::$callbacks as $callback) {
56+
$callback($this->getUpdate()->getCallbackQuery());
57+
}
58+
4959
return Request::answerCallbackQuery(['callback_query_id' => $this->getUpdate()->getCallbackQuery()->getId()]);
5060
}
61+
62+
/**
63+
* Add a new callback handler for callback queries.
64+
*
65+
* @param $callback
66+
*/
67+
public static function addCallbackHandler($callback)
68+
{
69+
self::$callbacks[] = $callback;
70+
}
5171
}

0 commit comments

Comments
 (0)