Skip to content

Commit

Permalink
Merge pull request #16 from tanhongit/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
tanhongit authored Oct 14, 2023
2 parents 22706e9 + 8b8bca9 commit 0f0d3fd
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
16 changes: 15 additions & 1 deletion src/Interfaces/AppInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
13 changes: 12 additions & 1 deletion src/Services/AppService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
5 changes: 4 additions & 1 deletion src/Services/SettingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
8 changes: 4 additions & 4 deletions src/Trait/BotSettingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
);
}
Expand All @@ -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',
'',
Expand All @@ -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',
'',
Expand All @@ -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',
Expand Down
7 changes: 1 addition & 6 deletions src/Trait/EventSettingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 0f0d3fd

Please sign in to comment.