-
-
Notifications
You must be signed in to change notification settings - Fork 964
/
Copy pathTelegram.php
1336 lines (1154 loc) · 35.1 KB
/
Telegram.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot;
defined('TB_BASE_PATH') || define('TB_BASE_PATH', __DIR__);
defined('TB_BASE_COMMANDS_PATH') || define('TB_BASE_COMMANDS_PATH', TB_BASE_PATH . '/Commands');
use Exception;
use InvalidArgumentException;
use Longman\TelegramBot\Commands\AdminCommand;
use Longman\TelegramBot\Commands\Command;
use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Entities\Chat;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Entities\User;
use Longman\TelegramBot\Exception\TelegramException;
use PDO;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use RegexIterator;
class Telegram
{
/**
* Version
*
* @var string
*/
protected $version = '0.82.0';
/**
* Telegram API key
*
* @var string
*/
protected $api_key = '';
/**
* Telegram Bot username
*
* @var string
*/
protected $bot_username = '';
/**
* Telegram Bot id
*
* @var int
*/
protected $bot_id = 0;
/**
* Raw request data (json) for webhook methods
*
* @var string
*/
protected $input = '';
/**
* Custom commands paths
*
* @var array
*/
protected $commands_paths = [];
/**
* Custom command class names
* ```
* [
* 'User' => [
* // command_name => command_class
* 'start' => 'name\space\to\StartCommand',
* ],
* 'Admin' => [], //etc
* ]
* ```
*
* @var array
*/
protected $command_classes = [
Command::AUTH_USER => [],
Command::AUTH_ADMIN => [],
Command::AUTH_SYSTEM => [],
];
/**
* Custom commands objects
*
* @var array
*/
protected $commands_objects = [];
/**
* Current Update object
*
* @var Update
*/
protected $update;
/**
* Upload path
*
* @var string
*/
protected $upload_path = '';
/**
* Download path
*
* @var string
*/
protected $download_path = '';
/**
* MySQL integration
*
* @var bool
*/
protected $mysql_enabled = false;
/**
* PDO object
*
* @var PDO
*/
protected $pdo;
/**
* Commands config
*
* @var array
*/
protected $commands_config = [];
/**
* Admins list
*
* @var array
*/
protected $admins_list = [];
/**
* ServerResponse of the last Command execution
*
* @var ServerResponse
*/
protected $last_command_response;
/**
* Check if runCommands() is running in this session
*
* @var bool
*/
protected $run_commands = false;
/**
* Is running getUpdates without DB enabled
*
* @var bool
*/
protected $getupdates_without_database = false;
/**
* Last update ID
* Only used when running getUpdates without a database
*
* @var int
*/
protected $last_update_id;
/**
* The command to be executed when there's a new message update and nothing more suitable is found
*/
public const GENERIC_MESSAGE_COMMAND = 'genericmessage';
/**
* The command to be executed by default (when no other relevant commands are applicable)
*/
public const GENERIC_COMMAND = 'generic';
/**
* Update filter method
*
* @var callable
*/
protected $update_filter;
/**
* Telegram constructor.
*
* @param string $api_key
* @param string $bot_username
*
* @throws TelegramException
*/
public function __construct(string $api_key, string $bot_username = '')
{
if (empty($api_key)) {
throw new TelegramException('API KEY not defined!');
}
preg_match('/(\d+):[\w\-]+/', $api_key, $matches);
if (!isset($matches[1])) {
throw new TelegramException('Invalid API KEY defined!');
}
$this->bot_id = (int) $matches[1];
$this->api_key = $api_key;
$this->bot_username = $bot_username;
//Add default system commands path
$this->addCommandsPath(TB_BASE_COMMANDS_PATH . '/SystemCommands');
Request::initialize($this);
}
/**
* Initialize Database connection
*
* @param array $credentials
* @param string $table_prefix
* @param string $encoding
*
* @return Telegram
* @throws TelegramException
*/
public function enableMySql(array $credentials, string $table_prefix = '', string $encoding = 'utf8mb4'): Telegram
{
$this->pdo = DB::initialize($credentials, $this, $table_prefix, $encoding);
ConversationDB::initializeConversation();
$this->mysql_enabled = true;
return $this;
}
/**
* Initialize Database external connection
*
* @param PDO $external_pdo_connection PDO database object
* @param string $table_prefix
*
* @return Telegram
* @throws TelegramException
*/
public function enableExternalMySql(PDO $external_pdo_connection, string $table_prefix = ''): Telegram
{
$this->pdo = DB::externalInitialize($external_pdo_connection, $this, $table_prefix);
ConversationDB::initializeConversation();
$this->mysql_enabled = true;
return $this;
}
/**
* Get commands list
*
* @return array $commands
* @throws TelegramException
*/
public function getCommandsList(): array
{
$commands = [];
foreach ($this->commands_paths as $path) {
try {
//Get all "*Command.php" files
$files = new RegexIterator(
new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path)
),
'/^.+Command.php$/'
);
foreach ($files as $file) {
// Convert filename to command
$command = $this->classNameToCommandName(substr($file->getFilename(), 0, -4));
// Invalid Classname
if (is_null($command)) {
continue;
}
// Already registered
if (array_key_exists($command, $commands)) {
continue;
}
require_once $file->getPathname();
$command_obj = $this->getCommandObject($command, $file->getPathname());
if ($command_obj instanceof Command) {
$commands[$command] = $command_obj;
}
}
} catch (Exception $e) {
throw new TelegramException('Error getting commands from path: ' . $path, 0, $e);
}
}
return $commands;
}
/**
* Get classname of predefined commands
*
* @see command_classes
*
* @param string $auth Auth of command
* @param string $command Command name
* @param string $filepath Path to the command file
*
* @return string|null
*/
public function getCommandClassName(string $auth, string $command, string $filepath = ''): ?string
{
$command = mb_strtolower($command);
// Invalid command
if (trim($command) === '') {
return null;
}
$auth = $this->ucFirstUnicode($auth);
// First, check for directly assigned command class.
if ($command_class = $this->command_classes[$auth][$command] ?? null) {
return $command_class;
}
// Start with default namespace.
$command_namespace = __NAMESPACE__ . '\\Commands\\' . $auth . 'Commands';
// Check if we can get the namespace from the file (if passed).
if ($filepath && !($command_namespace = $this->getFileNamespace($filepath))) {
return null;
}
$command_class = $command_namespace . '\\' . $this->commandNameToClassName($command);
if (class_exists($command_class)) {
return $command_class;
}
return null;
}
/**
* Get an object instance of the passed command
*
* @param string $command
* @param string $filepath
*
* @return Command|null
*/
public function getCommandObject(string $command, string $filepath = ''): ?Command
{
if (isset($this->commands_objects[$command])) {
return $this->commands_objects[$command];
}
$which = [Command::AUTH_SYSTEM];
$this->isAdmin() && $which[] = Command::AUTH_ADMIN;
$which[] = Command::AUTH_USER;
foreach ($which as $auth) {
$command_class = $this->getCommandClassName($auth, $command, $filepath);
if ($command_class) {
$command_obj = new $command_class($this, $this->update);
if ($auth === Command::AUTH_SYSTEM && $command_obj instanceof SystemCommand) {
return $command_obj;
}
if ($auth === Command::AUTH_ADMIN && $command_obj instanceof AdminCommand) {
return $command_obj;
}
if ($auth === Command::AUTH_USER && $command_obj instanceof UserCommand) {
return $command_obj;
}
}
}
return null;
}
/**
* Get namespace from php file by src path
*
* @param string $src (absolute path to file)
*
* @return string|null ("Longman\TelegramBot\Commands\SystemCommands" for example)
*/
protected function getFileNamespace(string $src): ?string
{
$content = file_get_contents($src);
if (preg_match('#^\s*namespace\s+(.+?);#m', $content, $m)) {
return $m[1];
}
return null;
}
/**
* Set custom input string for debug purposes
*
* @param string $input (json format)
*
* @return Telegram
*/
public function setCustomInput(string $input): Telegram
{
$this->input = $input;
return $this;
}
/**
* Get custom input string for debug purposes
*
* @return string
*/
public function getCustomInput(): string
{
return $this->input;
}
/**
* Get the ServerResponse of the last Command execution
*
* @return ServerResponse
*/
public function getLastCommandResponse(): ServerResponse
{
return $this->last_command_response;
}
/**
* Handle getUpdates method
*
* @todo Remove backwards compatibility for old signature and force $data to be an array.
*
* @param array|int|null $data
* @param int|null $timeout
*
* @return ServerResponse
* @throws TelegramException
*/
public function handleGetUpdates($data = null, ?int $timeout = null): ServerResponse
{
if (empty($this->bot_username)) {
throw new TelegramException('Bot Username is not defined!');
}
if (!DB::isDbConnected() && !$this->getupdates_without_database) {
return new ServerResponse(
[
'ok' => false,
'description' => 'getUpdates needs MySQL connection! (This can be overridden - see documentation)',
],
$this->bot_username
);
}
$offset = 0;
$limit = null;
// By default, get update types sent by Telegram.
$allowed_updates = [];
// @todo Backwards compatibility for old signature, remove in next version.
if (!is_array($data)) {
$limit = $data;
@trigger_error(
sprintf('Use of $limit and $timeout parameters in %s is deprecated. Use $data array instead.', __METHOD__),
E_USER_DEPRECATED
);
} else {
$offset = $data['offset'] ?? $offset;
$limit = $data['limit'] ?? $limit;
$timeout = $data['timeout'] ?? $timeout;
$allowed_updates = $data['allowed_updates'] ?? $allowed_updates;
}
// Take custom input into account.
if ($custom_input = $this->getCustomInput()) {
try {
$input = json_decode($this->input, true, 512, JSON_THROW_ON_ERROR);
if (empty($input)) {
throw new TelegramException('Custom input is empty');
}
$response = new ServerResponse($input, $this->bot_username);
} catch (\Throwable $e) {
throw new TelegramException('Invalid custom input JSON: ' . $e->getMessage());
}
} else {
if (DB::isDbConnected() && $last_update = DB::selectTelegramUpdate(1)) {
// Get last Update id from the database.
$last_update = reset($last_update);
$this->last_update_id = $last_update['id'] ?? null;
}
if ($this->last_update_id !== null) {
$offset = $this->last_update_id + 1; // As explained in the telegram bot API documentation.
}
$response = Request::getUpdates(compact('offset', 'limit', 'timeout', 'allowed_updates'));
}
if ($response->isOk()) {
// Log update.
TelegramLog::update($response->toJson());
// Process all updates
/** @var Update $update */
foreach ($response->getResult() as $update) {
$this->processUpdate($update);
}
if (!DB::isDbConnected() && !$custom_input && $this->last_update_id !== null && $offset === 0) {
// Mark update(s) as read after handling
$offset = $this->last_update_id + 1;
$limit = 1;
Request::getUpdates(compact('offset', 'limit', 'timeout', 'allowed_updates'));
}
}
return $response;
}
/**
* Handle bot request from webhook
*
* @return bool
*
* @throws TelegramException
*/
public function handle(): bool
{
if ($this->bot_username === '') {
throw new TelegramException('Bot Username is not defined!');
}
$input = Request::getInput();
if (empty($input)) {
throw new TelegramException('Input is empty! The webhook must not be called manually, only by Telegram.');
}
// Log update.
TelegramLog::update($input);
$post = json_decode($input, true);
if (empty($post)) {
throw new TelegramException('Invalid input JSON! The webhook must not be called manually, only by Telegram.');
}
if ($response = $this->processUpdate(new Update($post, $this->bot_username))) {
return $response->isOk();
}
return false;
}
/**
* Get the command name from the command type
*
* @param string $type
*
* @return string
*/
protected function getCommandFromType(string $type): string
{
return $this->ucFirstUnicode(str_replace('_', '', $type));
}
/**
* Process bot Update request
*
* @param Update $update
*
* @return ServerResponse
* @throws TelegramException
*/
public function processUpdate(Update $update): ServerResponse
{
$this->update = $update;
$this->last_update_id = $update->getUpdateId();
if (is_callable($this->update_filter)) {
$reason = 'Update denied by update_filter';
try {
$allowed = (bool) call_user_func_array($this->update_filter, [$update, $this, &$reason]);
} catch (Exception $e) {
$allowed = false;
}
if (!$allowed) {
TelegramLog::debug($reason);
return new ServerResponse(['ok' => false, 'description' => 'denied']);
}
}
//Load admin commands
if ($this->isAdmin()) {
$this->addCommandsPath(TB_BASE_COMMANDS_PATH . '/AdminCommands', false);
}
//Make sure we have an up-to-date command list
//This is necessary to "require" all the necessary command files!
$this->commands_objects = $this->getCommandsList();
//If all else fails, it's a generic message.
$command = self::GENERIC_MESSAGE_COMMAND;
$update_type = $this->update->getUpdateType();
if ($update_type === 'message') {
$message = $this->update->getMessage();
$type = $message->getType();
// Let's check if the message object has the type field we're looking for...
$command_tmp = $type === 'command' ? $message->getCommand() : $this->getCommandFromType($type);
// ...and if a fitting command class is available.
$command_obj = $command_tmp ? $this->getCommandObject($command_tmp) : null;
// Empty usage string denotes a non-executable command.
// @see https://github.com/php-telegram-bot/core/issues/772#issuecomment-388616072
if (
($command_obj === null && $type === 'command')
|| ($command_obj !== null && $command_obj->getUsage() !== '')
) {
$command = $command_tmp;
}
} elseif ($update_type !== null) {
$command = $this->getCommandFromType($update_type);
}
//Make sure we don't try to process update that was already processed
$last_id = DB::selectTelegramUpdate(1, $this->update->getUpdateId());
if ($last_id && count($last_id) === 1) {
TelegramLog::debug('Duplicate update received, processing aborted!');
return Request::emptyResponse();
}
DB::insertRequest($this->update);
return $this->executeCommand($command);
}
/**
* Execute /command
*
* @param string $command
*
* @return ServerResponse
* @throws TelegramException
*/
public function executeCommand(string $command): ServerResponse
{
$command = mb_strtolower($command);
$command_obj = $this->commands_objects[$command] ?? $this->getCommandObject($command);
if (!$command_obj || !$command_obj->isEnabled()) {
//Failsafe in case the Generic command can't be found
if ($command === self::GENERIC_COMMAND) {
throw new TelegramException('Generic command missing!');
}
//Handle a generic command or non existing one
$this->last_command_response = $this->executeCommand(self::GENERIC_COMMAND);
} else {
//execute() method is executed after preExecute()
//This is to prevent executing a DB query without a valid connection
if ($this->update) {
$this->last_command_response = $command_obj->setUpdate($this->update)->preExecute();
} else {
$this->last_command_response = $command_obj->preExecute();
}
}
return $this->last_command_response;
}
/**
* @deprecated
*
* @param string $command
*
* @return string
*/
protected function sanitizeCommand(string $command): string
{
return str_replace(' ', '', $this->ucWordsUnicode(str_replace('_', ' ', $command)));
}
/**
* Enable a single Admin account
*
* @param int $admin_id Single admin id
*
* @return Telegram
*/
public function enableAdmin(int $admin_id): Telegram
{
if ($admin_id <= 0) {
TelegramLog::error('Invalid value "' . $admin_id . '" for admin.');
} elseif (!in_array($admin_id, $this->admins_list, true)) {
$this->admins_list[] = $admin_id;
}
return $this;
}
/**
* Enable a list of Admin Accounts
*
* @param array $admin_ids List of admin ids
*
* @return Telegram
*/
public function enableAdmins(array $admin_ids): Telegram
{
foreach ($admin_ids as $admin_id) {
$this->enableAdmin($admin_id);
}
return $this;
}
/**
* Get list of admins
*
* @return array
*/
public function getAdminList(): array
{
return $this->admins_list;
}
/**
* Check if the passed user is an admin
*
* If no user id is passed, the current update is checked for a valid message sender.
*
* @param int|null $user_id
*
* @return bool
*/
public function isAdmin($user_id = null): bool
{
if ($user_id === null && $this->update !== null) {
//Try to figure out if the user is an admin
$update_methods = [
'getMessage',
'getEditedMessage',
'getChannelPost',
'getEditedChannelPost',
'getInlineQuery',
'getChosenInlineResult',
'getCallbackQuery',
];
foreach ($update_methods as $update_method) {
$object = call_user_func([$this->update, $update_method]);
if ($object !== null && $from = $object->getFrom()) {
$user_id = $from->getId();
break;
}
}
}
return ($user_id === null) ? false : in_array($user_id, $this->admins_list, true);
}
/**
* Check if user required the db connection
*
* @return bool
*/
public function isDbEnabled(): bool
{
return $this->mysql_enabled;
}
/**
* Add a single custom command class
*
* @param string $command_class Full command class name
*
* @return Telegram
*/
public function addCommandClass(string $command_class): Telegram
{
if (!$command_class || !class_exists($command_class)) {
$error = sprintf('Command class "%s" does not exist.', $command_class);
TelegramLog::error($error);
throw new InvalidArgumentException($error);
}
if (!is_a($command_class, Command::class, true)) {
$error = sprintf('Command class "%s" does not extend "%s".', $command_class, Command::class);
TelegramLog::error($error);
throw new InvalidArgumentException($error);
}
// Dummy object to get data from.
$command_object = new $command_class($this);
$auth = null;
$command_object->isSystemCommand() && $auth = Command::AUTH_SYSTEM;
$command_object->isAdminCommand() && $auth = Command::AUTH_ADMIN;
$command_object->isUserCommand() && $auth = Command::AUTH_USER;
if ($auth) {
$command = mb_strtolower($command_object->getName());
$this->command_classes[$auth][$command] = $command_class;
}
return $this;
}
/**
* Add multiple custom command classes
*
* @param array $command_classes List of full command class names
*
* @return Telegram
*/
public function addCommandClasses(array $command_classes): Telegram
{
foreach ($command_classes as $command_class) {
$this->addCommandClass($command_class);
}
return $this;
}
/**
* Set a single custom commands path
*
* @param string $path Custom commands path to set
*
* @return Telegram
*/
public function setCommandsPath(string $path): Telegram
{
$this->commands_paths = [];
$this->addCommandsPath($path);
return $this;
}
/**
* Add a single custom commands path
*
* @param string $path Custom commands path to add
* @param bool $before If the path should be prepended or appended to the list
*
* @return Telegram
*/
public function addCommandsPath(string $path, bool $before = true): Telegram
{
if (!is_dir($path)) {
TelegramLog::error('Commands path "' . $path . '" does not exist.');
} elseif (!in_array($path, $this->commands_paths, true)) {
if ($before) {
array_unshift($this->commands_paths, $path);
} else {
$this->commands_paths[] = $path;
}
}
return $this;
}
/**
* Set multiple custom commands paths
*
* @param array $paths Custom commands paths to add
*
* @return Telegram
*/
public function setCommandsPaths(array $paths): Telegram
{
$this->commands_paths = [];
$this->addCommandsPaths($paths);
return $this;
}
/**
* Add multiple custom commands paths
*
* @param array $paths Custom commands paths to add
* @param bool $before If the paths should be prepended or appended to the list
*
* @return Telegram
*/
public function addCommandsPaths(array $paths, bool $before = true): Telegram
{
foreach ($paths as $path) {
$this->addCommandsPath($path, $before);
}
return $this;
}
/**
* Return the list of commands paths
*
* @return array
*/
public function getCommandsPaths(): array
{
return $this->commands_paths;
}
/**
* Return the list of command classes
*
* @return array
*/
public function getCommandClasses(): array
{
return $this->command_classes;
}
/**
* Set custom upload path
*
* @param string $path Custom upload path
*
* @return Telegram
*/
public function setUploadPath(string $path): Telegram
{
$this->upload_path = $path;
return $this;
}
/**
* Get custom upload path
*
* @return string
*/
public function getUploadPath(): string
{
return $this->upload_path;
}
/**
* Set custom download path
*
* @param string $path Custom download path
*
* @return Telegram
*/
public function setDownloadPath(string $path): Telegram
{
$this->download_path = $path;
return $this;
}
/**
* Get custom download path
*
* @return string
*/
public function getDownloadPath(): string
{
return $this->download_path;
}
/**
* Set command config
*
* Provide further variables to a particular commands.
* For example you can add the channel name at the command /sendtochannel
* Or you can add the api key for external service.
*
* @param string $command
* @param array $config
*
* @return Telegram
*/