Skip to content

Commit 15bf35b

Browse files
committed
Merge branch 'develop' of https://github.com/akalongman/php-telegram-bot into fixes
# Conflicts: # src/Entities/ServerResponse.php
2 parents 3d27fb5 + b1a8959 commit 15bf35b

File tree

104 files changed

+3640
-6252
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+3640
-6252
lines changed

examples/Commands/ForcereplyCommand.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
namespace Longman\TelegramBot\Commands\UserCommands;
1212

1313
use Longman\TelegramBot\Commands\UserCommand;
14+
use Longman\TelegramBot\Entities\Keyboard;
1415
use Longman\TelegramBot\Request;
15-
use Longman\TelegramBot\Entities\ForceReply;
1616

1717
/**
1818
* User "/forcereply" command
@@ -25,21 +25,20 @@ class ForceReplyCommand extends UserCommand
2525
protected $name = 'forcereply';
2626
protected $description = 'Force reply with reply markup';
2727
protected $usage = '/forcereply';
28-
protected $version = '0.0.6';
28+
protected $version = '0.1.0';
2929
/**#@-*/
3030

3131
/**
3232
* {@inheritdoc}
3333
*/
3434
public function execute()
3535
{
36-
$message = $this->getMessage();
37-
$chat_id = $message->getChat()->getId();
36+
$chat_id = $this->getMessage()->getChat()->getId();
3837

3938
$data = [
4039
'chat_id' => $chat_id,
4140
'text' => 'Write something:',
42-
'reply_markup' => new ForceReply(['selective' => false]),
41+
'reply_markup' => Keyboard::forceReply(),
4342
];
4443

4544
return Request::sendMessage($data);

examples/Commands/HidekeyboardCommand.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
namespace Longman\TelegramBot\Commands\UserCommands;
1212

1313
use Longman\TelegramBot\Commands\UserCommand;
14-
use Longman\TelegramBot\Entities\ReplyKeyboardHide;
15-
use Longman\TelegramBot\Entities\ReplyKeyboardMarkup;
14+
use Longman\TelegramBot\Entities\Keyboard;
1615
use Longman\TelegramBot\Request;
1716

1817
/**
@@ -26,21 +25,20 @@ class HidekeyboardCommand extends UserCommand
2625
protected $name = 'hidekeyboard';
2726
protected $description = 'Hide the custom keyboard';
2827
protected $usage = '/hidekeyboard';
29-
protected $version = '0.0.6';
28+
protected $version = '0.1.0';
3029
/**#@-*/
3130

3231
/**
3332
* {@inheritdoc}
3433
*/
3534
public function execute()
3635
{
37-
$message = $this->getMessage();
38-
$chat_id = $message->getChat()->getId();
36+
$chat_id = $this->getMessage()->getChat()->getId();
3937

4038
$data = [
4139
'chat_id' => $chat_id,
4240
'text' => 'Keyboard Hidden',
43-
'reply_markup' => new ReplyKeyboardHide(['selective' => false]),
41+
'reply_markup' => Keyboard::hide(),
4442
];
4543

4644
return Request::sendMessage($data);

examples/Commands/InlinekeyboardCommand.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
namespace Longman\TelegramBot\Commands\UserCommands;
1212

1313
use Longman\TelegramBot\Commands\UserCommand;
14+
use Longman\TelegramBot\Entities\InlineKeyboard;
1415
use Longman\TelegramBot\Request;
15-
use Longman\TelegramBot\Entities\InlineKeyboardMarkup;
16-
use Longman\TelegramBot\Entities\InlineKeyboardButton;
1716

1817
/**
1918
* User "/inlinekeyboard" command
@@ -23,28 +22,29 @@ class InlinekeyboardCommand extends UserCommand
2322
/**#@+
2423
* {@inheritdoc}
2524
*/
26-
protected $name = 'Inlinekeyboard';
25+
protected $name = 'inlinekeyboard';
2726
protected $description = 'Show inline keyboard';
2827
protected $usage = '/inlinekeyboard';
29-
protected $version = '0.0.2';
28+
protected $version = '0.1.0';
3029
/**#@-*/
3130

3231
/**
3332
* {@inheritdoc}
3433
*/
3534
public function execute()
3635
{
37-
$message = $this->getMessage();
36+
$chat_id = $this->getMessage()->getChat()->getId();
3837

39-
$inline_keyboard = [
40-
new InlineKeyboardButton(['text' => 'inline', 'switch_inline_query' => 'true']),
41-
new InlineKeyboardButton(['text' => 'callback', 'callback_data' => 'identifier']),
42-
new InlineKeyboardButton(['text' => 'open url', 'url' => 'https://github.com/akalongman/php-telegram-bot']),
43-
];
44-
$data = [
45-
'chat_id' => $message->getChat()->getId(),
38+
$inline_keyboard = new InlineKeyboard([
39+
['text' => 'inline', 'switch_inline_query' => 'true'],
40+
['text' => 'callback', 'callback_data' => 'identifier'],
41+
['text' => 'open url', 'url' => 'https://github.com/akalongman/php-telegram-bot'],
42+
]);
43+
44+
$data = [
45+
'chat_id' => $chat_id,
4646
'text' => 'inline keyboard',
47-
'reply_markup' => new InlineKeyboardMarkup(['inline_keyboard' => [$inline_keyboard]]),
47+
'reply_markup' => $inline_keyboard,
4848
];
4949

5050
return Request::sendMessage($data);

examples/Commands/KeyboardCommand.php

Lines changed: 36 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
namespace Longman\TelegramBot\Commands\UserCommands;
1212

1313
use Longman\TelegramBot\Commands\UserCommand;
14+
use Longman\TelegramBot\Entities\Keyboard;
1415
use Longman\TelegramBot\Request;
15-
use Longman\TelegramBot\Entities\ReplyKeyboardMarkup;
1616

1717
/**
1818
* User "/keyboard" command
@@ -25,79 +25,62 @@ class KeyboardCommand extends UserCommand
2525
protected $name = 'keyboard';
2626
protected $description = 'Show a custom keyboard with reply markup';
2727
protected $usage = '/keyboard';
28-
protected $version = '0.1.0';
28+
protected $version = '0.2.0';
2929
/**#@-*/
3030

3131
/**
3232
* {@inheritdoc}
3333
*/
3434
public function execute()
3535
{
36-
$message = $this->getMessage();
37-
$chat_id = $message->getChat()->getId();
38-
39-
$data = [
40-
'chat_id' => $chat_id,
41-
'text' => 'Press a Button:',
42-
];
43-
4436
//Keyboard examples
37+
/** @var Keyboard[] $keyboards */
4538
$keyboards = [];
4639

4740
//Example 0
48-
$keyboard = [];
49-
$keyboard[] = ['7', '8', '9'];
50-
$keyboard[] = ['4', '5', '6'];
51-
$keyboard[] = ['1', '2', '3'];
52-
$keyboard[] = [' ', '0', ' '];
53-
$keyboards[] = $keyboard;
41+
$keyboards[] = new Keyboard(
42+
['7', '8', '9'],
43+
['4', '5', '6'],
44+
['1', '2', '3'],
45+
[' ', '0', ' ']
46+
);
5447

5548
//Example 1
56-
$keyboard = [];
57-
$keyboard[] = ['7', '8', '9', '+'];
58-
$keyboard[] = ['4', '5', '6', '-'];
59-
$keyboard[] = ['1', '2', '3', '*'];
60-
$keyboard[] = [' ', '0', ' ', '/'];
61-
$keyboards[] = $keyboard;
49+
$keyboards[] = new Keyboard(
50+
['7', '8', '9', '+'],
51+
['4', '5', '6', '-'],
52+
['1', '2', '3', '*'],
53+
[' ', '0', ' ', '/']
54+
);
6255

6356
//Example 2
64-
$keyboard = [];
65-
$keyboard[] = ['A'];
66-
$keyboard[] = ['B'];
67-
$keyboard[] = ['C'];
68-
$keyboards[] = $keyboard;
57+
$keyboards[] = new Keyboard('A', 'B', 'C');
6958

7059
//Example 3
71-
$keyboard = [];
72-
$keyboard[] = ['A'];
73-
$keyboard[] = ['B'];
74-
$keyboard[] = ['C', 'D'];
75-
$keyboards[] = $keyboard;
60+
$keyboards[] = new Keyboard(
61+
['text' => 'A'],
62+
'B',
63+
['C', 'D']
64+
);
7665

7766
//Example 4 (bots version 2.0)
78-
$keyboard = [];
79-
$keyboard[] = [
80-
[
81-
'text' => 'Send my contact',
82-
'request_contact' => true,
83-
],
84-
[
85-
'text' => 'Send my location',
86-
'request_location' => true,
87-
],
88-
];
89-
$keyboards[] = $keyboard;
67+
$keyboards[] = new Keyboard([
68+
['text' => 'Send my contact', 'request_contact' => true],
69+
['text' => 'Send my location', 'request_location' => true],
70+
]);
9071

9172
//Return a random keyboard.
92-
$keyboard = $keyboards[mt_rand(0, count($keyboards) - 1)];
93-
$data['reply_markup'] = new ReplyKeyboardMarkup(
94-
[
95-
'keyboard' => $keyboard,
96-
'resize_keyboard' => true,
97-
'one_time_keyboard' => false,
98-
'selective' => false,
99-
]
100-
);
73+
$keyboard = $keyboards[mt_rand(0, count($keyboards) - 1)]
74+
->setResizeKeyboard(true)
75+
->setOneTimeKeyboard(true)
76+
->setSelective(false);
77+
78+
$chat_id = $this->getMessage()->getChat()->getId();
79+
$data = [
80+
'chat_id' => $chat_id,
81+
'text' => 'Press a Button:',
82+
'reply_markup' => $keyboard,
83+
];
10184

10285
return Request::sendMessage($data);
10386
}

examples/Commands/MarkdownCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class MarkdownCommand extends UserCommand
2323
* {@inheritdoc}
2424
*/
2525
protected $name = 'markdown';
26-
protected $description = 'Print Markdown tesxt';
26+
protected $description = 'Print Markdown text';
2727
protected $usage = '/markdown';
2828
protected $version = '1.0.1';
2929
/**#@-*/

0 commit comments

Comments
 (0)