Skip to content

Bot API 5.1, Added two new update types #343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ public function preCheckoutQuery(Closure $action)
return $this->on(self::getPreCheckoutQueryEvent($action), self::getPreCheckoutQueryChecker());
}

public function myChatMember(Closure $action) {
return $this->on(self::getMyChatMemberEvent($action), self::getMyChatMemberChecker());
}

public function chatMember(Closure $action) {
return $this->on(self::getChatMemberEvent($action), self::getChatMemberChecker());
}

/**
* Use this method to add an event.
* If second closure will return true (or if you are passed null instead of closure), first one will be executed.
Expand Down Expand Up @@ -280,6 +288,30 @@ protected static function getPreCheckoutQueryEvent(Closure $action)
};
}

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

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

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

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

/**
* Returns check function to handling the command.
*
Expand Down Expand Up @@ -397,6 +429,28 @@ protected static function getPreCheckoutQueryChecker()
};
}

/**
* Returns check function to handling the myChatMember updates.
*
* @return Closure
*/
public static function getMyChatMemberChecker() {
return function (Update $update) {
return !is_null($update->getMyChatMember());
};
}

/**
* Returns check function to handling the chatMember updates.
*
* @return Closure
*/
public static function getChatMemberChecker() {
return function (Update $update) {
return !is_null($update->getChatMember());
};
}

public function __call($name, array $arguments)
{
if (method_exists($this, $name)) {
Expand Down
175 changes: 175 additions & 0 deletions src/Types/ChatInviteLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
<?php


namespace TelegramBot\Api\Types;


use TelegramBot\Api\BaseType;

class ChatInviteLink extends BaseType
{
/**
* {@inheritdoc}
*
* @var array
*/
protected static $requiredParams = [
'invite_link',
'creator',
'is_primary',
'is_revoked',
];

/**
* {@inheritdoc}
*
* @var array
*/
protected static $map = [
'invite_link' => true,
'creator' => User::class,
'is_primary' => true,
'is_revoked' => true,
'expire_date' => true,
'member_limit' => true
];

/**
* The invite link. If the link was created by another chat administrator,
* then the second part of the link will be replaced with “…”.
*
* @var string
*/
protected $invite_link;

/**
* Creator of the link
*
* @var User
*/
protected $creator;

/**
* True, if the link is primary
*
* @var boolean
*/
protected $isPrimary;

/**
* True, if the link is revoked
*
* @var boolean
*/
protected $isRevoked;

/**
* Optional. Point in time (Unix timestamp) when the link will expire or has been expired
*
* @var int
*/
protected $expireDate;

/**
* Optional. Maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999
*
* @var int
*/
protected $memberLimit;

/**
* @return string
*/
public function getInviteLink()
{
return $this->invite_link;
}

/**
* @param string $invite_link
*/
public function setInviteLink($invite_link)
{
$this->invite_link = $invite_link;
}

/**
* @return User
*/
public function getCreator()
{
return $this->creator;
}

/**
* @param User $creator
*/
public function setCreator($creator)
{
$this->creator = $creator;
}

/**
* @return bool
*/
public function isPrimary()
{
return $this->isPrimary;
}

/**
* @param bool $isPrimary
*/
public function setIsPrimary($isPrimary)
{
$this->isPrimary = $isPrimary;
}

/**
* @return bool
*/
public function isRevoked()
{
return $this->isRevoked;
}

/**
* @param bool $isRevoked
*/
public function setIsRevoked($isRevoked)
{
$this->isRevoked = $isRevoked;
}

/**
* @return int
*/
public function getExpireDate()
{
return $this->expireDate;
}

/**
* @param int $expireDate
*/
public function setExpireDate($expireDate)
{
$this->expireDate = $expireDate;
}

/**
* @return int
*/
public function getMemberLimit()
{
return $this->memberLimit;
}

/**
* @param int $memberLimit
*/
public function setMemberLimit($memberLimit)
{
$this->memberLimit = $memberLimit;
}
}
Loading