Skip to content

Commit 544af08

Browse files
committed
Add support for button styling and custom emoji in keyboard buttons
1 parent 9f332da commit 544af08

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/TL/Conversion/BotAPI.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@ private function parseButtons(array $rows, bool $inline): array
5050
$newrows[$key] = ['_' => 'keyboardButtonRow', 'buttons' => []];
5151
foreach ($row as $button) {
5252
$newrows[$key]['buttons'][$button_key] = ['_' => 'keyboardButton', 'text' => $button['text']];
53+
if (isset($button['style']) || isset($button['icon_custom_emoji_id'])) {
54+
$newrows[$key]['buttons'][$button_key]['style']['_'] = 'keyboardButtonStyle';
55+
$bgKey = match ($button['style'] ?? null) {
56+
'primary' => 'bg_primary',
57+
'danger' => 'bg_danger',
58+
'success' => 'bg_success',
59+
default => null,
60+
};
61+
if ($bgKey !== null) {
62+
$newrows[$key]['buttons'][$button_key]['style'][$bgKey] = true;
63+
}
64+
if (isset($button['icon_custom_emoji_id'])) {
65+
$newrows[$key]['buttons'][$button_key]['style']['icon'] = $button['icon_custom_emoji_id'];
66+
}
67+
}
5368
if (isset($button['url'])) {
5469
if (str_starts_with($button['url'], 'tg://user?id=')) {
5570
$newrows[$key]['buttons'][$button_key]['_'] = 'inputKeyboardButtonUserProfile';
@@ -100,7 +115,9 @@ private function parseButtons(array $rows, bool $inline): array
100115
if ($button['allow_channel_chats'] ?? false) {
101116
$peer_types []= ['_' => 'inlineQueryPeerTypeBroadcast'];
102117
}
103-
$newrows[$key]['buttons'][$button_key]['peer_types'] = $peer_types;
118+
if (!empty($peer_types)) {
119+
$newrows[$key]['buttons'][$button_key]['peer_types'] = $peer_types;
120+
}
104121
} elseif (isset($button['switch_inline_query_current_chat'])) {
105122
$newrows[$key]['buttons'][$button_key]['_'] = 'keyboardButtonSwitchInline';
106123
$newrows[$key]['buttons'][$button_key]['same_peer'] = true;

0 commit comments

Comments
 (0)