Skip to content

Commit d6e3078

Browse files
committed
(#30) Update logic to edit message from telegram
1 parent 5ced730 commit d6e3078

File tree

3 files changed

+53
-16
lines changed

3 files changed

+53
-16
lines changed

src/Services/AppService.php

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public function answerCallbackQuery(string $text = null): void
7272

7373
/**
7474
* Edit message from telegram
75+
* (Edit message text and reply markup)
7576
*
7677
* @param string|null $text
7778
* @param array $options
@@ -80,24 +81,60 @@ public function answerCallbackQuery(string $text = null): void
8081
public function editMessageText(?string $text = null, array $options = []): void
8182
{
8283
try {
83-
$content = array(
84-
'chat_id' => $this->telegram->Callback_ChatID(),
85-
'message_id' => $this->telegram->MessageID(),
86-
'disable_web_page_preview' => true,
87-
'parse_mode' => 'HTML',
88-
);
89-
90-
if (!empty($text)) {
91-
$content['text'] = $text;
92-
}
93-
94-
if (!empty($options) && isset($options['reply_markup'])) {
95-
$content['reply_markup'] = $this->telegram->buildInlineKeyBoard($options['reply_markup']);
96-
}
84+
$content = [
85+
'text' => $text ?? $this->Callback_Message_Text()
86+
];
87+
$content = array_merge($content, $this->setContentEditMessage($options));
9788

9889
$this->telegram->editMessageText($content);
9990
} catch (Exception $e) {
10091
error_log($e->getMessage());
10192
}
10293
}
94+
95+
/**
96+
* Edit message reply markup from a telegram
97+
* (Edit message reply markup only)
98+
*
99+
* @param array $options
100+
* @return void
101+
*/
102+
public function editMessageReplyMarkup(array $options = []): void
103+
{
104+
try {
105+
$this->telegram->editMessageReplyMarkup($this->setContentEditMessage($options));
106+
} catch (Exception $e) {
107+
error_log($e->getMessage());
108+
}
109+
}
110+
111+
/**
112+
* Get the text from callback message
113+
*
114+
* @return string
115+
*/
116+
public function Callback_Message_Text(): string
117+
{
118+
return $this->telegram->Callback_Message()['text'];
119+
}
120+
121+
/**
122+
* @param array $options
123+
* @return array
124+
*/
125+
public function setContentEditMessage(array $options = []): array
126+
{
127+
$content = array(
128+
'chat_id' => $this->telegram->Callback_ChatID(),
129+
'message_id' => $this->telegram->MessageID(),
130+
'disable_web_page_preview' => true,
131+
'parse_mode' => 'HTML',
132+
);
133+
134+
if (!empty($options) && isset($options['reply_markup'])) {
135+
$content['reply_markup'] = $this->telegram->buildInlineKeyBoard($options['reply_markup']);
136+
}
137+
138+
return $content;
139+
}
103140
}

src/Services/EventService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function eventMarkup(?string $event = null): array
103103
*/
104104
public function eventHandle(): void
105105
{
106-
$this->sendMessage(
106+
$this->editMessageText(
107107
view('tools.event'),
108108
['reply_markup' => $this->eventMarkup()]
109109
);

src/Services/SettingService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function settingCallbackHandler(string $callback): void
8080
$callback = str_replace($this->setting::SETTING_PREFIX, '', $callback);
8181

8282
if ($this->updateSettingItem($callback, !$this->settingConfig[$callback])) {
83-
$this->editMessageText(null, [
83+
$this->editMessageReplyMarkup([
8484
'reply_markup' => $this->settingMarkup(),
8585
]);
8686
} else {

0 commit comments

Comments
 (0)