Skip to content

Commit ad19356

Browse files
authored
Merge pull request #1 from TsSaltan/master
ReplyMarkup features + answerCallbackQuery method
2 parents 6e35caa + 8728aab commit ad19356

33 files changed

+1224
-19
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@
1515
/gradlew.bat
1616
/package-lock.php.yml
1717
/out/**
18-
/dn-sources/**
18+
/dn-sources/**
19+
.phpintel/**

README.MD

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,73 @@ $listener->addListener(function($update){
4141
});
4242
$listener->start();
4343
```
44+
### Использование клавиатуры
45+
#### Клавиатура под полем ввода (ReplyKeyboard)
46+
![ReplyKeyboard](https://sun9-45.userapi.com/c205624/v205624150/12151/u119tArN_LE.jpg)
47+
```php
48+
$api = new TelegramBotApi($bot_token);
49+
50+
$keyboard = TMarkup::replyKeyboard()
51+
->button('Button 1')->button('Button 2')
52+
->row()
53+
->button('Row 2')->button('Hello world')->button('test 123')
54+
->row()
55+
->button('Button in row 3');
56+
57+
$api->sendMessage()
58+
->chat_id(123456)
59+
->text('Hello world')
60+
->reply_markup($keyboard)
61+
->query();
62+
```
63+
64+
#### Удаление клавиатуры под полем ввода (ReplyKeyboard)
65+
```php
66+
$api = new TelegramBotApi($bot_token);
67+
68+
$hideKeyboard = TMarkup::removeKeyboard();
69+
70+
$api->sendMessage()
71+
->chat_id(123456)
72+
->text('Hello world')
73+
->reply_markup($hideKeyboard)
74+
->query();
75+
```
76+
77+
#### Клавиатура под сообщением (InlineKeyboard)
78+
![InlineKeyboard](https://sun9-59.userapi.com/c205624/v205624829/11e6f/itNoz8qnyFE.jpg)
79+
```php
80+
$api = new TelegramBotApi($bot_token);
81+
82+
// Обязательно вторым аргументом у button указывать данные для callback_data или url-ссылку
83+
$keyboard = TMarkup::inlineKeyboard()
84+
->button('Button with callback', 'press_1')->button('Button 2', 'press_2')
85+
->row()
86+
->button('Link to google', 'https://google.com')->button('Link to git', 'http://github.com')
87+
->row()
88+
->button('1', 'btn_1')->button('2', 'btn_2')->button('3', 'btn_3')->button('4', 'btn_4')->button('5', 'btn_5')->button('6', 'btn_6')->button('7', 'btn_7')->button('8', 'btn_8');
89+
90+
$api->sendMessage()
91+
->chat_id(123456)
92+
->text('Hello world')
93+
->reply_markup($keyboard)
94+
->query();
95+
```
96+
97+
#### Ответ на сообщение (ForceReply)
98+
![ForceReply](https://sun9-23.userapi.com/c205624/v205624829/11e98/pyW0VWHtPJ0.jpg)
99+
```php
100+
$api = new TelegramBotApi($bot_token);
101+
102+
$reply = TMarkup::forceReply();
103+
104+
$api->sendMessage()
105+
->chat_id(123456)
106+
->text('Hello world')
107+
->reply_markup($reply)
108+
->query();
109+
```
110+
44111
## Расширение для DevelNext
45112
[Скачать](https://github.com/broelik/jphp-telegram-bot-api/releases/latest)
46113

api-docs/README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
## telegram-bot-api
2-
> version 1.0.0, created by JPPM.
2+
> version 1.1.0, created by JPPM.
33
44

55
### Install
66
```
7-
jppm add telegram-bot-api@1.0.0
7+
jppm add telegram-bot-api@1.1.0
88
```
99

1010
### API
@@ -15,6 +15,14 @@ jppm add telegram-bot-api@1.0.0
1515
- [`TelegramError`](classes/telegram/exception/TelegramError.md)
1616
- [`TelegramException`](classes/telegram/exception/TelegramException.md)
1717

18+
#### `telegram\object\markup`
19+
20+
- [`AbstractMarkup`](classes/telegram/object/markup/AbstractMarkup.md)
21+
- [`TForceReply`](classes/telegram/object/markup/TForceReply.md)- _Shows reply interface to the user, as if they manually selected the bot‘s message and tapped 'Reply'_
22+
- [`TInlineKeyboard`](classes/telegram/object/markup/TInlineKeyboard.md)- _This object represents an inline keyboard that appears right next to the message it belongs to._
23+
- [`TReplyKeyboard`](classes/telegram/object/markup/TReplyKeyboard.md)- _This object represents a custom keyboard with reply options_
24+
- [`TReplyKeyboardRemove`](classes/telegram/object/markup/TReplyKeyboardRemove.md)- _Upon receiving a message with this object, Telegram clients will remove the current custom keyboard and display the default letter-keyboard. By default, custom keyboards are displayed until a new keyboard is sent by a bot. An exception is made for one-time keyboards that are hidden immediately after the user presses a button_
25+
1826
#### `telegram\object`
1927

2028
- [`TAudio`](classes/telegram/object/TAudio.md)
@@ -23,6 +31,7 @@ jppm add telegram-bot-api@1.0.0
2331
- [`TDocument`](classes/telegram/object/TDocument.md)
2432
- [`TFile`](classes/telegram/object/TFile.md)
2533
- [`TLocation`](classes/telegram/object/TLocation.md)
34+
- [`TMarkup`](classes/telegram/object/TMarkup.md)
2635
- [`TMessage`](classes/telegram/object/TMessage.md)
2736
- [`TMessageEntity`](classes/telegram/object/TMessageEntity.md)
2837
- [`TPhotoSize`](classes/telegram/object/TPhotoSize.md)
@@ -36,6 +45,7 @@ jppm add telegram-bot-api@1.0.0
3645

3746
#### `telegram\query`
3847

48+
- [`TAnswerCallbackQuery`](classes/telegram/query/TAnswerCallbackQuery.md)- _Use this method to send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. On success, True is returned._
3949
- [`TBaseQuery`](classes/telegram/query/TBaseQuery.md)
4050
- [`TEditMessageTextQuery`](classes/telegram/query/TEditMessageTextQuery.md)
4151
- [`TForwardMessageQuery`](classes/telegram/query/TForwardMessageQuery.md)

api-docs/classes/telegram/TelegramBotApi.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
- `->`[`kickChatMember()`](#method-kickchatmember)
3636
- `->`[`unbanChatMember()`](#method-unbanchatmember)
3737
- `->`[`getUpdates()`](#method-getupdates)
38+
- `->`[`answerCallbackQuery()`](#method-answercallbackquery)
3839
- `->`[`setProxy()`](#method-setproxy)
3940
- `->`[`getProxy()`](#method-getproxy)
4041
- `->`[`setToken()`](#method-settoken)
@@ -217,6 +218,15 @@ getUpdates(): TGetUpdatesQuery
217218

218219
---
219220

221+
<a name="method-answercallbackquery"></a>
222+
223+
### answerCallbackQuery()
224+
```php
225+
answerCallbackQuery(): TAnswerCallbackQuery
226+
```
227+
228+
---
229+
220230
<a name="method-setproxy"></a>
221231

222232
### setProxy()
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# TMarkup
2+
3+
- **class** `TMarkup` (`telegram\object\TMarkup`)
4+
- **source** `telegram/object/TMarkup.php`
5+
6+
---
7+
8+
#### Static Methods
9+
10+
- `TMarkup ::`[`replyKeyboard()`](#method-replykeyboard)
11+
- `TMarkup ::`[`inlineKeyboard()`](#method-inlinekeyboard)
12+
- `TMarkup ::`[`forceReply()`](#method-forcereply)
13+
- `TMarkup ::`[`removeKeyboard()`](#method-removekeyboard)
14+
15+
---
16+
# Static Methods
17+
18+
<a name="method-replykeyboard"></a>
19+
20+
### replyKeyboard()
21+
```php
22+
TMarkup::replyKeyboard(): TReplyKeyboard
23+
```
24+
25+
---
26+
27+
<a name="method-inlinekeyboard"></a>
28+
29+
### inlineKeyboard()
30+
```php
31+
TMarkup::inlineKeyboard(): TInlineKeyboard
32+
```
33+
34+
---
35+
36+
<a name="method-forcereply"></a>
37+
38+
### forceReply()
39+
```php
40+
TMarkup::forceReply(): TForceReply
41+
```
42+
43+
---
44+
45+
<a name="method-removekeyboard"></a>
46+
47+
### removeKeyboard()
48+
```php
49+
TMarkup::removeKeyboard(): TReplyKeyboardRemove
50+
```
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# AbstractMarkup
2+
3+
- **class** `AbstractMarkup` (`telegram\object\markup\AbstractMarkup`)
4+
- **source** `telegram/object/markup/AbstractMarkup.php`
5+
6+
**Child Classes**
7+
8+
> [TForceReply](classes/telegram/object/markup/TForceReply.md), [TReplyKeyboard](classes/telegram/object/markup/TReplyKeyboard.md), [TReplyKeyboardRemove](classes/telegram/object/markup/TReplyKeyboardRemove.md)
9+
10+
---
11+
12+
#### Properties
13+
14+
- `->`[`markup`](#prop-markup) : `array`
15+
16+
---
17+
18+
#### Methods
19+
20+
- `->`[`getMarkup()`](#method-getmarkup)
21+
22+
---
23+
# Methods
24+
25+
<a name="method-getmarkup"></a>
26+
27+
### getMarkup()
28+
```php
29+
getMarkup(): array
30+
```
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# TForceReply
2+
3+
- **class** `TForceReply` (`telegram\object\markup\TForceReply`) **extends** [`AbstractMarkup`](classes/telegram/object/markup/AbstractMarkup.md)
4+
- **source** `telegram/object/markup/TForceReply.php`
5+
6+
**Description**
7+
8+
Shows reply interface to the user, as if they manually selected the bot‘s message and tapped 'Reply'
9+
10+
---
11+
12+
#### Methods
13+
14+
- `->`[`__construct()`](#method-__construct)
15+
- `->`[`setSelective()`](#method-setselective) - _Use this parameter if you want to force reply from specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message._
16+
- See also in the parent class [AbstractMarkup](classes/telegram/object/markup/AbstractMarkup.md)
17+
18+
---
19+
# Methods
20+
21+
<a name="method-__construct"></a>
22+
23+
### __construct()
24+
```php
25+
__construct(): void
26+
```
27+
28+
---
29+
30+
<a name="method-setselective"></a>
31+
32+
### setSelective()
33+
```php
34+
setSelective(bool $value): void
35+
```
36+
Use this parameter if you want to force reply from specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# TInlineKeyboard
2+
3+
- **class** `TInlineKeyboard` (`telegram\object\markup\TInlineKeyboard`) **extends** [`TReplyKeyboard`](classes/telegram/object/markup/TReplyKeyboard.md)
4+
- **source** `telegram/object/markup/TInlineKeyboard.php`
5+
6+
**Description**
7+
8+
This object represents an inline keyboard that appears right next to the message it belongs to.
9+
10+
11+
---
12+
13+
#### Methods
14+
15+
- `->`[`button()`](#method-button) - _Добавить кнопку_
16+
- `->`[`getMarkup()`](#method-getmarkup)
17+
- See also in the parent class [TReplyKeyboard](classes/telegram/object/markup/TReplyKeyboard.md)
18+
19+
---
20+
# Methods
21+
22+
<a name="method-button"></a>
23+
24+
### button()
25+
```php
26+
button(string $text): TInlineKeyboard
27+
```
28+
Добавить кнопку
29+
30+
---
31+
32+
<a name="method-getmarkup"></a>
33+
34+
### getMarkup()
35+
```php
36+
getMarkup(): array
37+
```

0 commit comments

Comments
 (0)