|
5 | 5 | namespace BushlanovDev\MaxMessengerBot;
|
6 | 6 |
|
7 | 7 | use BushlanovDev\MaxMessengerBot\Enums\MessageFormat;
|
| 8 | +use BushlanovDev\MaxMessengerBot\Enums\SenderAction; |
8 | 9 | use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
|
9 | 10 | use BushlanovDev\MaxMessengerBot\Enums\UploadType;
|
10 | 11 | use BushlanovDev\MaxMessengerBot\Exceptions\ClientApiException;
|
|
19 | 20 | use BushlanovDev\MaxMessengerBot\Models\Attachments\Requests\VideoAttachmentRequest;
|
20 | 21 | use BushlanovDev\MaxMessengerBot\Models\BotInfo;
|
21 | 22 | use BushlanovDev\MaxMessengerBot\Models\Chat;
|
| 23 | +use BushlanovDev\MaxMessengerBot\Models\ChatList; |
22 | 24 | use BushlanovDev\MaxMessengerBot\Models\Message;
|
23 | 25 | use BushlanovDev\MaxMessengerBot\Models\MessageLink;
|
24 | 26 | use BushlanovDev\MaxMessengerBot\Models\Result;
|
@@ -46,6 +48,7 @@ class Api
|
46 | 48 | private const string METHOD_GET = 'GET';
|
47 | 49 | private const string METHOD_POST = 'POST';
|
48 | 50 | private const string METHOD_DELETE = 'DELETE';
|
| 51 | +// private const string METHOD_PATCH = 'PATCH'; |
49 | 52 |
|
50 | 53 | private const string ACTION_ME = '/me';
|
51 | 54 | private const string ACTION_SUBSCRIPTIONS = '/subscriptions';
|
@@ -477,4 +480,99 @@ public function getChat(int $chatId): Chat
|
477 | 480 | $this->client->request(self::METHOD_GET, self::ACTION_CHATS . '/' . $chatId)
|
478 | 481 | );
|
479 | 482 | }
|
| 483 | + |
| 484 | + /** |
| 485 | + * Returns chat/channel information by its public link or a dialog with a user by their username. |
| 486 | + * The link should be prefixed with '@' or can be passed without it. |
| 487 | + * |
| 488 | + * @param string $chatLink Public chat link (e.g., '@mychannel') or username (e.g., '@john_doe'). |
| 489 | + * |
| 490 | + * @return Chat |
| 491 | + * @throws ClientApiException |
| 492 | + * @throws NetworkException |
| 493 | + * @throws ReflectionException |
| 494 | + * @throws SerializationException |
| 495 | + */ |
| 496 | + public function getChatByLink(string $chatLink): Chat |
| 497 | + { |
| 498 | + return $this->modelFactory->createChat( |
| 499 | + $this->client->request( |
| 500 | + self::METHOD_GET, |
| 501 | + self::ACTION_CHATS . '/' . $chatLink, |
| 502 | + ) |
| 503 | + ); |
| 504 | + } |
| 505 | + |
| 506 | + /** |
| 507 | + * Returns information about chats that the bot participated in. The result is a paginated list. |
| 508 | + * |
| 509 | + * @param int|null $count Number of chats requested (1-100, default 50). |
| 510 | + * @param int|null $marker Points to the next data page. Use null for the first page. |
| 511 | + * |
| 512 | + * @return ChatList |
| 513 | + * @throws ClientApiException |
| 514 | + * @throws NetworkException |
| 515 | + * @throws ReflectionException |
| 516 | + * @throws SerializationException |
| 517 | + */ |
| 518 | + public function getChats(?int $count = null, ?int $marker = null): ChatList |
| 519 | + { |
| 520 | + $query = [ |
| 521 | + 'count' => $count, |
| 522 | + 'marker' => $marker, |
| 523 | + ]; |
| 524 | + |
| 525 | + return $this->modelFactory->createChatList( |
| 526 | + $this->client->request( |
| 527 | + self::METHOD_GET, |
| 528 | + self::ACTION_CHATS, |
| 529 | + array_filter($query, fn($value) => $value !== null), |
| 530 | + ) |
| 531 | + ); |
| 532 | + } |
| 533 | + |
| 534 | + /** |
| 535 | + * Deletes a chat for all participants. The bot must have appropriate permissions. |
| 536 | + * |
| 537 | + * @param int $chatId Chat identifier to delete. |
| 538 | + * |
| 539 | + * @return Result |
| 540 | + * @throws ClientApiException |
| 541 | + * @throws NetworkException |
| 542 | + * @throws ReflectionException |
| 543 | + * @throws SerializationException |
| 544 | + */ |
| 545 | + public function deleteChat(int $chatId): Result |
| 546 | + { |
| 547 | + return $this->modelFactory->createResult( |
| 548 | + $this->client->request( |
| 549 | + self::METHOD_DELETE, |
| 550 | + self::ACTION_CHATS . '/' . $chatId, |
| 551 | + ) |
| 552 | + ); |
| 553 | + } |
| 554 | + |
| 555 | + /** |
| 556 | + * Sends a specific action to a chat, such as 'typing...'. This is used to show bot activity to the user. |
| 557 | + * |
| 558 | + * @param int $chatId The identifier of the target chat. |
| 559 | + * @param SenderAction $action The action to be sent. |
| 560 | + * |
| 561 | + * @return Result |
| 562 | + * @throws ClientApiException |
| 563 | + * @throws NetworkException |
| 564 | + * @throws ReflectionException |
| 565 | + * @throws SerializationException |
| 566 | + */ |
| 567 | + public function sendAction(int $chatId, SenderAction $action): Result |
| 568 | + { |
| 569 | + return $this->modelFactory->createResult( |
| 570 | + $this->client->request( |
| 571 | + self::METHOD_POST, |
| 572 | + self::ACTION_CHATS . '/' . $chatId . '/actions', |
| 573 | + [], |
| 574 | + ['action' => $action->value], |
| 575 | + ) |
| 576 | + ); |
| 577 | + } |
480 | 578 | }
|
0 commit comments