Added subscribe method

This commit is contained in:
Alex
2025-07-08 21:46:04 +03:00
parent 45020eab52
commit b997fa17ab
6 changed files with 137 additions and 3 deletions
+26 -1
View File
@@ -8,7 +8,9 @@ use BushlanovDev\MaxMessengerBot\Exceptions\ClientApiException;
use BushlanovDev\MaxMessengerBot\Exceptions\NetworkException;
use BushlanovDev\MaxMessengerBot\Exceptions\SerializationException;
use BushlanovDev\MaxMessengerBot\Models\BotInfo;
use BushlanovDev\MaxMessengerBot\Models\ResultModel;
use BushlanovDev\MaxMessengerBot\Models\Subscription;
use BushlanovDev\MaxMessengerBot\Models\SubscriptionRequestBody;
use InvalidArgumentException;
/**
@@ -20,7 +22,7 @@ use InvalidArgumentException;
class Api
{
private const string METHOD_GET = 'GET';
// private const string METHOD_POST = 'POST';
private const string METHOD_POST = 'POST';
// private const string METHOD_DELETE = 'DELETE';
private const string ACTION_ME = '/me';
@@ -84,4 +86,27 @@ class Api
$this->client->request(self::METHOD_GET, self::ACTION_SUBSCRIPTIONS)
);
}
/**
* Subscribes the bot to receive updates via WebHook.
*
* @param SubscriptionRequestBody $body
*
* @return ResultModel
*
* @throws ClientApiException
* @throws NetworkException
* @throws SerializationException
*/
public function subscribe(SubscriptionRequestBody $body): ResultModel
{
return $this->modelFactory->createResult(
$this->client->request(
self::METHOD_POST,
self::ACTION_SUBSCRIPTIONS,
[],
$body->toArray(),
)
);
}
}