Skip to content

Commit

Permalink
support for Telegram Bot Api 5.4 and 5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
cheeghi committed Dec 21, 2021
1 parent cb6505a commit dc80682
Show file tree
Hide file tree
Showing 10 changed files with 456 additions and 22 deletions.
9 changes: 0 additions & 9 deletions .scrutinizer.yml

This file was deleted.

8 changes: 0 additions & 8 deletions .travis.yml

This file was deleted.

8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

Asynchronous PHP Telegram Bot Framework built on top of [ReactPHP](https://reactphp.org/)

[![Bot API](https://img.shields.io/badge/Bot%20API-5.3%20(June%202021)-blue)](https://core.telegram.org/bots/api)
[![Bot API](https://img.shields.io/badge/Bot%20API-5.5%20(December%202021)-blue)](https://core.telegram.org/bots/api)
[![PHP](https://img.shields.io/badge/PHP-%3E%3D7.3-blue)](https://www.php.net/)
[![Build Status](https://travis-ci.org/badfarm/zanzara.svg?branch=master)](https://travis-ci.org/badfarm/zanzara)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/badfarm/zanzara/badges/quality-score.png?b=develop)](https://scrutinizer-ci.com/g/badfarm/zanzara/?branch=develop)
[![Build](https://github.com/badfarm/zanzara/actions/workflows/build.yml/badge.svg)](https://github.com/badfarm/zanzara/actions/workflows/build.yml)
[![Code style](https://img.shields.io/badge/code%20style-standard-green)](https://www.php-fig.org/psr/psr-2/)
[![License](https://img.shields.io/badge/license-MIT-green)](https://github.com/badfarm/zanzara/blob/develop/LICENSE.md)

Expand All @@ -20,7 +19,6 @@ Asynchronous PHP Telegram Bot Framework built on top of [ReactPHP](https://react
* Based on [ReactPHP](https://reactphp.org/) asynchronous non-blocking I/O model
* Scheduled functions/timers provided by ReactPHP
* Bulk message sending (no more 429 annoying errors)
* Full [Telegram Bot Api 5.3](https://core.telegram.org/bots/api) support (June 2021)

### Installation
```
Expand Down Expand Up @@ -54,4 +52,4 @@ Then run it from command line as follows:

Enjoy your bot!

Check out [Wiki](https://github.com/badfarm/zanzara/wiki) for documentation.
Check out the [Wiki](https://github.com/badfarm/zanzara/wiki) for documentation.
21 changes: 21 additions & 0 deletions src/Zanzara/Listener/ListenerCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Zanzara\Middleware\MiddlewareInterface;
use Zanzara\Telegram\Type\CallbackQuery;
use Zanzara\Telegram\Type\ChannelPost;
use Zanzara\Telegram\Type\ChatJoinRequest;
use Zanzara\Telegram\Type\ChosenInlineResult;
use Zanzara\Telegram\Type\EditedChannelPost;
use Zanzara\Telegram\Type\EditedMessage;
Expand Down Expand Up @@ -460,6 +461,26 @@ public function onPollAnswer($callback, array $filters = []): MiddlewareCollecto
return $listener;
}

/**
* Listen for a chat join request.
* You can call this function more than once, every callback will be executed.
*
* Eg. $bot->onChatJoinRequest(function(Context $ctx) {});
*
* @param $callback
* @param array $filters for ex. ['chat_type' => 'group'], in this case the listener will be executed only if the
* message is sent in a group chat.
* @return MiddlewareCollector
* @throws DependencyException
* @throws NotFoundException
*/
public function onChatJoinRequest($callback, array $filters = []): MiddlewareCollector
{
$listener = new Listener($callback, $this->container, null, $filters);
$this->listeners[ChatJoinRequest::class][] = $listener;
return $listener;
}

/**
* Listen for a generic update.
* You can call this function more than once, every callback will be executed.
Expand Down
65 changes: 65 additions & 0 deletions src/Zanzara/Telegram/TelegramTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -1740,6 +1740,71 @@ public function revokeChatInviteLink($chat_id, $invite_link): PromiseInterface
return $this->callApi("revokeChatInviteLink", $required, ChatInviteLink::class);
}

/**
* Use this method to approve a chat join request. The bot must be an administrator in the chat for this to work and
* must have the can_invite_users administrator right. Returns True on success.
*
* More on https://core.telegram.org/bots/api#approvechatjoinrequest
*
* @param $chat_id mixed Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param $user_id mixed Unique identifier of the target user
* @return PromiseInterface
*/
public function approveChatJoinRequest($chat_id, $user_id): PromiseInterface
{
$required = compact("chat_id", "user_id");
return $this->callApi("approveChatJoinRequest", $required);
}

/**
* Use this method to decline a chat join request. The bot must be an administrator in the chat for this to work and
* must have the can_invite_users administrator right. Returns True on success.
*
* More on https://core.telegram.org/bots/api#declinechatjoinrequest
*
* @param $chat_id mixed Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param $user_id mixed Unique identifier of the target user
* @return PromiseInterface
*/
public function declineChatJoinRequest($chat_id, $user_id): PromiseInterface
{
$required = compact("chat_id", "user_id");
return $this->callApi("declineChatJoinRequest", $required);
}

/**
* Use this method to ban a channel chat in a supergroup or a channel. Until the chat is unbanned, the owner of the
* banned chat won't be able to send messages on behalf of any of their channels. The bot must be an administrator
* in the supergroup or channel for this to work and must have the appropriate administrator rights. Returns True on success.
*
* More on https://core.telegram.org/bots/api#declinechatjoinrequest
*
* @param $chat_id mixed Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param $sender_chat_id mixed Unique identifier of the target sender chat
* @return PromiseInterface
*/
public function banChatSenderChat($chat_id, $sender_chat_id): PromiseInterface
{
$required = compact("chat_id", "sender_chat_id");
return $this->callApi("banChatSenderChat", $required);
}

/**
* Use this method to unban a previously banned channel chat in a supergroup or channel. The bot must be an administrator
* for this to work and must have the appropriate administrator rights. Returns True on success.
*
* More on https://core.telegram.org/bots/api#declinechatjoinrequest
*
* @param $chat_id mixed Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param $sender_chat_id mixed Unique identifier of the target sender chat
* @return PromiseInterface
*/
public function unbanChatSenderChat($chat_id, $sender_chat_id): PromiseInterface
{
$required = compact("chat_id", "sender_chat_id");
return $this->callApi("unbanChatSenderChat", $required);
}

/**
* @param string $method
* @param array $params
Expand Down
71 changes: 71 additions & 0 deletions src/Zanzara/Telegram/Type/Chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ class Chat implements \JsonSerializable
*/
private $bio;

/**
* Optional. True, if privacy settings of the other party in the private chat allows to use tg://user?id=<user_id>
* links only in chats with the user. Returned only in getChat.
*
* @var bool|null
*/
private $has_private_forwards;

/**
* Optional. Description, for groups, supergroups and channel chats. Returned only in getChat.
*
Expand Down Expand Up @@ -109,6 +117,21 @@ class Chat implements \JsonSerializable
*/
private $slow_mode_delay;

/**
* Optional. The time after which all messages sent to the chat will be automatically deleted; in seconds. Returned
* only in getChat.
*
* @var int|null
*/
private $message_auto_delete_time;

/**
* Optional. True, if messages from the chat can't be forwarded to other chats. Returned only in getChat.
*
* @var bool|null
*/
private $has_protected_content;

/**
* Optional. For supergroups, name of group sticker set. Returned only in getChat.
*
Expand Down Expand Up @@ -435,4 +458,52 @@ public function setLocation(?ChatLocation $location): void
$this->location = $location;
}

/**
* @return bool|null
*/
public function getHasPrivateForwards(): ?bool
{
return $this->has_private_forwards;
}

/**
* @param bool|null $has_private_forwards
*/
public function setHasPrivateForwards(?bool $has_private_forwards): void
{
$this->has_private_forwards = $has_private_forwards;
}

/**
* @return int|null
*/
public function getMessageAutoDeleteTime(): ?int
{
return $this->message_auto_delete_time;
}

/**
* @param int|null $message_auto_delete_time
*/
public function setMessageAutoDeleteTime(?int $message_auto_delete_time): void
{
$this->message_auto_delete_time = $message_auto_delete_time;
}

/**
* @return bool|null
*/
public function getHasProtectedContent(): ?bool
{
return $this->has_protected_content;
}

/**
* @param bool|null $has_protected_content
*/
public function setHasProtectedContent(?bool $has_protected_content): void
{
$this->has_protected_content = $has_protected_content;
}

}
69 changes: 69 additions & 0 deletions src/Zanzara/Telegram/Type/ChatInviteLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,27 @@ class ChatInviteLink
*/
private $member_limit;

/**
* True, if users joining the chat via the link need to be approved by chat administrators
*
* @var bool
*/
private $creates_join_request;

/**
* Optional. Number of pending join requests created using this link
*
* @var int|null
*/
private $pending_join_request_count;

/**
* Optional. Invite link name
*
* @var string|null
*/
private $name;

/**
* @return string
*/
Expand Down Expand Up @@ -176,4 +197,52 @@ public function setMemberLimit(?int $member_limit): void
$this->member_limit = $member_limit;
}

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

/**
* @param bool $creates_join_request
*/
public function setCreatesJoinRequest(bool $creates_join_request): void
{
$this->creates_join_request = $creates_join_request;
}

/**
* @return int|null
*/
public function getPendingJoinRequestCount(): ?int
{
return $this->pending_join_request_count;
}

/**
* @param int|null $pending_join_request_count
*/
public function setPendingJoinRequestCount(?int $pending_join_request_count): void
{
$this->pending_join_request_count = $pending_join_request_count;
}

/**
* @return string|null
*/
public function getName(): ?string
{
return $this->name;
}

/**
* @param string|null $name
*/
public function setName(?string $name): void
{
$this->name = $name;
}

}
Loading

0 comments on commit dc80682

Please sign in to comment.