From 72a06e269f41bc46185b3f66a60763a3941b5575 Mon Sep 17 00:00:00 2001 From: Abbas mkhzomi Date: Mon, 6 Nov 2023 16:52:52 +0330 Subject: [PATCH 1/9] Update TelegramMessage.php --- src/TelegramMessage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TelegramMessage.php b/src/TelegramMessage.php index b8b0e8c..5431674 100644 --- a/src/TelegramMessage.php +++ b/src/TelegramMessage.php @@ -20,7 +20,7 @@ public function __construct(string $content = '') { parent::__construct(); $this->content($content); - $this->payload['parse_mode'] = 'Markdown'; + $this->payload['parse_mode'] = 'MarkdownV2'; } public static function create(string $content = ''): self From 13cd03a4910e937b0e480015691fb2f201572bb2 Mon Sep 17 00:00:00 2001 From: Abbas mkhzomi Date: Mon, 6 Nov 2023 16:55:29 +0330 Subject: [PATCH 2/9] add normal function to remove parse mode --- src/Traits/HasSharedLogic.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Traits/HasSharedLogic.php b/src/Traits/HasSharedLogic.php index 1adef5c..65eaae9 100644 --- a/src/Traits/HasSharedLogic.php +++ b/src/Traits/HasSharedLogic.php @@ -50,6 +50,18 @@ public function keyboardMarkup(array $markup): self return $this; } + /** + * Recipient's Chat ID. + * + * @return static + */ + public function normal() + { + unset($this->payload['parse_mode']); + + return $this; + } + /** * Add a normal keyboard button. * From 5b192251f07869101d29f510ed641a45d2e7fb07 Mon Sep 17 00:00:00 2001 From: abbasudo Date: Mon, 6 Nov 2023 13:25:50 +0000 Subject: [PATCH 3/9] Fix styling --- src/Traits/HasSharedLogic.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Traits/HasSharedLogic.php b/src/Traits/HasSharedLogic.php index 65eaae9..e9ca2c2 100644 --- a/src/Traits/HasSharedLogic.php +++ b/src/Traits/HasSharedLogic.php @@ -61,7 +61,7 @@ public function normal() return $this; } - + /** * Add a normal keyboard button. * From 3370540f89437c35d921b030853eb956efaae859 Mon Sep 17 00:00:00 2001 From: Abbas mkhzomi Date: Mon, 6 Nov 2023 17:08:52 +0330 Subject: [PATCH 4/9] Update HasSharedLogic.php --- src/Traits/HasSharedLogic.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Traits/HasSharedLogic.php b/src/Traits/HasSharedLogic.php index e9ca2c2..953aeeb 100644 --- a/src/Traits/HasSharedLogic.php +++ b/src/Traits/HasSharedLogic.php @@ -51,7 +51,7 @@ public function keyboardMarkup(array $markup): self } /** - * Recipient's Chat ID. + * unsets parse mode of the message. * * @return static */ @@ -62,6 +62,19 @@ public function normal() return $this; } + + /** + * Sets parse mode of the message. + * + * @return static + */ + public function parseMode(string $mode = null) + { + $this->payload['parse_mode'] = $mode; + + return $this; + } + /** * Add a normal keyboard button. * From 4b0ffeaea53ab73021b5a0dbc783e71411bd35cf Mon Sep 17 00:00:00 2001 From: abbasudo Date: Mon, 6 Nov 2023 13:39:12 +0000 Subject: [PATCH 5/9] Fix styling --- src/Traits/HasSharedLogic.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Traits/HasSharedLogic.php b/src/Traits/HasSharedLogic.php index 953aeeb..28d7e88 100644 --- a/src/Traits/HasSharedLogic.php +++ b/src/Traits/HasSharedLogic.php @@ -62,7 +62,6 @@ public function normal() return $this; } - /** * Sets parse mode of the message. * @@ -74,7 +73,7 @@ public function parseMode(string $mode = null) return $this; } - + /** * Add a normal keyboard button. * From 292024451c11b2192af14994562e455099a74a92 Mon Sep 17 00:00:00 2001 From: Abbas mkhzomi Date: Wed, 13 Dec 2023 11:55:32 +0330 Subject: [PATCH 6/9] add mode validation --- src/Traits/HasSharedLogic.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Traits/HasSharedLogic.php b/src/Traits/HasSharedLogic.php index 28d7e88..8c69a1f 100644 --- a/src/Traits/HasSharedLogic.php +++ b/src/Traits/HasSharedLogic.php @@ -69,6 +69,10 @@ public function normal() */ public function parseMode(string $mode = null) { + if (isset($mode) and ! in_array($mode, $allowed = ['Markdown', 'HTML', 'MarkdownV2'])) { + throw new InvalidArgumentException("Invalid aggregate type [$mode], allowed types: [".implode(', ', $allowed).'].'); + } + $this->payload['parse_mode'] = $mode; return $this; From 8f463e10013d4b2f2f9af3ad500579d32f047d78 Mon Sep 17 00:00:00 2001 From: abbasudo Date: Wed, 13 Dec 2023 08:25:52 +0000 Subject: [PATCH 7/9] Fix styling --- src/Telegram.php | 2 +- src/TelegramFile.php | 4 ++-- src/TelegramMessage.php | 2 +- src/Traits/HasSharedLogic.php | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Telegram.php b/src/Telegram.php index 589998e..f496005 100644 --- a/src/Telegram.php +++ b/src/Telegram.php @@ -23,7 +23,7 @@ class Telegram /** @var string Telegram Bot API Base URI */ protected string $apiBaseUri; - public function __construct(string $token = null, HttpClient $httpClient = null, string $apiBaseUri = null) + public function __construct(?string $token = null, ?HttpClient $httpClient = null, ?string $apiBaseUri = null) { $this->token = $token; $this->http = $httpClient ?? new HttpClient(); diff --git a/src/TelegramFile.php b/src/TelegramFile.php index 47acca4..1745ab4 100644 --- a/src/TelegramFile.php +++ b/src/TelegramFile.php @@ -48,7 +48,7 @@ public function content(string $content): self * @param resource|StreamInterface|string $file * @return $this */ - public function file(mixed $file, string $type, string $filename = null): self + public function file(mixed $file, string $type, ?string $filename = null): self { $this->type = $type; @@ -102,7 +102,7 @@ public function audio(string $file): self * * @return $this */ - public function document(string $file, string $filename = null): self + public function document(string $file, ?string $filename = null): self { return $this->file($file, 'document', $filename); } diff --git a/src/TelegramMessage.php b/src/TelegramMessage.php index 5431674..10b3633 100644 --- a/src/TelegramMessage.php +++ b/src/TelegramMessage.php @@ -33,7 +33,7 @@ public static function create(string $content = ''): self * * @return $this */ - public function content(string $content, int $limit = null): self + public function content(string $content, ?int $limit = null): self { $this->payload['text'] = $content; diff --git a/src/Traits/HasSharedLogic.php b/src/Traits/HasSharedLogic.php index 8c69a1f..f9dd3e7 100644 --- a/src/Traits/HasSharedLogic.php +++ b/src/Traits/HasSharedLogic.php @@ -67,12 +67,12 @@ public function normal() * * @return static */ - public function parseMode(string $mode = null) + public function parseMode(?string $mode = null) { if (isset($mode) and ! in_array($mode, $allowed = ['Markdown', 'HTML', 'MarkdownV2'])) { throw new InvalidArgumentException("Invalid aggregate type [$mode], allowed types: [".implode(', ', $allowed).'].'); } - + $this->payload['parse_mode'] = $mode; return $this; From 6ec5af3a1e59031d9d58ea7427b73732c8714f92 Mon Sep 17 00:00:00 2001 From: Abbas mkhzomi Date: Wed, 13 Dec 2023 11:57:45 +0330 Subject: [PATCH 8/9] add mode validation --- src/Traits/HasSharedLogic.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Traits/HasSharedLogic.php b/src/Traits/HasSharedLogic.php index f9dd3e7..fba6ee9 100644 --- a/src/Traits/HasSharedLogic.php +++ b/src/Traits/HasSharedLogic.php @@ -3,6 +3,7 @@ namespace NotificationChannels\Telegram\Traits; use Illuminate\Support\Traits\Conditionable; +use InvalidArgumentException; /** * Trait HasSharedLogic. From cc742121096bec5782a644c9ea94b6610f84340b Mon Sep 17 00:00:00 2001 From: Abbas mkhzomi Date: Wed, 13 Dec 2023 12:01:22 +0330 Subject: [PATCH 9/9] change default parse mode --- src/TelegramMessage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TelegramMessage.php b/src/TelegramMessage.php index 10b3633..a6664bb 100644 --- a/src/TelegramMessage.php +++ b/src/TelegramMessage.php @@ -20,7 +20,7 @@ public function __construct(string $content = '') { parent::__construct(); $this->content($content); - $this->payload['parse_mode'] = 'MarkdownV2'; + $this->payload['parse_mode'] = 'Markdown'; } public static function create(string $content = ''): self