Skip to content

Commit

Permalink
[fix] missing parse mode in DTOs
Browse files Browse the repository at this point in the history
  • Loading branch information
fabio-ivona committed Feb 1, 2024
1 parent 9622ee7 commit 4113053
Show file tree
Hide file tree
Showing 26 changed files with 325 additions and 74 deletions.
6 changes: 3 additions & 3 deletions src/Concerns/ComposesMessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function html(string $message = null): Telegraph
$telegraph->setMessageText($message);
}

$telegraph->data['parse_mode'] = 'html';
$telegraph->data['parse_mode'] = Telegraph::PARSE_HTML;

return $telegraph;
}
Expand All @@ -49,7 +49,7 @@ public function markdown(string $message = null): Telegraph
$telegraph->setMessageText($message);
}

$telegraph->data['parse_mode'] = 'markdown';
$telegraph->data['parse_mode'] = Telegraph::PARSE_MARKDOWN;

return $telegraph;
}
Expand All @@ -62,7 +62,7 @@ public function markdownV2(string $message = null): Telegraph
$telegraph->setMessageText($message);
}

$telegraph->data['parse_mode'] = 'MarkdownV2';
$telegraph->data['parse_mode'] = Telegraph::PARSE_MARKDOWNV2;

return $telegraph;
}
Expand Down
40 changes: 32 additions & 8 deletions src/DTO/InlineQueryResultArticle.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace DefStudio\Telegraph\DTO;

use DefStudio\Telegraph\Telegraph;

class InlineQueryResultArticle extends InlineQueryResult
{
protected string $type = 'article';
Expand All @@ -16,6 +18,7 @@ class InlineQueryResultArticle extends InlineQueryResult
protected int|null $thumbWidth = null;
protected int|null $thumbHeight = null;
protected bool|null $hideUrl = null;
protected string|null $parseMode = null;

public static function make(string $id, string $title, string $message = null): InlineQueryResultArticle
{
Expand All @@ -27,48 +30,69 @@ public static function make(string $id, string $title, string $message = null):
return $result;
}

public function url(string|null $url): InlineQueryResultArticle
public function url(string|null $url): static
{
$this->url = $url;

return $this;
}

public function description(string|null $description): InlineQueryResultArticle
public function description(string|null $description): static
{
$this->description = $description;

return $this;
}

public function thumbUrl(string|null $thumbUrl): InlineQueryResultArticle
public function thumbUrl(string|null $thumbUrl): static
{
$this->thumbUrl = $thumbUrl;

return $this;
}

public function thumbWidth(int|null $thumbWidth): InlineQueryResultArticle
public function thumbWidth(int|null $thumbWidth): static
{
$this->thumbWidth = $thumbWidth;

return $this;
}

public function thumbHeight(int|null $thumbHeight): InlineQueryResultArticle
public function thumbHeight(int|null $thumbHeight): static
{
$this->thumbHeight = $thumbHeight;

return $this;
}

public function hideUrl(bool|null $hideUrl): InlineQueryResultArticle
public function hideUrl(bool|null $hideUrl): static
{
$this->hideUrl = $hideUrl;

return $this;
}

public function html(): static
{
$this->parseMode = Telegraph::PARSE_HTML;

return $this;
}

public function markdown(): static
{
$this->parseMode = Telegraph::PARSE_MARKDOWN;

return $this;
}

public function markdownV2(): static
{
$this->parseMode = Telegraph::PARSE_MARKDOWNV2;

return $this;
}

/**
* @inheritDoc
*/
Expand All @@ -84,10 +108,10 @@ public function data(): array
'thumb_height' => $this->thumbHeight,
];

if($this->message !== null){
if($this->message !== null) {
$data['input_message_content'] = [
'message_text' => $this->message,
'parse_mode' => config('telegraph.default_parse_mode', 'html'),
'parse_mode' => $this->parseMode ?? config('telegraph.default_parse_mode', Telegraph::PARSE_HTML),
];
}

Expand Down
32 changes: 28 additions & 4 deletions src/DTO/InlineQueryResultAudio.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace DefStudio\Telegraph\DTO;

use DefStudio\Telegraph\Telegraph;

class InlineQueryResultAudio extends InlineQueryResult
{
protected string $type = 'audio';
Expand All @@ -13,6 +15,7 @@ class InlineQueryResultAudio extends InlineQueryResult
protected string|null $caption = null;
protected string|null $performer = null;
protected int|null $duration = null;
protected string|null $parseMode = null;

public static function make(string $id, string $url, string $title): InlineQueryResultAudio
{
Expand All @@ -24,27 +27,48 @@ public static function make(string $id, string $url, string $title): InlineQuery
return $result;
}

public function caption(string|null $caption): InlineQueryResultAudio
public function caption(string|null $caption): static
{
$this->caption = $caption;

return $this;
}

public function performer(string|null $performer): InlineQueryResultAudio
public function performer(string|null $performer): static
{
$this->performer = $performer;

return $this;
}

public function duration(int|null $duration): InlineQueryResultAudio
public function duration(int|null $duration): static
{
$this->duration = $duration;

return $this;
}

public function html(): static
{
$this->parseMode = Telegraph::PARSE_HTML;

return $this;
}

public function markdown(): static
{
$this->parseMode = Telegraph::PARSE_MARKDOWN;

return $this;
}

public function markdownV2(): static
{
$this->parseMode = Telegraph::PARSE_MARKDOWNV2;

return $this;
}

/**
* @inheritDoc
*/
Expand All @@ -54,7 +78,7 @@ public function data(): array
'audio_url' => $this->url,
'title' => $this->title,
'caption' => $this->caption,
'parse_mode' => config('telegraph.default_parse_mode', 'html'),
'parse_mode' => $this->parseMode ?? config('telegraph.default_parse_mode', Telegraph::PARSE_HTML),
'performer' => $this->performer,
'audio_duration' => $this->duration,
];
Expand Down
38 changes: 31 additions & 7 deletions src/DTO/InlineQueryResultContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace DefStudio\Telegraph\DTO;

use DefStudio\Telegraph\Telegraph;

class InlineQueryResultContact extends InlineQueryResult
{
protected string $type = 'contact';
Expand All @@ -16,6 +18,7 @@ class InlineQueryResultContact extends InlineQueryResult
protected string|null $lastName = null;
protected string|null $vcard = null;
protected string|null $thumbUrl = null;
protected string|null $parseMode = null;

public static function make(string $id, string $phoneNumber, string $firstName, string $message = null): InlineQueryResultContact
{
Expand All @@ -28,41 +31,62 @@ public static function make(string $id, string $phoneNumber, string $firstName,
return $result;
}

public function thumbWidth(int|null $thumbWidth): InlineQueryResultContact
public function thumbWidth(int|null $thumbWidth): static
{
$this->thumbWidth = $thumbWidth;

return $this;
}

public function thumbHeight(int|null $thumbHeight): InlineQueryResultContact
public function thumbHeight(int|null $thumbHeight): static
{
$this->thumbHeight = $thumbHeight;

return $this;
}

public function lastName(string|null $lastName): InlineQueryResultContact
public function lastName(string|null $lastName): static
{
$this->lastName = $lastName;

return $this;
}

public function vcard(string|null $vcard): InlineQueryResultContact
public function vcard(string|null $vcard): static
{
$this->vcard = $vcard;

return $this;
}

public function thumbUrl(string|null $thumbUrl): InlineQueryResultContact
public function thumbUrl(string|null $thumbUrl): static
{
$this->thumbUrl = $thumbUrl;

return $this;
}

public function html(): static
{
$this->parseMode = Telegraph::PARSE_HTML;

return $this;
}

public function markdown(): static
{
$this->parseMode = Telegraph::PARSE_MARKDOWN;

return $this;
}

public function markdownV2(): static
{
$this->parseMode = Telegraph::PARSE_MARKDOWNV2;

return $this;
}

/**
* @inheritDoc
*/
Expand All @@ -78,10 +102,10 @@ public function data(): array
'thumb_height' => $this->thumbHeight,
];

if($this->message !== null){
if($this->message !== null) {
$data['input_message_content'] = [
'message_text' => $this->message,
'parse_mode' => config('telegraph.default_parse_mode', 'html'),
'parse_mode' => $this->parseMode ?? config('telegraph.default_parse_mode', Telegraph::PARSE_HTML),
];
}

Expand Down
Loading

0 comments on commit 4113053

Please sign in to comment.