From 8b8bca9307ffbd7510e878a9b63077a90501d6fc Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Sat, 14 Oct 2023 12:32:17 +0700 Subject: [PATCH] feat: create method to get command messages from telegram --- src/Interfaces/AppInterface.php | 14 ++++++++++++++ src/Services/AppService.php | 11 +++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/Interfaces/AppInterface.php b/src/Interfaces/AppInterface.php index d44538d..acb60bc 100644 --- a/src/Interfaces/AppInterface.php +++ b/src/Interfaces/AppInterface.php @@ -86,4 +86,18 @@ public function setCallbackContentMessage(array $options = []): array; * @return void */ public function setCurrentChatId(string $chatId): void; + + /** + * Get the username of the bot + * + * @return string|null + */ + public function getBotName(): ?string; + + /** + * Get the command message from a telegram + * + * @return string + */ + public function getCommandMessage(): string; } diff --git a/src/Services/AppService.php b/src/Services/AppService.php index 2478b1e..6a7f4a0 100644 --- a/src/Services/AppService.php +++ b/src/Services/AppService.php @@ -127,4 +127,15 @@ public function setCallbackContentMessage(array $options = []): array return $content; } + + public function getBotName(): ?string + { + return $this->telegram->getMe()['result']['username'] ?? null; + } + + public function getCommandMessage(): string + { + $text = $this->telegram->Text(); + return str_replace('@' . $this->getBotName(), '', $text); + } }