diff --git a/src/Interfaces/AppInterface.php b/src/Interfaces/AppInterface.php index 150d41a..acb60bc 100644 --- a/src/Interfaces/AppInterface.php +++ b/src/Interfaces/AppInterface.php @@ -24,7 +24,7 @@ public function sendMessage( /** * Send a photo to telegram * - * @param string $photo + * @param string $photo (path to photo) * @param string $caption * * @return void @@ -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 8de81eb..6a7f4a0 100644 --- a/src/Services/AppService.php +++ b/src/Services/AppService.php @@ -58,7 +58,7 @@ public function sendPhoto(string $photo = '', string $caption = ''): void } $content = $this->createBaseContent(); - $content['photo'] = $photo; + $content['photo'] = curl_file_create($photo); $content['caption'] = $caption; $this->telegram->sendPhoto($content); @@ -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); + } } diff --git a/src/Services/SettingService.php b/src/Services/SettingService.php index b48955d..4a1684d 100644 --- a/src/Services/SettingService.php +++ b/src/Services/SettingService.php @@ -23,11 +23,14 @@ class SettingService extends AppService implements SettingInterface public function __construct( Telegram $telegram, Setting $setting, - Event $event + Event $event, + ?string $chatId = null ) { parent::__construct($telegram); $this->setting = $setting; $this->event = $event; + + $this->setCurrentChatId($chatId); } } diff --git a/src/Trait/BotSettingTrait.php b/src/Trait/BotSettingTrait.php index e41dc0c..3d2593f 100644 --- a/src/Trait/BotSettingTrait.php +++ b/src/Trait/BotSettingTrait.php @@ -9,7 +9,7 @@ trait BotSettingTrait public function settingHandle(?string $view = null): void { $this->sendMessage( - view($view ?? config('telegram-git-notifier.view.tools.setting')), + view($view ?? config('telegram-git-notifier.view.tools.settings')), ['reply_markup' => $this->settingMarkup()] ); } @@ -19,7 +19,7 @@ public function settingMarkup(): array $markup = [ [ $this->telegram->buildInlineKeyBoardButton( - $this->setting[SettingConstant::T_IS_NOTIFIED] + $this->setting->getSettings()[SettingConstant::T_IS_NOTIFIED] ? '✅ Allow notifications' : 'Allow notifications', '', @@ -28,7 +28,7 @@ public function settingMarkup(): array ], [ $this->telegram->buildInlineKeyBoardButton( - $this->setting[SettingConstant::T_ALL_EVENTS_NOTIFICATION] + $this->setting->getSettings()[SettingConstant::T_ALL_EVENTS_NOTIFICATION] ? '✅ Enable All Events Notify' : 'Enable All Events Notify', '', @@ -52,7 +52,7 @@ public function settingMarkup(): array public function customEventMarkup(array $markup): array { - if (!$this->setting[SettingConstant::T_ALL_EVENTS_NOTIFICATION]) { + if (!$this->setting->getSettings()[SettingConstant::T_ALL_EVENTS_NOTIFICATION]) { $markup[] = [ $this->telegram->buildInlineKeyBoardButton( '🦑 Custom github events', diff --git a/src/Trait/EventSettingTrait.php b/src/Trait/EventSettingTrait.php index 7815eb7..369766d 100644 --- a/src/Trait/EventSettingTrait.php +++ b/src/Trait/EventSettingTrait.php @@ -23,12 +23,7 @@ public function eventMarkup( $replyMarkupItem = []; } - $callbackData = $this->getCallbackData( - $key, - $platform, - $value, - $parentEvent - ); + $callbackData = $this->getCallbackData($key, $platform, $value, $parentEvent); $eventName = $this->getEventName($key, $value); $replyMarkupItem[] = $this->telegram->buildInlineKeyBoardButton(