Skip to content

Commit 4a788a3

Browse files
committed
Renaming to Conversation, Readme
1 parent 6a0d3d3 commit 4a788a3

File tree

8 files changed

+110
-95
lines changed

8 files changed

+110
-95
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ You can also store inline query and chosen inline query in the database.
348348
### Channels Support
349349

350350
All methods implemented can be used to manage channels.
351-
With [admin commands](#admin-commands) you can manage your channel directly with your bot private chat.
351+
With [admin commands](#admin-commands) you can manage your channels directly with your bot private chat.
352352

353353
### Commands
354354

@@ -397,7 +397,7 @@ $telegram->setCommandConfig('date', ['google_api_key' => 'your_google_api_key_he
397397
Enabling this feature, the admin bot can perform some super user commands like:
398398
- Send message to all chats */sendtoall*
399399
- List all the chats started with the bot */chats*
400-
- Send a message to a channel */sendtochannel* (NEW! see below how to configure it)
400+
- Send a message to your channels */sendtochannel* (NEW! see below how to configure it)
401401
You can specify one or more admins with this option:
402402

403403
```php
@@ -414,7 +414,11 @@ To enable this feature follow these steps:
414414
- Enable admin interface for your user as explained in the admin section above.
415415
- Enter your channel name as a parameter for the */sendtochannel* command:
416416
```php
417-
$telegram->setCommandConfig('sendtochannel', ['your_channel' => '@type_here_your_channel']);
417+
$telegram->setCommandConfig('sendtochannel', ['your_channel' => ['@type_here_your_channel']]);
418+
```
419+
- If you want to manage more channels:
420+
```php
421+
$telegram->setCommandConfig('sendtochannel', ['your_channel'=>['@type_here_your_channel', '@type_here_another_channel', '@and_so_on']]);
418422
```
419423
- Enjoy!
420424

src/Commands/AdminCommands/SendtochannelCommand.php

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace Longman\TelegramBot\Commands\AdminCommands;
1111

1212
use Longman\TelegramBot\Request;
13-
use Longman\TelegramBot\Tracking;
13+
use Longman\TelegramBot\Conversation;
1414
use Longman\TelegramBot\Entities\Message;
1515
use Longman\TelegramBot\Entities\ReplyKeyboardHide;
1616
use Longman\TelegramBot\Entities\ReplyKeyboardMarkup;
@@ -50,9 +50,9 @@ public function execute()
5050
$data['chat_id'] = $chat_id;
5151

5252
//tracking
53-
$path = new Tracking($user_id, $chat_id, $this->getName());
54-
$path->startTrack();
55-
$session = $path->GetData();
53+
$conversation = new Conversation($user_id, $chat_id, $this->getName());
54+
$conversation->start();
55+
$session = $conversation->getData();
5656

5757
if (!isset($session['state'])) {
5858
$state = '0';
@@ -68,7 +68,7 @@ public function execute()
6868
case 0:
6969
if ($type != 'Message' || !in_array(trim($text), $channels)) {
7070
$session['state'] = '0';
71-
$path->updateTrack($session);
71+
$conversation->update($session);
7272

7373
$keyboard = [];
7474
foreach ($channels as $channel) {
@@ -97,7 +97,7 @@ public function execute()
9797
case 1:
9898
if ($session['last_message_id'] == $message->getMessageId()) {
9999
$session['state'] = 1;
100-
$path->updateTrack($session);
100+
$conversation->update($session);
101101

102102
$data['reply_markup'] = new ReplyKeyBoardHide(['selective' => true]);
103103
$data['text'] = 'Insert the content you want to share: text, photo, audio...';
@@ -112,7 +112,7 @@ public function execute()
112112
case 2:
113113
if ($session['last_message_id'] == $message->getMessageId() || !($text == 'Yes' || $text == 'No')) {
114114
$session['state'] = 2;
115-
$path->updateTrack($session);
115+
$conversation->update($session);
116116

117117
if ($session['message_type'] == 'Video' || $session['message_type'] == 'Photo') {
118118
$keyboard = [['Yes', 'No']];
@@ -143,7 +143,7 @@ public function execute()
143143
case 3:
144144
if (($session['last_message_id'] == $message->getMessageId() || $type != 'Message' ) && $session['set_caption']) {
145145
$session['state'] = 3;
146-
$path->updateTrack($session);
146+
$conversation->update($session);
147147

148148
$data['text'] = 'Insert caption:';
149149
$data['reply_markup'] = new ReplyKeyBoardHide(['selective' => true]);
@@ -156,7 +156,7 @@ public function execute()
156156
case 4:
157157
if ($session['last_message_id'] == $message->getMessageId() || !($text == 'Yes' || $text == 'No')) {
158158
$session['state'] = '4';
159-
$path->updateTrack($session);
159+
$conversation->update($session);
160160

161161
$data['text'] = 'Message will look like this:';
162162
$result = Request::sendMessage($data);
@@ -194,7 +194,7 @@ public function execute()
194194
$session['last_message_id'] = $message->getMessageId();
195195
// no break
196196
case 5:
197-
$path->stopTrack();
197+
$conversation->stop();
198198

199199
$data['reply_markup'] = new ReplyKeyBoardHide(['selective' => true]);
200200

@@ -225,9 +225,20 @@ public function execute()
225225
}
226226

227227
/**
228+
* SendBack
229+
*
230+
* Received a message, the bot can send a copy of it to another chat/channel.
231+
* You don't have to care about the type of thei message, the function detect it and use the proper
232+
* REQUEST:: function to send it.
233+
* $data include all the var that you need to send the message to the propor chat
228234
*
229-
* @todo Complete dock block
230235
* @todo This method will be moved at an higher level maybe in AdminCommans or Command
236+
* @todo Looking for a more significative name
237+
*
238+
* @param Longman\TelegramBot\Entities\Message $message
239+
* @param array $data
240+
*
241+
* @return Longman\TelegramBot\Entities\ServerResponse
231242
*/
232243
public function sendBack(Message $message, array $data)
233244
{

src/Commands/SystemCommands/GenericmessageCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace Longman\TelegramBot\Commands\SystemCommands;
1212

13-
use Longman\TelegramBot\Tracking;
13+
use Longman\TelegramBot\Conversation;
1414
use Longman\TelegramBot\Commands\SystemCommand;
1515

1616
/**
@@ -50,7 +50,7 @@ public function execute()
5050
$chat_id = $message->getChat()->getId();
5151
$user_id = $message->getFrom()->getId();
5252
//Fetch Track if exist
53-
$command = (new Tracking($user_id, $chat_id))->getTrackCommand();
53+
$command = (new Conversation($user_id, $chat_id))->getConversationCommand();
5454
if (! is_null($command)) {
5555
return $this->telegram->executeCommand($command, $this->update);
5656
}

src/Commands/UserCommands/SurveyCommand.php

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

1212
use Longman\TelegramBot\Request;
13-
use Longman\TelegramBot\Tracking;
13+
use Longman\TelegramBot\Conversation;
1414
use Longman\TelegramBot\Commands\UserCommand;
1515
use Longman\TelegramBot\Entities\ForceReply;
1616
use Longman\TelegramBot\Entities\ReplyKeyboardHide;
@@ -57,11 +57,11 @@ public function execute()
5757
$data['chat_id'] = $chat_id;
5858

5959
//tracking
60-
$path = new Tracking($user_id, $chat_id, $this->getName());
61-
$path->startTrack();
60+
$conversation = new Conversation($user_id, $chat_id, $this->getName());
61+
$conversation->start();
6262

6363
//cache data from the tracking session if any
64-
$session = $path->GetData();
64+
$session = $conversation->GetData();
6565
if (!isset($session['state'])) {
6666
$state = '0';
6767
} else {
@@ -75,7 +75,7 @@ public function execute()
7575
case 0:
7676
if (empty($text)) {
7777
$session['state'] = '0';
78-
$path->updateTrack($session);
78+
$conversation->update($session);
7979

8080
$data['text'] = 'Type your name:';
8181
$data['reply_markup'] = new ReplyKeyBoardHide(['selective' => true]);
@@ -88,7 +88,7 @@ public function execute()
8888
case 1:
8989
if (empty($text)) {
9090
$session['state'] = 1;
91-
$path->updateTrack($session);
91+
$conversation->update($session);
9292

9393
$data['text'] = 'Type your surname:';
9494
$result = Request::sendMessage($data);
@@ -102,7 +102,7 @@ public function execute()
102102
case 2:
103103
if (empty($text) || !is_numeric($text)) {
104104
$session['state'] = '2';
105-
$path->updateTrack($session);
105+
$conversation->update($session);
106106
$data['text'] = 'Type your age:';
107107
if (!empty($text) && !is_numeric($text)) {
108108
$data['text'] = 'Type your age, must be a number';
@@ -117,7 +117,7 @@ public function execute()
117117
case 3:
118118
if (empty($text) || !($text == 'M' || $text == 'F')) {
119119
$session['state'] = '3';
120-
$path->updateTrack($session);
120+
$conversation->update($session);
121121

122122
$keyboard = [['M','F']];
123123
$reply_keyboard_markup = new ReplyKeyboardMarkup(
@@ -143,7 +143,7 @@ public function execute()
143143
case 4:
144144
if (is_null($message->getLocation())) {
145145
$session['state'] = '4';
146-
$path->updateTrack($session);
146+
$conversation->update($session);
147147

148148
$data['text'] = 'Insert your home location (need location object):';
149149
$data['reply_markup'] = new ReplyKeyBoardHide(['selective' => true]);
@@ -158,7 +158,7 @@ public function execute()
158158
case 5:
159159
if (is_null($message->getPhoto())) {
160160
$session['state'] = '5';
161-
$path->updateTrack($session);
161+
$conversation->update($session);
162162

163163
$data['text'] = 'Insert your picture:';
164164
$result = Request::sendMessage($data);
@@ -168,7 +168,7 @@ public function execute()
168168

169169
// no break
170170
case 6:
171-
$path->stopTrack();
171+
$conversation->stop();
172172
$out_text = '/Survey result:' . "\n";
173173
unset($session['state']);
174174
foreach ($session as $k => $v) {

0 commit comments

Comments
 (0)