Skip to content

Refactor entities #291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Nov 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f6fb481
Initial ugly commit of the refactored Entities.
noplanman Aug 27, 2016
3791a65
Update all InlineQueryResult classes with getters and setters.
noplanman Sep 2, 2016
95867a6
Update InlinequeryCommand SystemCommand with new classes.
noplanman Sep 2, 2016
da0a94d
Update entity tests.
noplanman Sep 2, 2016
8737a14
Merge remote-tracking branch 'origin/master' into refactor_entities
noplanman Sep 2, 2016
8ec1b2d
Merge remote-tracking branch 'upstream/develop' into refactor_entities
noplanman Sep 2, 2016
c38610f
Merge remote-tracking branch 'upstream/develop' into refactor_entities
noplanman Sep 8, 2016
d30757a
If a pretty object array is empty, return null instead of an empty ar…
noplanman Sep 21, 2016
bf5c064
Add initial rewrites of keyboard entities.
noplanman Sep 21, 2016
2711d62
First rewrite of the keyboard entities.
noplanman Sep 23, 2016
94aa39e
introduce md tryMention
MBoretto Sep 28, 2016
c816458
improving try mention markdown
MBoretto Sep 29, 2016
c35a03f
Merge pull request #3 from MBoretto/md_mention
noplanman Sep 29, 2016
8dba19f
Add initial keyboard tests and fix a few keyboard issues.
noplanman Oct 1, 2016
9eb50bb
Change interpretation of keyboard parameters, so that each parameter …
noplanman Oct 3, 2016
ce42f43
Add InlineKeyboard tests and fix createFromParams method.
noplanman Oct 3, 2016
1b66475
Remove unnecessary conditional when creating keyboard from params.
noplanman Oct 4, 2016
0001e68
Add extra keyboard tests and fix keyboard row and button parsing.
noplanman Oct 5, 2016
f9a70a2
Make use of the new Keyboard entities.
noplanman Oct 10, 2016
d58e54b
Fix survey command to use new Keyboard entities.
noplanman Oct 10, 2016
3120727
Improve docblock for object arrays.
noplanman Oct 10, 2016
d1b4f1c
Fix sendtochannel command to use updated code and use new Keyboard en…
noplanman Oct 10, 2016
9ef9730
Merge remote-tracking branch 'upstream/develop' into refactor_entities
noplanman Oct 10, 2016
d4baa56
Update getWebhookInfo entity to new structure.
noplanman Oct 10, 2016
c268c7f
Use proper InlineKeyboard type hinting for inline queries.
noplanman Oct 10, 2016
d220516
Move tryMention to the Entity class.
noplanman Oct 10, 2016
01b137c
Fix ReplyToMessage class, as data wasn't set properly.
noplanman Oct 10, 2016
27cc9e9
Fix tryMention for Chat entity and add extra Chat tests.
noplanman Oct 10, 2016
a4ea86d
Update Message tests and add initial ones for getType.
noplanman Oct 10, 2016
1cfa477
Optimise tryMention a bit, removing duplicate code.
noplanman Oct 10, 2016
1ff9b4f
Simplify Keyboard entities and tests to remove duplicate code.
noplanman Oct 11, 2016
879ceb9
Return body on request exception instead of throwing TelegramException.
noplanman Oct 11, 2016
6009277
Remove entity reflect method and replace it by saving the raw data ar…
noplanman Oct 11, 2016
be54377
Use new Entity schema for ServerResponse and save raw_data in Entities.
noplanman Oct 11, 2016
b1cc1f0
Update docblock comments for Request methods.
noplanman Oct 11, 2016
38a8658
Clean up Entity tests.
noplanman Oct 11, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions examples/Commands/ForcereplyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
namespace Longman\TelegramBot\Commands\UserCommands;

use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Entities\Keyboard;
use Longman\TelegramBot\Request;
use Longman\TelegramBot\Entities\ForceReply;

/**
* User "/forcereply" command
Expand All @@ -25,21 +25,20 @@ class ForceReplyCommand extends UserCommand
protected $name = 'forcereply';
protected $description = 'Force reply with reply markup';
protected $usage = '/forcereply';
protected $version = '0.0.6';
protected $version = '0.1.0';
/**#@-*/

/**
* {@inheritdoc}
*/
public function execute()
{
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$chat_id = $this->getMessage()->getChat()->getId();

$data = [
'chat_id' => $chat_id,
'text' => 'Write something:',
'reply_markup' => new ForceReply(['selective' => false]),
'reply_markup' => Keyboard::forceReply(),
];

return Request::sendMessage($data);
Expand Down
10 changes: 4 additions & 6 deletions examples/Commands/HidekeyboardCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
namespace Longman\TelegramBot\Commands\UserCommands;

use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Entities\ReplyKeyboardHide;
use Longman\TelegramBot\Entities\ReplyKeyboardMarkup;
use Longman\TelegramBot\Entities\Keyboard;
use Longman\TelegramBot\Request;

/**
Expand All @@ -26,21 +25,20 @@ class HidekeyboardCommand extends UserCommand
protected $name = 'hidekeyboard';
protected $description = 'Hide the custom keyboard';
protected $usage = '/hidekeyboard';
protected $version = '0.0.6';
protected $version = '0.1.0';
/**#@-*/

/**
* {@inheritdoc}
*/
public function execute()
{
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$chat_id = $this->getMessage()->getChat()->getId();

$data = [
'chat_id' => $chat_id,
'text' => 'Keyboard Hidden',
'reply_markup' => new ReplyKeyboardHide(['selective' => false]),
'reply_markup' => Keyboard::hide(),
];

return Request::sendMessage($data);
Expand Down
26 changes: 13 additions & 13 deletions examples/Commands/InlinekeyboardCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
namespace Longman\TelegramBot\Commands\UserCommands;

use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Entities\InlineKeyboard;
use Longman\TelegramBot\Request;
use Longman\TelegramBot\Entities\InlineKeyboardMarkup;
use Longman\TelegramBot\Entities\InlineKeyboardButton;

/**
* User "/inlinekeyboard" command
Expand All @@ -23,28 +22,29 @@ class InlinekeyboardCommand extends UserCommand
/**#@+
* {@inheritdoc}
*/
protected $name = 'Inlinekeyboard';
protected $name = 'inlinekeyboard';
protected $description = 'Show inline keyboard';
protected $usage = '/inlinekeyboard';
protected $version = '0.0.2';
protected $version = '0.1.0';
/**#@-*/

/**
* {@inheritdoc}
*/
public function execute()
{
$message = $this->getMessage();
$chat_id = $this->getMessage()->getChat()->getId();

$inline_keyboard = [
new InlineKeyboardButton(['text' => 'inline', 'switch_inline_query' => 'true']),
new InlineKeyboardButton(['text' => 'callback', 'callback_data' => 'identifier']),
new InlineKeyboardButton(['text' => 'open url', 'url' => 'https://github.com/akalongman/php-telegram-bot']),
];
$data = [
'chat_id' => $message->getChat()->getId(),
$inline_keyboard = new InlineKeyboard([
['text' => 'inline', 'switch_inline_query' => 'true'],
['text' => 'callback', 'callback_data' => 'identifier'],
['text' => 'open url', 'url' => 'https://github.com/akalongman/php-telegram-bot'],
]);

$data = [
'chat_id' => $chat_id,
'text' => 'inline keyboard',
'reply_markup' => new InlineKeyboardMarkup(['inline_keyboard' => [$inline_keyboard]]),
'reply_markup' => $inline_keyboard,
];

return Request::sendMessage($data);
Expand Down
89 changes: 36 additions & 53 deletions examples/Commands/KeyboardCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
namespace Longman\TelegramBot\Commands\UserCommands;

use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Entities\Keyboard;
use Longman\TelegramBot\Request;
use Longman\TelegramBot\Entities\ReplyKeyboardMarkup;

/**
* User "/keyboard" command
Expand All @@ -25,79 +25,62 @@ class KeyboardCommand extends UserCommand
protected $name = 'keyboard';
protected $description = 'Show a custom keyboard with reply markup';
protected $usage = '/keyboard';
protected $version = '0.1.0';
protected $version = '0.2.0';
/**#@-*/

/**
* {@inheritdoc}
*/
public function execute()
{
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();

$data = [
'chat_id' => $chat_id,
'text' => 'Press a Button:',
];

//Keyboard examples
/** @var Keyboard[] $keyboards */
$keyboards = [];

//Example 0
$keyboard = [];
$keyboard[] = ['7', '8', '9'];
$keyboard[] = ['4', '5', '6'];
$keyboard[] = ['1', '2', '3'];
$keyboard[] = [' ', '0', ' '];
$keyboards[] = $keyboard;
$keyboards[] = new Keyboard(
['7', '8', '9'],
['4', '5', '6'],
['1', '2', '3'],
[' ', '0', ' ']
);

//Example 1
$keyboard = [];
$keyboard[] = ['7', '8', '9', '+'];
$keyboard[] = ['4', '5', '6', '-'];
$keyboard[] = ['1', '2', '3', '*'];
$keyboard[] = [' ', '0', ' ', '/'];
$keyboards[] = $keyboard;
$keyboards[] = new Keyboard(
['7', '8', '9', '+'],
['4', '5', '6', '-'],
['1', '2', '3', '*'],
[' ', '0', ' ', '/']
);

//Example 2
$keyboard = [];
$keyboard[] = ['A'];
$keyboard[] = ['B'];
$keyboard[] = ['C'];
$keyboards[] = $keyboard;
$keyboards[] = new Keyboard('A', 'B', 'C');

//Example 3
$keyboard = [];
$keyboard[] = ['A'];
$keyboard[] = ['B'];
$keyboard[] = ['C', 'D'];
$keyboards[] = $keyboard;
$keyboards[] = new Keyboard(
['text' => 'A'],
'B',
['C', 'D']
);

//Example 4 (bots version 2.0)
$keyboard = [];
$keyboard[] = [
[
'text' => 'Send my contact',
'request_contact' => true,
],
[
'text' => 'Send my location',
'request_location' => true,
],
];
$keyboards[] = $keyboard;
$keyboards[] = new Keyboard([
['text' => 'Send my contact', 'request_contact' => true],
['text' => 'Send my location', 'request_location' => true],
]);

//Return a random keyboard.
$keyboard = $keyboards[mt_rand(0, count($keyboards) - 1)];
$data['reply_markup'] = new ReplyKeyboardMarkup(
[
'keyboard' => $keyboard,
'resize_keyboard' => true,
'one_time_keyboard' => false,
'selective' => false,
]
);
$keyboard = $keyboards[mt_rand(0, count($keyboards) - 1)]
->setResizeKeyboard(true)
->setOneTimeKeyboard(true)
->setSelective(false);

$chat_id = $this->getMessage()->getChat()->getId();
$data = [
'chat_id' => $chat_id,
'text' => 'Press a Button:',
'reply_markup' => $keyboard,
];

return Request::sendMessage($data);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/Commands/MarkdownCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MarkdownCommand extends UserCommand
* {@inheritdoc}
*/
protected $name = 'markdown';
protected $description = 'Print Markdown tesxt';
protected $description = 'Print Markdown text';
protected $usage = '/markdown';
protected $version = '1.0.1';
/**#@-*/
Expand Down
Loading