mirror of
https://github.com/BushlanovDev/max-bot-api-client-php.git
synced 2026-11-27 07:52:33 +00:00
Added AudioAttachmentRequest & ContactAttachmentRequest & FileAttachmentRequest & LocationAttachmentRequest & ShareAttachmentRequest & StickerAttachmentRequest & VideoAttachmentRequest
This commit is contained in:
+1
-1
@@ -6,6 +6,6 @@ namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Models\AbstractModel;
|
||||
|
||||
abstract readonly class AbstractAttachmentPayload extends AbstractModel
|
||||
abstract readonly class AbstractAttachmentRequestPayload extends AbstractModel
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads;
|
||||
|
||||
/**
|
||||
* Payload for a contact attachment request.
|
||||
*/
|
||||
final readonly class ContactAttachmentRequestPayload extends AbstractAttachmentRequestPayload
|
||||
{
|
||||
/**
|
||||
* @param string|null $name Contact name.
|
||||
* @param int|null $contactId Contact identifier if it is a registered Max user.
|
||||
* @param string|null $vcfInfo Full information about the contact in VCF format.
|
||||
* @param string|null $vcfPhone Contact phone in VCF format.
|
||||
*/
|
||||
public function __construct(
|
||||
public ?string $name = null,
|
||||
public ?int $contactId = null,
|
||||
public ?string $vcfInfo = null,
|
||||
public ?string $vcfPhone = null,
|
||||
) {
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -6,7 +6,7 @@ namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\AbstractButton;
|
||||
|
||||
final readonly class InlineKeyboardPayload extends AbstractAttachmentPayload
|
||||
final readonly class InlineKeyboardAttachmentRequestPayload extends AbstractAttachmentRequestPayload
|
||||
{
|
||||
/**
|
||||
* @param AbstractButton[][] $buttons
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads;
|
||||
|
||||
/**
|
||||
* Payload for a location attachment request.
|
||||
*/
|
||||
final readonly class LocationAttachmentRequestPayload extends AbstractAttachmentRequestPayload
|
||||
{
|
||||
/**
|
||||
* @param float $latitude Latitude as a floating-point number.
|
||||
* @param float $longitude Longitude as a floating-point number.
|
||||
*/
|
||||
public function __construct(
|
||||
public float $latitude,
|
||||
public float $longitude,
|
||||
) {
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -10,7 +10,7 @@ use InvalidArgumentException;
|
||||
/**
|
||||
* Request to attach image. All fields are mutually exclusive.
|
||||
*/
|
||||
final readonly class PhotoAttachmentPayload extends AbstractAttachmentPayload
|
||||
final readonly class PhotoAttachmentRequestPayload extends AbstractAttachmentRequestPayload
|
||||
{
|
||||
/**
|
||||
* @param string|null $url Any external image URL you want to attach.
|
||||
@@ -25,7 +25,7 @@ final readonly class PhotoAttachmentPayload extends AbstractAttachmentPayload
|
||||
) {
|
||||
if (count(array_filter([$this->url, $this->token, $this->photos])) !== 1) {
|
||||
throw new InvalidArgumentException(
|
||||
'Provide exactly one of "url", "token", or "photos" for PhotoAttachmentPayload.'
|
||||
'Provide exactly one of "url", "token", or "photos" for PhotoAttachmentRequestPayload.'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Payload for a share (URL preview) attachment request.
|
||||
*/
|
||||
final readonly class ShareAttachmentRequestPayload extends AbstractAttachmentRequestPayload
|
||||
{
|
||||
/**
|
||||
* @param string|null $url URL to be attached to the message for media preview.
|
||||
* @param string|null $token Token of a previously generated share attachment.
|
||||
*/
|
||||
public function __construct(
|
||||
public ?string $url = null,
|
||||
public ?string $token = null,
|
||||
) {
|
||||
if (count(array_filter([$this->url, $this->token])) !== 1) {
|
||||
throw new InvalidArgumentException(
|
||||
'Provide exactly one of "url" or "token" for ShareAttachmentRequestPayload.'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads;
|
||||
|
||||
/**
|
||||
* Payload for a sticker attachment request.
|
||||
*/
|
||||
final readonly class StickerAttachmentRequestPayload extends AbstractAttachmentRequestPayload
|
||||
{
|
||||
/**
|
||||
* @param string $code The unique code of the sticker to be sent.
|
||||
*/
|
||||
public function __construct(
|
||||
public string $code,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads;
|
||||
|
||||
/**
|
||||
* Payload for attachments that are uploaded to the server first (video, audio, file).
|
||||
*/
|
||||
final readonly class UploadedInfoAttachmentRequestPayload extends AbstractAttachmentRequestPayload
|
||||
{
|
||||
/**
|
||||
* @param string $token The unique token received after a successful file upload.
|
||||
*/
|
||||
public function __construct(
|
||||
public string $token,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Requests;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\AbstractModel;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\AbstractAttachmentPayload;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\AbstractAttachmentRequestPayload;
|
||||
|
||||
/**
|
||||
* Message attachments.
|
||||
@@ -15,7 +15,7 @@ abstract readonly class AbstractAttachmentRequest extends AbstractModel
|
||||
{
|
||||
public function __construct(
|
||||
public AttachmentType $type,
|
||||
public AbstractAttachmentPayload $payload,
|
||||
public AbstractAttachmentRequestPayload $payload,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Requests;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\UploadedInfoAttachmentRequestPayload;
|
||||
|
||||
/**
|
||||
* Request to attach an audio file to a message.
|
||||
*/
|
||||
final readonly class AudioAttachmentRequest extends AbstractAttachmentRequest
|
||||
{
|
||||
/**
|
||||
* @param string $token The unique token received after a successful audio file upload.
|
||||
*/
|
||||
public function __construct(string $token)
|
||||
{
|
||||
parent::__construct(
|
||||
AttachmentType::Audio,
|
||||
new UploadedInfoAttachmentRequestPayload($token),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Requests;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\ContactAttachmentRequestPayload;
|
||||
|
||||
/**
|
||||
* Request to attach a contact card to a message.
|
||||
*/
|
||||
final readonly class ContactAttachmentRequest extends AbstractAttachmentRequest
|
||||
{
|
||||
/**
|
||||
* @param string|null $name Contact name.
|
||||
* @param int|null $contactId Contact identifier if it is a registered Max user.
|
||||
* @param string|null $vcfInfo Full information about the contact in VCF format.
|
||||
* @param string|null $vcfPhone Contact phone in VCF format.
|
||||
*/
|
||||
public function __construct(
|
||||
?string $name = null,
|
||||
?int $contactId = null,
|
||||
?string $vcfInfo = null,
|
||||
?string $vcfPhone = null
|
||||
) {
|
||||
parent::__construct(
|
||||
AttachmentType::Contact,
|
||||
new ContactAttachmentRequestPayload($name, $contactId, $vcfInfo, $vcfPhone),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Requests;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\UploadedInfoAttachmentRequestPayload;
|
||||
|
||||
/**
|
||||
* Request to attach a generic file to a message.
|
||||
*/
|
||||
final readonly class FileAttachmentRequest extends AbstractAttachmentRequest
|
||||
{
|
||||
/**
|
||||
* @param string $token The unique token received after a successful file upload.
|
||||
*/
|
||||
public function __construct(string $token)
|
||||
{
|
||||
parent::__construct(
|
||||
AttachmentType::File,
|
||||
new UploadedInfoAttachmentRequestPayload($token),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Requests;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\AbstractButton;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\InlineKeyboardPayload;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\InlineKeyboardAttachmentRequestPayload;
|
||||
|
||||
final readonly class InlineKeyboardAttachmentRequest extends AbstractAttachmentRequest
|
||||
{
|
||||
@@ -17,7 +17,7 @@ final readonly class InlineKeyboardAttachmentRequest extends AbstractAttachmentR
|
||||
{
|
||||
parent::__construct(
|
||||
AttachmentType::InlineKeyboard,
|
||||
new InlineKeyboardPayload($buttons)
|
||||
new InlineKeyboardAttachmentRequestPayload($buttons),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Requests;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\LocationAttachmentRequestPayload;
|
||||
|
||||
/**
|
||||
* Request to attach a geographical location to a message.
|
||||
*/
|
||||
final readonly class LocationAttachmentRequest extends AbstractAttachmentRequest
|
||||
{
|
||||
/**
|
||||
* @param float $latitude Latitude as a floating-point number.
|
||||
* @param float $longitude Longitude as a floating-point number.
|
||||
*/
|
||||
public function __construct(float $latitude, float $longitude)
|
||||
{
|
||||
parent::__construct(
|
||||
AttachmentType::Location,
|
||||
new LocationAttachmentRequestPayload($latitude, $longitude),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ declare(strict_types=1);
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Requests;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\PhotoAttachmentPayload;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\PhotoAttachmentRequestPayload;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\PhotoToken;
|
||||
|
||||
/**
|
||||
@@ -22,7 +22,7 @@ final readonly class PhotoAttachmentRequest extends AbstractAttachmentRequest
|
||||
*/
|
||||
public static function fromUrl(string $url): self
|
||||
{
|
||||
return new self(new PhotoAttachmentPayload(url: $url));
|
||||
return new self(new PhotoAttachmentRequestPayload(url: $url));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,7 +34,7 @@ final readonly class PhotoAttachmentRequest extends AbstractAttachmentRequest
|
||||
*/
|
||||
public static function fromToken(string $token): self
|
||||
{
|
||||
return new self(new PhotoAttachmentPayload(token: $token));
|
||||
return new self(new PhotoAttachmentRequestPayload(token: $token));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,13 +46,13 @@ final readonly class PhotoAttachmentRequest extends AbstractAttachmentRequest
|
||||
*/
|
||||
public static function fromPhotos(array $photos): self
|
||||
{
|
||||
return new self(new PhotoAttachmentPayload(photos: $photos));
|
||||
return new self(new PhotoAttachmentRequestPayload(photos: $photos));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PhotoAttachmentPayload $payload Request to attach image.
|
||||
* @param PhotoAttachmentRequestPayload $payload Request to attach image.
|
||||
*/
|
||||
private function __construct(PhotoAttachmentPayload $payload)
|
||||
private function __construct(PhotoAttachmentRequestPayload $payload)
|
||||
{
|
||||
parent::__construct(AttachmentType::Image, $payload);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Requests;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\ShareAttachmentRequestPayload;
|
||||
|
||||
/**
|
||||
* Request to attach a media preview of an external URL.
|
||||
*/
|
||||
final readonly class ShareAttachmentRequest extends AbstractAttachmentRequest
|
||||
{
|
||||
/**
|
||||
* Creates a request to attach a URL preview.
|
||||
*
|
||||
* @param string $url The URL to generate a preview for.
|
||||
*
|
||||
* @return ShareAttachmentRequest
|
||||
*/
|
||||
public static function fromUrl(string $url): self
|
||||
{
|
||||
return new self(new ShareAttachmentRequestPayload(url: $url));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a request to re-send a URL preview using its token.
|
||||
*
|
||||
* @param string $token The token of a previously generated preview.
|
||||
*
|
||||
* @return ShareAttachmentRequest
|
||||
*/
|
||||
public static function fromToken(string $token): self
|
||||
{
|
||||
return new self(new ShareAttachmentRequestPayload(token: $token));
|
||||
}
|
||||
|
||||
private function __construct(ShareAttachmentRequestPayload $payload)
|
||||
{
|
||||
parent::__construct(AttachmentType::Share, $payload);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Requests;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\StickerAttachmentRequestPayload;
|
||||
|
||||
/**
|
||||
* Request to attach a sticker to a message.
|
||||
*/
|
||||
final readonly class StickerAttachmentRequest extends AbstractAttachmentRequest
|
||||
{
|
||||
/**
|
||||
* @param string $code The unique code of the sticker.
|
||||
*/
|
||||
public function __construct(string $code)
|
||||
{
|
||||
parent::__construct(
|
||||
AttachmentType::Sticker,
|
||||
new StickerAttachmentRequestPayload($code),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Requests;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\UploadedInfoAttachmentRequestPayload;
|
||||
|
||||
/**
|
||||
* Request to attach a video to a message.
|
||||
*/
|
||||
final readonly class VideoAttachmentRequest extends AbstractAttachmentRequest
|
||||
{
|
||||
/**
|
||||
* @param string $token The unique token received after a successful video upload.
|
||||
*/
|
||||
public function __construct(string $token)
|
||||
{
|
||||
parent::__construct(
|
||||
AttachmentType::Video,
|
||||
new UploadedInfoAttachmentRequestPayload($token),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user