File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
src/Commands/SystemCommands Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
5
5
6
6
## [ Unreleased]
7
7
### Added
8
+ - Callbacks can be added to be executed when callback queries are called.
8
9
### Changed
9
10
### Deprecated
10
11
### Removed
Original file line number Diff line number Diff line change 18
18
*/
19
19
class CallbackqueryCommand extends SystemCommand
20
20
{
21
+ /**
22
+ * @var callable[]
23
+ */
24
+ protected static $ callbacks = [];
25
+
21
26
/**
22
27
* @var string
23
28
*/
@@ -46,6 +51,21 @@ public function execute()
46
51
//$query_id = $callback_query->getId();
47
52
//$query_data = $callback_query->getData();
48
53
54
+ // Call all registered callbacks.
55
+ foreach (self ::$ callbacks as $ callback ) {
56
+ $ callback ($ this ->getUpdate ()->getCallbackQuery ());
57
+ }
58
+
49
59
return Request::answerCallbackQuery (['callback_query_id ' => $ this ->getUpdate ()->getCallbackQuery ()->getId ()]);
50
60
}
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
+ }
51
71
}
You can’t perform that action at this time.
0 commit comments