1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace CSlant\LaravelTelegramGitNotifier\Traits; |
6
|
|
|
|
7
|
|
|
use Illuminate\Support\Facades\Config; |
8
|
|
|
use Telegram as TelegramSDK; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Trait Markup |
12
|
|
|
* |
13
|
|
|
* Provides common markup generation methods for Telegram bot interfaces. |
14
|
|
|
*/ |
15
|
|
|
trait Markup |
16
|
|
|
{ |
17
|
|
|
private const CONFIG_AUTHOR_DISCUSSION = 'telegram-git-notifier.author.discussion'; |
18
|
|
|
private const CONFIG_AUTHOR_SOURCE_CODE = 'telegram-git-notifier.author.source_code'; |
19
|
|
|
private const TRANSLATION_PREFIX = 'tg-notifier::tools/menu.'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Generate menu markup with discussion and source code buttons. |
23
|
|
|
* |
24
|
|
|
* @param TelegramSDK $telegram The Telegram SDK instance |
25
|
|
|
* @return array<array<array<string, string>>> The generated inline keyboard markup |
26
|
|
|
*/ |
27
|
|
|
public function menuMarkup(TelegramSDK $telegram): array |
28
|
|
|
{ |
29
|
|
|
return [ |
30
|
|
|
$this->createButtonRow( |
31
|
|
|
$telegram, |
32
|
|
|
'🗨 ' . $this->trans('discussion'), |
33
|
|
|
Config::get(self::CONFIG_AUTHOR_DISCUSSION, '#') |
|
|
|
|
34
|
|
|
), |
35
|
|
|
$this->createButtonRow( |
36
|
|
|
$telegram, |
37
|
|
|
'💠 ' . $this->trans('source_code'), |
38
|
|
|
Config::get(self::CONFIG_AUTHOR_SOURCE_CODE, '#') |
|
|
|
|
39
|
|
|
), |
40
|
|
|
]; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Create a single button row for the inline keyboard. |
45
|
|
|
* |
46
|
|
|
* @param TelegramSDK $telegram The Telegram SDK instance |
47
|
|
|
* @param string $text The button text |
48
|
|
|
* @param string $url The URL to open when the button is pressed |
49
|
|
|
* @return array<array<string, string>> The button row |
50
|
|
|
*/ |
51
|
|
|
private function createButtonRow(TelegramSDK $telegram, string $text, string $url): array |
52
|
|
|
{ |
53
|
|
|
return [$telegram->buildInlineKeyBoardButton($text, $url)]; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get a translated string from the language file. |
58
|
|
|
* |
59
|
|
|
* @param string $key The translation key |
60
|
|
|
* @return string The translated string |
61
|
|
|
*/ |
62
|
|
|
private function trans(string $key): string |
63
|
|
|
{ |
64
|
|
|
return __(self::TRANSLATION_PREFIX . $key); |
|
|
|
|
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|