Skip to content

Commit

Permalink
Merge pull request #78 from Pabloader/pabloader-master
Browse files Browse the repository at this point in the history
Client::callbackQuery
  • Loading branch information
iGusev authored Jul 27, 2017
2 parents e3547c7 + 1aedaf6 commit 5fc3278
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public function editedMessage(Closure $action)
return $this->on(self::getEditedMessageEvent($action), self::getEditedMessageChecker());
}

public function callbackQuery(Closure $action)
{
return $this->on(self::getCallbackQueryEvent($action), self::getCallbackQueryChecker());
}

public function channelPost(Closure $action)
{
return $this->on(self::getChannelPostEvent($action), self::getChannelPostChecker());
Expand Down Expand Up @@ -197,6 +202,19 @@ protected static function getChannelPostEvent(Closure $action)
};
}

protected static function getCallbackQueryEvent(Closure $action)
{
return function (Update $update) use ($action) {
if (!$update->getCallbackQuery()) {
return true;
}

$reflectionAction = new ReflectionFunction($action);
$reflectionAction->invokeArgs([$update->getCallbackQuery()]);
return false;
};
}

protected static function getEditedChannelPostEvent(Closure $action)
{
return function (Update $update) use ($action) {
Expand Down Expand Up @@ -307,6 +325,18 @@ protected static function getChannelPostChecker()
};
}

/**
* Returns check function to handling the callbackQuery.
*
* @return Closure
*/
protected static function getCallbackQueryChecker()
{
return function (Update $update) {
return !is_null($update->getCallbackQuery());
};
}

/**
* Returns check function to handling the edited channel post.
*
Expand Down

0 comments on commit 5fc3278

Please sign in to comment.