Skip to content

Commit e9f7838

Browse files
committed
my_chat_member, chat_member, chat_join_request updates and invite link methods
1 parent eaae352 commit e9f7838

File tree

11 files changed

+1046
-4
lines changed

11 files changed

+1046
-4
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

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

5+
## 2.6.0 - YYYY-MM-DD
6+
- Add `\TelegramBot\Api\Types\Update::$myChatMember` field
7+
- Add `\TelegramBot\Api\Types\Update::$chatMember` field
8+
- Add `\TelegramBot\Api\Types\Update::$chatJoinRequest` field
9+
- Add `\TelegramBot\Api\BotApi::createChatInviteLink` api method
10+
- Add `\TelegramBot\Api\BotApi::editChatInviteLink` api method
11+
- Add `\TelegramBot\Api\BotApi::revokeChatInviteLink` api method
12+
- Add `\TelegramBot\Api\BotApi::approveChatJoinRequest` api method
13+
- Add `\TelegramBot\Api\BotApi::declineChatJoinRequest` api method
14+
515
## 2.5.0 - 2023-08-09
616

717
### Added

composer.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,16 @@
4242
"coverage": "XDEBUG_MODE=coverage vendor/bin/simple-phpunit --coverage-html build/coverage",
4343
"psalm": "vendor/bin/psalm",
4444
"cs-fix": "vendor/bin/php-cs-fixer fix --allow-risky=yes --diff --ansi",
45-
"cs-check": "vendor/bin/php-cs-fixer fix --allow-risky=yes --diff --ansi --dry-run"
45+
"cs-check": "vendor/bin/php-cs-fixer fix --allow-risky=yes --diff --ansi --dry-run",
46+
"checks": [
47+
"@cs-fix",
48+
"@psalm",
49+
"@test"
50+
]
4651
},
4752
"extra": {
4853
"branch-alias": {
49-
"dev-master": "2.5-dev"
54+
"dev-master": "2.6-dev"
5055
}
5156
}
5257
}

src/BotApi.php

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use TelegramBot\Api\Types\ArrayOfUpdates;
1111
use TelegramBot\Api\Types\BotCommand;
1212
use TelegramBot\Api\Types\Chat;
13+
use TelegramBot\Api\Types\ChatInviteLink;
1314
use TelegramBot\Api\Types\ChatMember;
1415
use TelegramBot\Api\Types\File;
1516
use TelegramBot\Api\Types\ForceReply;
@@ -2126,6 +2127,117 @@ public function exportChatInviteLink($chatId)
21262127
]);
21272128
}
21282129

2130+
/**
2131+
* Use this method to create an additional invite link for a chat. The bot must be an administrator in the chat
2132+
* for this to work and must have the appropriate administrator rights.
2133+
* The link can be revoked using the method revokeChatInviteLink.
2134+
* Returns the new invite link as ChatInviteLink object.
2135+
*
2136+
* @param int|string $chatId Unique identifier for the target chat or
2137+
* username of the target channel (in the format @channelusername)
2138+
* @param string|null $name Invite link name; 0-32 characters
2139+
* @param int|null $expireDate Point in time (Unix timestamp) when the link will expire
2140+
* @param int|null $memberLimit The maximum number of users that can be members of the chat simultaneously
2141+
* after joining the chat via this invite link; 1-99999
2142+
* @param bool|null $createsJoinRequest True, if users joining the chat via the link need to be approved by chat administrators.
2143+
* If True, member_limit can't be specified
2144+
* @return ChatInviteLink
2145+
* @throws Exception
2146+
*/
2147+
public function createChatInviteLink($chatId, $name = null, $expireDate = null, $memberLimit = null, $createsJoinRequest = null)
2148+
{
2149+
return ChatInviteLink::fromResponse($this->call('createChatInviteLink', [
2150+
'chat_id' => $chatId,
2151+
'name' => $name,
2152+
'expire_date' => $expireDate,
2153+
'member_limit' => $memberLimit,
2154+
'creates_join_request' => $createsJoinRequest,
2155+
]));
2156+
}
2157+
2158+
/**
2159+
* Use this method to edit a non-primary invite link created by the bot.
2160+
* The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
2161+
* Returns the edited invite link as a ChatInviteLink object.
2162+
*
2163+
* @param int|string $chatId Unique identifier for the target chat or
2164+
* username of the target channel (in the format @channelusername)
2165+
* @param string $inviteLink The invite link to edit
2166+
* @param string|null $name Invite link name; 0-32 characters
2167+
* @param int|null $expireDate Point in time (Unix timestamp) when the link will expire
2168+
* @param int|null $memberLimit The maximum number of users that can be members of the chat simultaneously
2169+
* after joining the chat via this invite link; 1-99999
2170+
* @param bool|null $createsJoinRequest True, if users joining the chat via the link need to be approved by chat administrators.
2171+
* If True, member_limit can't be specified
2172+
* @return ChatInviteLink
2173+
* @throws Exception
2174+
*/
2175+
public function editChatInviteLink($chatId, $inviteLink, $name = null, $expireDate = null, $memberLimit = null, $createsJoinRequest = null)
2176+
{
2177+
return ChatInviteLink::fromResponse($this->call('editChatInviteLink', [
2178+
'chat_id' => $chatId,
2179+
'invite_link' => $inviteLink,
2180+
'name' => $name,
2181+
'expire_date' => $expireDate,
2182+
'member_limit' => $memberLimit,
2183+
'creates_join_request' => $createsJoinRequest,
2184+
]));
2185+
}
2186+
2187+
/**
2188+
* Use this method to revoke an invite link created by the bot.
2189+
* If the primary link is revoked, a new link is automatically generated.
2190+
* The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
2191+
* Returns the revoked invite link as ChatInviteLink object.
2192+
*
2193+
* @param int|string $chatId Unique identifier for the target chat or
2194+
* username of the target channel (in the format @channelusername)
2195+
* @param string $inviteLink The invite link to edit
2196+
* @return ChatInviteLink
2197+
* @throws Exception
2198+
*/
2199+
public function revokeChatInviteLink($chatId, $inviteLink)
2200+
{
2201+
return ChatInviteLink::fromResponse($this->call('revokeChatInviteLink', [
2202+
'chat_id' => $chatId,
2203+
'invite_link' => $inviteLink,
2204+
]));
2205+
}
2206+
2207+
/**
2208+
* Use this method to approve a chat join request. The bot must be an administrator in the chat for this to work and
2209+
* must have the can_invite_users administrator right. Returns True on success.
2210+
*
2211+
* @param int|string $chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
2212+
* @param int $userId Unique identifier of the target user
2213+
* @return bool
2214+
* @throws Exception
2215+
*/
2216+
public function approveChatJoinRequest($chatId, $userId)
2217+
{
2218+
return $this->call('approveChatJoinRequest', [
2219+
'chat_id' => $chatId,
2220+
'user_id' => $userId,
2221+
]);
2222+
}
2223+
2224+
/**
2225+
* Use this method to decline a chat join request. The bot must be an administrator in the chat for this to work and
2226+
* must have the can_invite_users administrator right. Returns True on success.
2227+
*
2228+
* @param int|string $chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
2229+
* @param int $userId Unique identifier of the target user
2230+
* @return bool
2231+
* @throws Exception
2232+
*/
2233+
public function declineChatJoinRequest($chatId, $userId)
2234+
{
2235+
return $this->call('declineChatJoinRequest', [
2236+
'chat_id' => $chatId,
2237+
'user_id' => $userId,
2238+
]);
2239+
}
2240+
21292241
/**
21302242
* Use this method to set a new profile photo for the chat. Photos can't be changed for private chats.
21312243
* The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.

0 commit comments

Comments
 (0)