generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #660 from AndrzejkaNowicki/main
Support for handling webhook requests to join chats/channels
- Loading branch information
Showing
12 changed files
with
485 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DefStudio\Telegraph\DTO; | ||
|
||
use Carbon\Carbon; | ||
use Carbon\CarbonInterface; | ||
use Illuminate\Contracts\Support\Arrayable; | ||
|
||
/** | ||
* @implements Arrayable<string, string|int|bool|array<string, mixed>> | ||
*/ | ||
class ChatInviteLink implements Arrayable | ||
{ | ||
private string $inviteLink; | ||
private User $creator; | ||
private bool $createsJoinRequest; | ||
private bool $isPrimary; | ||
private bool $isRevoked; | ||
private ?string $name = null; | ||
private ?CarbonInterface $expireDate = null; | ||
private ?int $memberLimit = null; | ||
private ?int $pendingJoinRequestsCount = null; | ||
private ?int $subscriptionPeriod = null; | ||
private ?int $subscriptionPrice = null; | ||
|
||
private function __construct() | ||
{ | ||
} | ||
|
||
/** | ||
* @param array{ | ||
* creator: array<string, mixed>, | ||
* invite_link: string, | ||
* creates_join_request: bool, | ||
* is_primary: bool, | ||
* is_revoked: bool, | ||
* name?: string, | ||
* expire_date?: int, | ||
* member_limit?: int, | ||
* pending_join_requests_count?: int, | ||
* subscription_period?: int, | ||
* subscription_price?: int | ||
* } $data | ||
*/ | ||
public static function fromArray(array $data): ChatInviteLink | ||
{ | ||
$invite = new self(); | ||
|
||
$invite->inviteLink = $data['invite_link']; | ||
|
||
/* @phpstan-ignore-next-line */ | ||
$invite->creator = User::fromArray($data['creator']); | ||
|
||
$invite->createsJoinRequest = $data['creates_join_request']; | ||
|
||
$invite->isPrimary = $data['is_primary']; | ||
|
||
$invite->isRevoked = $data['is_revoked']; | ||
|
||
if (isset($data['name'])) { | ||
$invite->name = $data['name']; | ||
} | ||
|
||
if (isset($data['expire_date'])) { | ||
/* @phpstan-ignore-next-line */ | ||
$invite->expireDate = Carbon::createFromTimestamp($data['expire_date']); | ||
} | ||
|
||
if (isset($data['member_limit'])) { | ||
$invite->memberLimit = $data['member_limit']; | ||
} | ||
|
||
if (isset($data['pending_join_requests_count'])) { | ||
$invite->pendingJoinRequestsCount = $data['pending_join_requests_count']; | ||
} | ||
|
||
if (isset($data['subscription_period'])) { | ||
$invite->subscriptionPeriod = $data['subscription_period']; | ||
} | ||
|
||
if (isset($data['subscription_price'])) { | ||
$invite->subscriptionPrice = $data['subscription_price']; | ||
} | ||
|
||
return $invite; | ||
} | ||
|
||
public function inviteLink(): string | ||
{ | ||
return $this->inviteLink; | ||
} | ||
|
||
public function creator(): User | ||
{ | ||
return $this->creator; | ||
} | ||
|
||
public function createsJoinRequest(): bool | ||
{ | ||
return $this->createsJoinRequest; | ||
} | ||
|
||
public function isPrimary(): bool | ||
{ | ||
return $this->isPrimary; | ||
} | ||
|
||
public function isRevoked(): bool | ||
{ | ||
return $this->isRevoked; | ||
} | ||
|
||
public function name(): ?string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function expireDate(): ?CarbonInterface | ||
{ | ||
return $this->expireDate; | ||
} | ||
|
||
public function memberLimit(): ?int | ||
{ | ||
return $this->memberLimit; | ||
} | ||
|
||
public function pendingJoinRequestsCount(): ?int | ||
{ | ||
return $this->pendingJoinRequestsCount; | ||
} | ||
|
||
public function subscriptionPeriod(): ?int | ||
{ | ||
return $this->subscriptionPeriod; | ||
} | ||
|
||
public function subscriptionPrice(): ?int | ||
{ | ||
return $this->subscriptionPrice; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return array_filter([ | ||
'invite_link' => $this->inviteLink, | ||
'creator' => $this->creator->toArray(), | ||
'creates_join_request' => $this->createsJoinRequest, | ||
'is_primary' => $this->isPrimary, | ||
'is_revoked' => $this->isRevoked, | ||
'name' => $this->name, | ||
'expire_date' => $this->expireDate?->timestamp, | ||
'member_limit' => $this->memberLimit, | ||
'pending_join_requests_count' => $this->pendingJoinRequestsCount, | ||
'subscription_period' => $this->subscriptionPeriod, | ||
'subscription_price' => $this->subscriptionPrice, | ||
], fn ($value) => $value !== null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
|
||
namespace DefStudio\Telegraph\DTO; | ||
|
||
use Carbon\Carbon; | ||
use Carbon\CarbonInterface; | ||
use Illuminate\Contracts\Support\Arrayable; | ||
|
||
/** | ||
* @implements Arrayable<string, string|int|bool|array<string, mixed>> | ||
*/ | ||
class ChatJoinRequest implements Arrayable | ||
{ | ||
private int $userChatId; | ||
private CarbonInterface $date; | ||
private ?string $bio = null; | ||
private ?ChatInviteLink $inviteLink = null; | ||
private Chat $chat; | ||
private User $from; | ||
|
||
private function __construct() | ||
{ | ||
} | ||
|
||
/** | ||
* @param array{ | ||
* user_chat_id: int, | ||
* date: int, | ||
* bio?: string, | ||
* invite_link?: array<string, mixed>, | ||
* chat: array<string, mixed>, | ||
* from: array<string, mixed>, | ||
* } $data | ||
*/ | ||
public static function fromArray(array $data): ChatJoinRequest | ||
{ | ||
$request = new self(); | ||
|
||
$request->userChatId = $data['user_chat_id']; | ||
|
||
/* @phpstan-ignore-next-line */ | ||
$request->date = Carbon::createFromTimestamp($data['date']); | ||
|
||
if (isset($data['bio'])) { | ||
$request->bio = $data['bio']; | ||
} | ||
|
||
if (isset($data['invite_link'])) { | ||
/* @phpstan-ignore-next-line */ | ||
$request->inviteLink = ChatInviteLink::fromArray($data['invite_link']); | ||
} | ||
|
||
/* @phpstan-ignore-next-line */ | ||
$request->chat = Chat::fromArray($data['chat']); | ||
|
||
/* @phpstan-ignore-next-line */ | ||
$request->from = User::fromArray($data['from']); | ||
|
||
return $request; | ||
} | ||
|
||
public function userChatId(): int | ||
{ | ||
return $this->userChatId; | ||
} | ||
|
||
public function date(): CarbonInterface | ||
{ | ||
return $this->date; | ||
} | ||
|
||
public function bio(): ?string | ||
{ | ||
return $this->bio; | ||
} | ||
|
||
public function inviteLink(): ?ChatInviteLink | ||
{ | ||
return $this->inviteLink; | ||
} | ||
|
||
public function chat(): Chat | ||
{ | ||
return $this->chat; | ||
} | ||
|
||
public function from(): User | ||
{ | ||
return $this->from; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return array_filter([ | ||
'user_chat_id' => $this->userChatId, | ||
'date' => $this->date->timestamp, | ||
'bio' => $this->bio, | ||
'invite_link' => $this->inviteLink?->toArray(), | ||
'chat' => $this->chat->toArray(), | ||
'from' => $this->from->toArray(), | ||
], fn ($value) => $value !== null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.