|
22 | 22 | use BushlanovDev\MaxMessengerBot\Models\Chat;
|
23 | 23 | use BushlanovDev\MaxMessengerBot\Models\ChatList;
|
24 | 24 | use BushlanovDev\MaxMessengerBot\Models\ChatMember;
|
| 25 | +use BushlanovDev\MaxMessengerBot\Models\ChatMembersList; |
25 | 26 | use BushlanovDev\MaxMessengerBot\Models\Message;
|
26 | 27 | use BushlanovDev\MaxMessengerBot\Models\MessageLink;
|
27 | 28 | use BushlanovDev\MaxMessengerBot\Models\Result;
|
@@ -60,6 +61,9 @@ class Api
|
60 | 61 | private const string ACTION_CHATS_ACTIONS = '/chats/%d/actions';
|
61 | 62 | private const string ACTION_CHATS_PIN = '/chats/%d/pin';
|
62 | 63 | private const string ACTION_CHATS_MEMBERS_ME = '/chats/%d/members/me';
|
| 64 | + private const string ACTION_CHATS_MEMBERS_ADMINS = '/chats/%d/members/admins'; |
| 65 | + private const string ACTION_CHATS_MEMBERS_ADMINS_ID = '/chats/%d/members/admins/%d'; |
| 66 | + private const string ACTION_CHATS_MEMBERS = '/chats/%d/members'; |
63 | 67 | private const string ACTION_UPDATES = '/updates';
|
64 | 68 |
|
65 | 69 | private readonly ClientApiInterface $client;
|
@@ -703,7 +707,7 @@ public function getMessages(
|
703 | 707 | $response = $this->client->request(
|
704 | 708 | self::METHOD_GET,
|
705 | 709 | self::ACTION_MESSAGES,
|
706 |
| - array_filter($query, fn ($value) => $value !== null) |
| 710 | + array_filter($query, fn($value) => $value !== null), |
707 | 711 | );
|
708 | 712 |
|
709 | 713 | return $this->modelFactory->createMessages($response);
|
@@ -779,4 +783,111 @@ public function pinMessage(int $chatId, string $messageId, bool $notify = true):
|
779 | 783 | )
|
780 | 784 | );
|
781 | 785 | }
|
| 786 | + |
| 787 | + /** |
| 788 | + * Returns all chat administrators. The bot must be an administrator in the requested chat. |
| 789 | + * |
| 790 | + * @param int $chatId Chat identifier. |
| 791 | + * |
| 792 | + * @return ChatMembersList |
| 793 | + * @throws ClientApiException |
| 794 | + * @throws NetworkException |
| 795 | + * @throws ReflectionException |
| 796 | + * @throws SerializationException |
| 797 | + */ |
| 798 | + public function getAdmins(int $chatId): ChatMembersList |
| 799 | + { |
| 800 | + return $this->modelFactory->createChatMembersList( |
| 801 | + $this->client->request( |
| 802 | + self::METHOD_GET, |
| 803 | + sprintf(self::ACTION_CHATS_MEMBERS_ADMINS, $chatId), |
| 804 | + ) |
| 805 | + ); |
| 806 | + } |
| 807 | + |
| 808 | + /** |
| 809 | + * Returns a paginated list of users who are participating in a chat. |
| 810 | + * |
| 811 | + * @param int $chatId The identifier of the chat. |
| 812 | + * @param int[]|null $userIds A list of user identifiers to get their specific membership. |
| 813 | + * When this parameter is passed, `count` and `marker` are ignored. |
| 814 | + * @param int|null $marker The pagination marker to get the next page of members. |
| 815 | + * @param int|null $count The number of members to return (1-100, default is 20). |
| 816 | + * |
| 817 | + * @return ChatMembersList |
| 818 | + * @throws ClientApiException |
| 819 | + * @throws NetworkException |
| 820 | + * @throws ReflectionException |
| 821 | + * @throws SerializationException |
| 822 | + */ |
| 823 | + public function getMembers( |
| 824 | + int $chatId, |
| 825 | + ?array $userIds = null, |
| 826 | + ?int $marker = null, |
| 827 | + ?int $count = null |
| 828 | + ): ChatMembersList { |
| 829 | + $query = [ |
| 830 | + 'user_ids' => $userIds !== null ? implode(',', $userIds) : null, |
| 831 | + 'marker' => $marker, |
| 832 | + 'count' => $count, |
| 833 | + ]; |
| 834 | + |
| 835 | + return $this->modelFactory->createChatMembersList( |
| 836 | + $this->client->request( |
| 837 | + self::METHOD_GET, |
| 838 | + sprintf(self::ACTION_CHATS_MEMBERS, $chatId), |
| 839 | + array_filter($query, fn($value) => $value !== null), |
| 840 | + ) |
| 841 | + ); |
| 842 | + } |
| 843 | + |
| 844 | + /** |
| 845 | + * Revokes admin rights from a user in the chat. |
| 846 | + * |
| 847 | + * @param int $chatId The identifier of the chat. |
| 848 | + * @param int $userId The identifier of the user to revoke admin rights from. |
| 849 | + * |
| 850 | + * @return Result |
| 851 | + * @throws ClientApiException |
| 852 | + * @throws NetworkException |
| 853 | + * @throws ReflectionException |
| 854 | + * @throws SerializationException |
| 855 | + */ |
| 856 | + public function deleteAdmins(int $chatId, int $userId): Result |
| 857 | + { |
| 858 | + return $this->modelFactory->createResult( |
| 859 | + $this->client->request( |
| 860 | + self::METHOD_DELETE, |
| 861 | + sprintf(self::ACTION_CHATS_MEMBERS_ADMINS_ID, $chatId, $userId), |
| 862 | + ) |
| 863 | + ); |
| 864 | + } |
| 865 | + |
| 866 | + /** |
| 867 | + * Removes a member from a chat. The bot may require additional permissions. |
| 868 | + * |
| 869 | + * @param int $chatId The identifier of the chat. |
| 870 | + * @param int $userId The identifier of the user to remove. |
| 871 | + * @param bool $block Set to true if the user should also be blocked in the chat. |
| 872 | + * Applicable only for chats with a public or private link. |
| 873 | + * |
| 874 | + * @return Result |
| 875 | + * @throws ClientApiException |
| 876 | + * @throws NetworkException |
| 877 | + * @throws ReflectionException |
| 878 | + * @throws SerializationException |
| 879 | + */ |
| 880 | + public function removeMember(int $chatId, int $userId, bool $block = false): Result |
| 881 | + { |
| 882 | + return $this->modelFactory->createResult( |
| 883 | + $this->client->request( |
| 884 | + self::METHOD_DELETE, |
| 885 | + sprintf(self::ACTION_CHATS_MEMBERS, $chatId), |
| 886 | + [ |
| 887 | + 'user_id' => $userId, |
| 888 | + 'block' => $block, |
| 889 | + ], |
| 890 | + ) |
| 891 | + ); |
| 892 | + } |
782 | 893 | }
|
0 commit comments