-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from tanhongit/main
Deploy
- Loading branch information
Showing
13 changed files
with
181 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"is_notified": true, | ||
"enable_all_event": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace TelegramGithubNotify\App\Helpers; | ||
|
||
class SettingHelper | ||
{ | ||
public const SETTING_FILE = __DIR__ . '/../../storage/tg-setting.json'; | ||
|
||
public array $settings = []; | ||
|
||
public function __construct() | ||
{ | ||
if (file_exists(self::SETTING_FILE)) { | ||
$this->setSettingConfig(); | ||
} | ||
} | ||
|
||
/** | ||
* Set settings | ||
* | ||
* @return void | ||
*/ | ||
public function setSettingConfig(): void | ||
{ | ||
$json = file_get_contents(self::SETTING_FILE); | ||
$this->settings = json_decode($json, true); | ||
} | ||
|
||
/** | ||
* Get settings | ||
* | ||
* @return array | ||
*/ | ||
public function getSettingConfig(): array | ||
{ | ||
return $this->settings; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function enableAllEvents(): bool | ||
{ | ||
if (!empty($this->settings) && $this->settings['enable_all_event'] === true) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace TelegramGithubNotify\App\Services; | ||
|
||
use Telegram; | ||
|
||
class AppService | ||
{ | ||
public Telegram $telegram; | ||
|
||
public function __construct() | ||
{ | ||
$this->telegram = new Telegram(config('telegram-bot.token')); | ||
} | ||
|
||
/** | ||
* Send a message to telegram | ||
* | ||
* @param string $message | ||
* @param array $options | ||
* @param string $sendType | ||
* @return void | ||
*/ | ||
public function sendMessage(string $message = '', array $options = [], string $sendType = 'Message'): void | ||
{ | ||
$content = array( | ||
'chat_id' => config('telegram-bot.chat_id'), | ||
'disable_web_page_preview' => true, | ||
'parse_mode' => 'HTML' | ||
); | ||
|
||
if ($sendType === 'Message') { | ||
$content['text'] = $message; | ||
} elseif ($sendType === 'Photo' && !empty($options)) { | ||
$content['photo'] = $options['photo']; | ||
$content['caption'] = $message; | ||
} | ||
|
||
if (!empty($options) && isset($options['reply_markup'])) { | ||
$content['reply_markup'] = $this->telegram->buildInlineKeyBoard($options['reply_markup']); | ||
} | ||
|
||
$this->telegram->{'send' . $sendType}($content); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace TelegramGithubNotify\App\Services; | ||
|
||
use Telegram; | ||
|
||
class SettingService extends AppService | ||
{ | ||
public function settingMarkup(Telegram $telegram): void | ||
{ | ||
$keyboard = [ | ||
[ | ||
$telegram->buildInlineKeyBoardButton('🔔 Notification', '', '/notification'), | ||
] | ||
]; | ||
|
||
if (enable_all_events()) { | ||
$eventSetting = $telegram->buildInlineKeyBoardButton('🔕 Disable All Events', '', '/disable_all_events'); | ||
} else { | ||
$eventSetting = $telegram->buildInlineKeyBoardButton('🔔 Enable All Events', '', '/enable_all_events'); | ||
} | ||
|
||
$keyboard[0][] = [ | ||
$eventSetting, | ||
$telegram->buildInlineKeyBoardButton('Check Events', '', '/check_events'), | ||
]; | ||
|
||
$this->sendMessage(view('tools.settings'), ['reply_markup' => $keyboard]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.