Skip to content

Commit

Permalink
Merge pull request #615 from HFUBlackRabbit/chat-join-requests-actions
Browse files Browse the repository at this point in the history
[feat] chat join request management
  • Loading branch information
fabio-ivona authored Aug 26, 2024
2 parents 847276d + 06bd778 commit 86cdb50
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Concerns/HasBotsAndChats.php
Original file line number Diff line number Diff line change
Expand Up @@ -529,4 +529,26 @@ public function demoteChatMember(string $userId): Telegraph

return $telegraph;
}

public function approveChatJoinRequest(string $userId): Telegraph
{
$telegraph = clone $this;

$telegraph->endpoint = self::ENDPOINT_APPROVE_CHAT_JOIN_REQUEST;
$telegraph->data['chat_id'] = $telegraph->getChatId();
$telegraph->data['user_id'] = $userId;

return $telegraph;
}

public function declineChatJoinRequest(string $userId): Telegraph
{
$telegraph = clone $this;

$telegraph->endpoint = self::ENDPOINT_DECLINE_CHAT_JOIN_REQUEST;
$telegraph->data['chat_id'] = $telegraph->getChatId();
$telegraph->data['user_id'] = $userId;

return $telegraph;
}
}
10 changes: 10 additions & 0 deletions src/Models/TelegraphChat.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,16 @@ public function demoteMember(string $userId): Telegraph
return TelegraphFacade::chat($this)->demoteChatMember($userId);
}

public function acceptInvite(string $userId): Telegraph
{
return TelegraphFacade::chat($this)->approveChatJoinRequest($userId);
}

public function declineInvite(string $userId): Telegraph
{
return TelegraphFacade::chat($this)->declineChatJoinRequest($userId);
}

public function poll(string $question): TelegraphPollPayload
{
return TelegraphFacade::chat($this)->poll($question);
Expand Down
2 changes: 2 additions & 0 deletions src/Telegraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ class Telegraph
public const ENDPOINT_GET_CHAT_MENU_BUTTON = 'getChatMenuButton';
public const ENDPOINT_DICE = 'sendDice';
public const ENDPOINT_SEND_STICKER = 'sendSticker';
public const ENDPOINT_APPROVE_CHAT_JOIN_REQUEST = 'approveChatJoinRequest';
public const ENDPOINT_DECLINE_CHAT_JOIN_REQUEST = 'declineChatJoinRequest';


/** @var array<string, mixed> */
Expand Down
22 changes: 22 additions & 0 deletions tests/Unit/Models/TelegraphChatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -838,3 +838,25 @@
'message_thread_id' => 5,
]);
});

it('can accept chat join request', function () {
Telegraph::fake();
$chat = make_chat();

$chat->acceptInvite(123456)->send();

Telegraph::assertSentData(\DefStudio\Telegraph\Telegraph::ENDPOINT_APPROVE_CHAT_JOIN_REQUEST, [
'user_id' => 123456
], false);
});

it('can decline chat join request', function () {
Telegraph::fake();
$chat = make_chat();

$chat->declineInvite(123456)->send();

Telegraph::assertSentData(\DefStudio\Telegraph\Telegraph::ENDPOINT_DECLINE_CHAT_JOIN_REQUEST, [
'user_id' => 123456
], false);
});

0 comments on commit 86cdb50

Please sign in to comment.