Skip to content

Commit c7837b0

Browse files
committed
new command structure in examples
1 parent 9828c73 commit c7837b0

File tree

5 files changed

+81
-100
lines changed

5 files changed

+81
-100
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ The Bot can:
2828
- handle commands in chat with other bots.
2929
- manage Channel from the bot admin interface.
3030
- full support for **inline bots**. (**new!**)
31-
- Messages, InlineQuery and ChosenInlineQuery are stored in the Database. (**new!**)
31+
- Messages, InlineQuery and ChosenInlineQuery are stored in the Database.
32+
- Conversation feature (**new!**)
3233

3334
-----
3435
This code is available on
@@ -397,7 +398,7 @@ $telegram->setCommandConfig('date', ['google_api_key' => 'your_google_api_key_he
397398
Enabling this feature, the admin bot can perform some super user commands like:
398399
- Send message to all chats */sendtoall*
399400
- List all the chats started with the bot */chats*
400-
- Send a message to your channels */sendtochannel* (NEW! see below how to configure it)
401+
- Post any content to your channels */sendtochannel* (NEW! see below how to configure it)
401402
You can specify one or more admins with this option:
402403

403404
```php
Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,46 @@
11
<?php
2-
3-
/*
2+
/**
43
* This file is part of the TelegramBot package.
54
*
65
* (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
76
*
87
* For the full copyright and license information, please view the LICENSE
98
* file that was distributed with this source code.
10-
* Written by <[email protected]>
11-
*/
12-
namespace Longman\TelegramBot\Commands;
9+
*/
1310

14-
use Longman\TelegramBot\Request;
15-
use Longman\TelegramBot\Command;
16-
use Longman\TelegramBot\Entities\Update;
11+
namespace Longman\TelegramBot\Commands\UserCommands;
1712

18-
use Longman\TelegramBot\Entities\ReplyKeyboardMarkup;
19-
use Longman\TelegramBot\Entities\ReplyKeyboardHide;
13+
use Longman\TelegramBot\Commands\UserCommand;
14+
use Longman\TelegramBot\Request;
2015
use Longman\TelegramBot\Entities\ForceReply;
2116

22-
class ForceReplyCommand extends Command
17+
/**
18+
* User "/forcereply" command
19+
*/
20+
class ForceReplyCommand extends UserCommand
2321
{
22+
/**#@+
23+
* {@inheritdoc}
24+
*/
2425
protected $name = 'forcereply';
2526
protected $description = 'Force reply with reply markup';
2627
protected $usage = '/forcereply';
2728
protected $version = '0.0.5';
28-
protected $enabled = true;
29+
/**#@-*/
2930

31+
/**
32+
* {@inheritdoc}
33+
*/
3034
public function execute()
3135
{
32-
$update = $this->getUpdate();
3336
$message = $this->getMessage();
34-
$message_id = $message->getMessageId();
35-
3637
$chat_id = $message->getChat()->getId();
37-
$text = $message->getText(true);
3838

39-
$data = array();
39+
$data = [];
4040
$data['chat_id'] = $chat_id;
4141
$data['text'] = 'Write something:';
42-
#$data['reply_to_message_id'] = $message_id;
43-
44-
$force_reply = new ForceReply(['selective' => false]);
45-
46-
#echo $json;
47-
$data['reply_markup'] = $force_reply;
48-
42+
$data['reply_markup'] = new ForceReply(['selective' => false]);
4943

50-
$result = Request::sendMessage($data);
51-
return $result;
44+
return Request::sendMessage($data);
5245
}
5346
}
Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,46 @@
11
<?php
2-
3-
/*
2+
/**
43
* This file is part of the TelegramBot package.
54
*
65
* (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
76
*
87
* For the full copyright and license information, please view the LICENSE
98
* file that was distributed with this source code.
10-
* Written by Marco Boretto <[email protected]>
11-
*/
12-
namespace Longman\TelegramBot\Commands;
9+
*/
1310

14-
use Longman\TelegramBot\Request;
15-
use Longman\TelegramBot\Command;
16-
use Longman\TelegramBot\Entities\Update;
11+
namespace Longman\TelegramBot\Commands\UserCommands;
1712

13+
use Longman\TelegramBot\Commands\UserCommand;
14+
use Longman\TelegramBot\Request;
1815
use Longman\TelegramBot\Entities\ReplyKeyboardMarkup;
19-
use Longman\TelegramBot\Entities\ReplyKeyboardHide;
20-
use Longman\TelegramBot\Entities\ForceReply;
2116

22-
class HidekeyboardCommand extends Command
17+
/**
18+
* User "/hidekeyboard" command
19+
*/
20+
class HidekeyboardCommand extends UserCommand
2321
{
22+
/**#@+
23+
* {@inheritdoc}
24+
*/
2425
protected $name = 'hidekeyboard';
2526
protected $description = 'Hide the custom keyboard';
2627
protected $usage = '/hidekeyboard';
2728
protected $version = '0.0.5';
28-
protected $enabled = true;
29+
/**#@-*/
2930

31+
/**
32+
* {@inheritdoc}
33+
*/
3034
public function execute()
3135
{
32-
$update = $this->getUpdate();
3336
$message = $this->getMessage();
34-
$message_id = $message->getMessageId();
35-
3637
$chat_id = $message->getChat()->getId();
37-
$text = $message->getText(true);
3838

39-
$data = array();
39+
$data = [];
4040
$data['chat_id'] = $chat_id;
4141
$data['text'] = 'Keyboard Hided';
42-
#$data['reply_to_message_id'] = $message_id;
43-
44-
$reply_keyboard_hide = new ReplyKeyboardHide([ 'selective' => false]);
45-
46-
$data['reply_markup'] = $reply_keyboard_hide;
42+
$data['reply_markup'] = new ReplyKeyboardHide([ 'selective' => false]);
4743

48-
$result = Request::sendMessage($data);
49-
return $result;
44+
return Request::sendMessage($data);
5045
}
5146
}

examples/Commands/ImageCommand.php

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,46 @@
11
<?php
2-
3-
/*
2+
/**
43
* This file is part of the TelegramBot package.
54
*
65
* (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
76
*
87
* For the full copyright and license information, please view the LICENSE
98
* file that was distributed with this source code.
10-
*/
11-
namespace Longman\TelegramBot\Commands;
9+
*/
10+
11+
namespace Longman\TelegramBot\Commands\UserCommands;
1212

13+
use Longman\TelegramBot\Commands\UserCommand;
1314
use Longman\TelegramBot\Request;
14-
use Longman\TelegramBot\Command;
15-
use Longman\TelegramBot\Entities\Update;
15+
use Longman\TelegramBot\Entities\ReplyKeyboardMarkup;
1616

17-
class ImageCommand extends Command
17+
/**
18+
* User "/image" command
19+
*/
20+
class ImageCommand extends UserCommand
1821
{
22+
/**#@+
23+
* {@inheritdoc}
24+
*/
1925
protected $name = 'image';
2026
protected $description = 'Send Image';
2127
protected $usage = '/image';
2228
protected $version = '1.0.0';
23-
protected $enabled = true;
24-
protected $public = true;
29+
/**#@-*/
2530

31+
/**
32+
* {@inheritdoc}
33+
*/
2634
public function execute()
2735
{
28-
$update = $this->getUpdate();
2936
$message = $this->getMessage();
30-
3137
$chat_id = $message->getChat()->getId();
3238
$text = $message->getText(true);
3339

34-
$data = array();
40+
$data = [];
3541
$data['chat_id'] = $chat_id;
3642
$data['caption'] = $text;
3743

38-
39-
//$result = Request::sendDocument($data,'structure.sql');
40-
//$result = Request::sendSticker($data, $this->telegram->getUploadPath().'/'.'image.jpg');
41-
42-
$result = Request::sendPhoto($data, $this->telegram->getUploadPath().'/'.'image.jpg');
43-
return $result;
44+
return Request::sendPhoto($data, $this->telegram->getUploadPath().'/'.'image.jpg');
4445
}
4546
}

examples/Commands/KeyboardCommand.php

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,48 @@
11
<?php
2-
3-
/*
2+
/**
43
* This file is part of the TelegramBot package.
54
*
65
* (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
76
*
87
* For the full copyright and license information, please view the LICENSE
98
* file that was distributed with this source code.
10-
* written by Marco Boretto <[email protected]>
11-
*/
12-
namespace Longman\TelegramBot\Commands;
9+
*/
1310

14-
use Longman\TelegramBot\Request;
15-
use Longman\TelegramBot\Command;
16-
use Longman\TelegramBot\Entities\Update;
11+
namespace Longman\TelegramBot\Commands\UserCommands;
1712

13+
use Longman\TelegramBot\Commands\UserCommand;
14+
use Longman\TelegramBot\Request;
1815
use Longman\TelegramBot\Entities\ReplyKeyboardMarkup;
19-
use Longman\TelegramBot\Entities\ReplyKeyboardHide;
20-
use Longman\TelegramBot\Entities\ForceReply;
2116

22-
class KeyboardCommand extends Command
17+
/**
18+
* User "/keyboard" command
19+
*/
20+
class KeyboardCommand extends UserCommand
2321
{
22+
/**#@+
23+
* {@inheritdoc}
24+
*/
2425
protected $name = 'keyboard';
2526
protected $description = 'Show a custom keybord with reply markup';
2627
protected $usage = '/keyboard';
2728
protected $version = '0.0.5';
28-
protected $enabled = true;
29+
/**#@-*/
2930

31+
/**
32+
* {@inheritdoc}
33+
*/
3034
public function execute()
3135
{
32-
$update = $this->getUpdate();
3336
$message = $this->getMessage();
34-
$message_id = $message->getMessageId();
35-
3637
$chat_id = $message->getChat()->getId();
3738
$text = $message->getText(true);
3839

39-
$data = array();
40+
$data = [];
4041
$data['chat_id'] = $chat_id;
4142
$data['text'] = 'Press a Button:';
42-
#$data['reply_to_message_id'] = $message_id;
43-
4443

45-
46-
#Keyboard examples
47-
$keyboards = array();
44+
//Keyboard examples
45+
$keyboards = [];
4846

4947
//0
5048
$keyboard[] = ['7','8','9'];
@@ -64,7 +62,6 @@ public function execute()
6462
$keyboards[] = $keyboard;
6563
unset($keyboard);
6664

67-
6865
//2
6966
$keyboard[] = ['A'];
7067
$keyboard[] = ['B'];
@@ -73,8 +70,6 @@ public function execute()
7370
$keyboards[] = $keyboard;
7471
unset($keyboard);
7572

76-
77-
7873
//3
7974
$keyboard[] = ['A'];
8075
$keyboard[] = ['B'];
@@ -83,19 +78,15 @@ public function execute()
8378
$keyboards[] = $keyboard;
8479
unset($keyboard);
8580

86-
87-
$reply_keyboard_markup = new ReplyKeyboardMarkup(
81+
$data['reply_markup'] = new ReplyKeyboardMarkup(
8882
[
8983
'keyboard' => $keyboards[1] ,
9084
'resize_keyboard' => true,
9185
'one_time_keyboard' => false,
9286
'selective' => false
9387
]
9488
);
95-
#echo $json;
96-
$data['reply_markup'] = $reply_keyboard_markup;
9789

98-
$result = Request::sendMessage($data);
99-
return $result;
90+
return Request::sendMessage($data);
10091
}
10192
}

0 commit comments

Comments
 (0)