Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Commit 9bca72e

Browse files
committed
Common functionality for the "user_id + message_id or inline_message_id" dilemma
1 parent a709641 commit 9bca72e

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

src/Abstracts/TelegramMethods.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,27 @@ final public function export(): array
7777

7878
return $finalArray;
7979
}
80+
81+
/**
82+
* Will resolve the dependency of a mandatory inline_message_id OR a chat_id + message_id
83+
*
84+
* NOTE: This will use pass by reference instead of copy on write as the use-case for this functions allows this
85+
*
86+
* @param array $return
87+
* @return array
88+
*/
89+
final protected function mandatoryUserOrInlineMessageId(array &$return): array
90+
{
91+
if (empty($this->chat_id) && empty($this->message_id)) {
92+
$return[] = 'inline_message_id';
93+
}
94+
95+
// On the other hand, chat_id and message_id are mandatory if inline_message_id is not filled in
96+
if (empty($this->inline_message_id)) {
97+
$return[] = 'chat_id';
98+
$return[] = 'message_id';
99+
}
100+
101+
return $return;
102+
}
80103
}

src/Telegram/Methods/EditMessageCaption.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class EditMessageCaption extends TelegramMethods
5050

5151
public function getMandatoryFields(): array
5252
{
53-
return [];
53+
$returnValue = [];
54+
return $this->mandatoryUserOrInlineMessageId($returnValue);
5455
}
5556
}

src/Telegram/Methods/EditMessageReplyMarkup.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class EditMessageReplyMarkup extends TelegramMethods
4444

4545
public function getMandatoryFields(): array
4646
{
47-
return [];
47+
$returnValue = [];
48+
return $this->mandatoryUserOrInlineMessageId($returnValue);
4849
}
4950
}

src/Telegram/Methods/EditMessageText.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,7 @@ class EditMessageText extends TelegramMethods
6464
public function getMandatoryFields(): array
6565
{
6666
$returnValue[] = 'text';
67-
// Inline_message_id is mandatory if no chat_id and message_id are filled in
68-
if (empty($this->chat_id) && empty($this->message_id)) {
69-
$returnValue[] = 'inline_message_id';
70-
}
71-
72-
// On the other hand, chat_id and message_id are mandatory if inline_message_id is not filled in
73-
if (empty($this->inline_message_id)) {
74-
$returnValue[] = 'chat_id';
75-
$returnValue[] = 'message_id';
76-
}
77-
67+
$this->mandatoryUserOrInlineMessageId($returnValue);
7868
return $returnValue;
7969
}
8070
}

0 commit comments

Comments
 (0)