Skip to content

Commit f368bc3

Browse files
committed
Update TInlineKeyboard.php
1 parent a6003ed commit f368bc3

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/telegram/object/markup/TInlineKeyboard.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
namespace telegram\object\markup;
33

4+
use telegram\exception\TelegramException;
5+
46
/**
57
* --EN--
68
* This object represents an inline keyboard that appears right next to the message it belongs to.
@@ -11,18 +13,37 @@
1113
* @see https://core.telegram.org/bots/api#inlinekeyboardmarkup
1214
*/
1315
class TInlineKeyboard extends TReplyKeyboard {
16+
/**
17+
* Callback data limit
18+
*/
19+
const MAX_CBDATA_LENGTH = 64;
20+
1421
/**
1522
* Добавить кнопку
1623
* @param string $text Текст кнопки
1724
* @param string $data Данные, которые будут возвращены при нажатии или ссылка для перехода
1825
* @return TInlineKeyboard
1926
*/
20-
public function button(string $text, string $data){
27+
public function button(string $text){
2128
$btn = ['text' => $text];
2229

23-
if(strpos($data, 'http:') === 0 || strpos($data, 'https:') === 0){
30+
if(func_num_args() < 2){
31+
throw new TelegramException('Parameter callback_data required for InlineKeyboard buttons');
32+
} else {
33+
$data = func_get_arg(1);
34+
}
35+
36+
if(!is_string($data)){
37+
throw new TelegramException('Parameter callback_data should be a string');
38+
}
39+
40+
if(strpos($data, 'http:') === 0 || strpos($data, 'https:') === 0 || strpos($data, 'tg:') === 0){
2441
$btn['url'] = $data;
2542
} else {
43+
if(strlen($data) > self::MAX_CBDATA_LENGTH){
44+
throw new TelegramException('Parameter callback_data should be a string no more than ' . MAX_CBDATA_LENGTH . ' bytes in size');
45+
}
46+
2647
$btn['callback_data'] = $data;
2748
}
2849

0 commit comments

Comments
 (0)