Skip to content

Commit

Permalink
Merge pull request #449 from BoShurik/chat-member-update
Browse files Browse the repository at this point in the history
Add missing Update fields + invite link methods
  • Loading branch information
BoShurik authored Sep 5, 2023
2 parents eaae352 + e9f7838 commit 903df6b
Show file tree
Hide file tree
Showing 11 changed files with 1,046 additions and 4 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

All Notable changes to `PHP Telegram Bot Api` will be documented in this file

## 2.6.0 - YYYY-MM-DD
- Add `\TelegramBot\Api\Types\Update::$myChatMember` field
- Add `\TelegramBot\Api\Types\Update::$chatMember` field
- Add `\TelegramBot\Api\Types\Update::$chatJoinRequest` field
- Add `\TelegramBot\Api\BotApi::createChatInviteLink` api method
- Add `\TelegramBot\Api\BotApi::editChatInviteLink` api method
- Add `\TelegramBot\Api\BotApi::revokeChatInviteLink` api method
- Add `\TelegramBot\Api\BotApi::approveChatJoinRequest` api method
- Add `\TelegramBot\Api\BotApi::declineChatJoinRequest` api method

## 2.5.0 - 2023-08-09

### Added
Expand Down
9 changes: 7 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@
"coverage": "XDEBUG_MODE=coverage vendor/bin/simple-phpunit --coverage-html build/coverage",
"psalm": "vendor/bin/psalm",
"cs-fix": "vendor/bin/php-cs-fixer fix --allow-risky=yes --diff --ansi",
"cs-check": "vendor/bin/php-cs-fixer fix --allow-risky=yes --diff --ansi --dry-run"
"cs-check": "vendor/bin/php-cs-fixer fix --allow-risky=yes --diff --ansi --dry-run",
"checks": [
"@cs-fix",
"@psalm",
"@test"
]
},
"extra": {
"branch-alias": {
"dev-master": "2.5-dev"
"dev-master": "2.6-dev"
}
}
}
112 changes: 112 additions & 0 deletions src/BotApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use TelegramBot\Api\Types\ArrayOfUpdates;
use TelegramBot\Api\Types\BotCommand;
use TelegramBot\Api\Types\Chat;
use TelegramBot\Api\Types\ChatInviteLink;
use TelegramBot\Api\Types\ChatMember;
use TelegramBot\Api\Types\File;
use TelegramBot\Api\Types\ForceReply;
Expand Down Expand Up @@ -2126,6 +2127,117 @@ public function exportChatInviteLink($chatId)
]);
}

/**
* Use this method to create an additional invite link for a chat. The bot must be an administrator in the chat
* for this to work and must have the appropriate administrator rights.
* The link can be revoked using the method revokeChatInviteLink.
* Returns the new invite link as ChatInviteLink object.
*
* @param int|string $chatId Unique identifier for the target chat or
* username of the target channel (in the format @channelusername)
* @param string|null $name Invite link name; 0-32 characters
* @param int|null $expireDate Point in time (Unix timestamp) when the link will expire
* @param int|null $memberLimit The maximum number of users that can be members of the chat simultaneously
* after joining the chat via this invite link; 1-99999
* @param bool|null $createsJoinRequest True, if users joining the chat via the link need to be approved by chat administrators.
* If True, member_limit can't be specified
* @return ChatInviteLink
* @throws Exception
*/
public function createChatInviteLink($chatId, $name = null, $expireDate = null, $memberLimit = null, $createsJoinRequest = null)
{
return ChatInviteLink::fromResponse($this->call('createChatInviteLink', [
'chat_id' => $chatId,
'name' => $name,
'expire_date' => $expireDate,
'member_limit' => $memberLimit,
'creates_join_request' => $createsJoinRequest,
]));
}

/**
* Use this method to edit a non-primary invite link created by the bot.
* The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
* Returns the edited invite link as a ChatInviteLink object.
*
* @param int|string $chatId Unique identifier for the target chat or
* username of the target channel (in the format @channelusername)
* @param string $inviteLink The invite link to edit
* @param string|null $name Invite link name; 0-32 characters
* @param int|null $expireDate Point in time (Unix timestamp) when the link will expire
* @param int|null $memberLimit The maximum number of users that can be members of the chat simultaneously
* after joining the chat via this invite link; 1-99999
* @param bool|null $createsJoinRequest True, if users joining the chat via the link need to be approved by chat administrators.
* If True, member_limit can't be specified
* @return ChatInviteLink
* @throws Exception
*/
public function editChatInviteLink($chatId, $inviteLink, $name = null, $expireDate = null, $memberLimit = null, $createsJoinRequest = null)
{
return ChatInviteLink::fromResponse($this->call('editChatInviteLink', [
'chat_id' => $chatId,
'invite_link' => $inviteLink,
'name' => $name,
'expire_date' => $expireDate,
'member_limit' => $memberLimit,
'creates_join_request' => $createsJoinRequest,
]));
}

/**
* Use this method to revoke an invite link created by the bot.
* If the primary link is revoked, a new link is automatically generated.
* The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
* Returns the revoked invite link as ChatInviteLink object.
*
* @param int|string $chatId Unique identifier for the target chat or
* username of the target channel (in the format @channelusername)
* @param string $inviteLink The invite link to edit
* @return ChatInviteLink
* @throws Exception
*/
public function revokeChatInviteLink($chatId, $inviteLink)
{
return ChatInviteLink::fromResponse($this->call('revokeChatInviteLink', [
'chat_id' => $chatId,
'invite_link' => $inviteLink,
]));
}

/**
* 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.
*
* @param int|string $chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param int $userId Unique identifier of the target user
* @return bool
* @throws Exception
*/
public function approveChatJoinRequest($chatId, $userId)
{
return $this->call('approveChatJoinRequest', [
'chat_id' => $chatId,
'user_id' => $userId,
]);
}

/**
* 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.
*
* @param int|string $chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param int $userId Unique identifier of the target user
* @return bool
* @throws Exception
*/
public function declineChatJoinRequest($chatId, $userId)
{
return $this->call('declineChatJoinRequest', [
'chat_id' => $chatId,
'user_id' => $userId,
]);
}

/**
* Use this method to set a new profile photo for the chat. Photos can't be changed for private chats.
* The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
Expand Down
Loading

0 comments on commit 903df6b

Please sign in to comment.