Skip to content

Commit f94f06e

Browse files
committed
update documentation
1 parent d8103c3 commit f94f06e

File tree

4 files changed

+88
-40
lines changed

4 files changed

+88
-40
lines changed

README.md

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ The Bot can:
2323
- retrive update with webhook and getUpdate methods.
2424
- supports all types and methods according to Telegram API (2015 October 28).
2525
- handle commands in chat with other bots.
26-
27-
It is ready for the channels support.
28-
26+
- manage Channel from the bot admin interface (**new!**)
2927

3028
## Instructions
3129
### Create your first bot
@@ -208,11 +206,12 @@ then run
208206
./getUpdateCLI.php
209207
```
210208
### Types
211-
All types implemented according to Telegram API (2015 October 8).
209+
All types implemented according to Telegram API (2015 October 28).
212210

213-
### Methods New!
214-
All methods implemented according to Telegram API (2015 October 8).
215-
###Send Photo
211+
### Methods
212+
All methods implemented according to Telegram API (2015 October 28).
213+
214+
####Send Photo
216215
To send a local photo provide the file path as second param:
217216

218217
```php
@@ -230,18 +229,18 @@ $result = Request::sendPhoto($data);
230229

231230
*sendAudio*, *sendDocument*, *sendSticker*, *sendVideo* and *sendVoice* works in the same way.
232231
See *ImageCommand.php* for a full example.
233-
###Send Chat Action
232+
####Send Chat Action
234233

235234
```php
236235
Request::sendChatAction(['chat_id' => $chat_id, 'action' => 'typing']);
237236
```
238-
###getUserProfilePhoto
237+
####getUserProfilePhoto
239238
Retrieve the user photo, see the *WhoamiCommand.php* for a full example.
240239

241-
###GetFile and dowloadFile
240+
####GetFile and dowloadFile
242241
Get the file path and download it, see the *WhoamiCommand.php* for a full example.
243242

244-
### Send message to all active chats
243+
#### Send message to all active chats
245244
To do this you have to enable the Mysql connection.
246245
Here's an example of use:
247246

@@ -263,8 +262,8 @@ in commands, create database and import *structure.sql* and enable
263262
Mysql support after object creation and BEFORE handle method:
264263

265264
```php
266-
$credentials = array('host'=>'localhost', 'user'=>'dbuser',
267-
'password'=>'dbpass', 'database'=>'dbname');
265+
$credentials = ['host'=>'localhost', 'user'=>'dbuser',
266+
'password'=>'dbpass', 'database'=>'dbname'];
268267

269268
$telegram->enableMySQL($credentials);
270269
```
@@ -273,6 +272,11 @@ You can set a custom prefix to all the tables while you are enabling Mysql:
273272
```php
274273
$telegram->enableMySQL($credentials, $BOT_NAME.'_');
275274
```
275+
Consider to use the utf8mb4 branch if you find some special characters problems.
276+
277+
### Channels Support
278+
All methods implemented can be used to manage channels.
279+
(**new!**) With admin interface you can manage your channel directly with your bot private chat.
276280

277281
### Commands
278282
The bot is able to recognise commands in chat with multiple bot (/command@mybot ).
@@ -301,11 +305,19 @@ $telegram->addCommandsPath($COMMANDS_FOLDER);
301305

302306
Inside *examples/Commands/* there are some sample that show how to use types.
303307

308+
#### Commands Configuration
309+
With this method you can set some command specified parameters, for
310+
example, google geocode/timezone api key for date command:
311+
```php
312+
$telegram->setCommandConfig('date',
313+
['google_api_key'=>'your_google_api_key_here']);
314+
```
315+
304316
### Admin Commands
305317
Enabling this feature, the admin bot can perform some super user command like:
306318
- Send message to all chats */sendtoall*
307319
- List all the chats started with the bot */chats*
308-
320+
- Send a message to a channel */sendtochannel* (NEW! see below how to configure it)
309321
You can specify one or more admin with this option:
310322

311323
```php
@@ -315,21 +327,25 @@ Telegram user id can be retrieved with the command **/whoami**.
315327
Admin commands are stored in *src/Admin/* folder.
316328
To know all the commands avaiable type **/help**.
317329

318-
### Commands Configuration
319-
With this method you can set some command specified parameters, for
320-
example, google geocode/timezone api key for date command:
330+
#### Channel Administration (NEW!)
331+
Follow those steps:
332+
- Add your bot as channel administrator, this can be done with any telegram client.
333+
- Enable admin interface for your user as explained in the admin section above.
334+
- Enter your channel name as a param for the sendtoall command:
321335
```php
322-
$telegram->setCommandConfig('date',
323-
array('google_api_key'=>'your_google_api_key_here'));
336+
$telegram->setCommandConfig('sendtochannel', ['your_channel'=>'@type_here_your_channel']);
324337
```
325-
### Upload and Download directory
338+
- Enjoy!
339+
340+
### Upload and Download directory path
326341
You can overwrite the default Upload and Download directory with:
327342
```php
328343
$telegram->setDownloadPath("yourpath/Download");
329344
$telegram->setUploadPath("yourpath../Upload");
330345
```
331346
###Unset Webhook
332347
Edit *example/unset.php* with your credential and execute it.
348+
333349
### Logging
334350
Thrown Exception are stored in *TelegramException.log* file (in the base directory).
335351

examples/getUpdatesCLI.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/usr/bin/env php
22
<?php
3+
//README
4+
//This configuration file is intented to run the bot with the webhook method
5+
//Uncommented parameters must be filled
6+
37
#bash script
48
#while true; do ./getUpdatesCLI.php; done
59

@@ -10,28 +14,38 @@
1014
$API_KEY = 'your_bot_api_key';
1115
$BOT_NAME = 'namebot';
1216
//$COMMANDS_FOLDER = __DIR__.'/Commands/';
13-
$credentials = array(
17+
$credentials = [
1418
'host'=>'localhost',
1519
'user'=>'dbuser',
1620
'password'=>'dbpass',
1721
'database'=>'dbname'
18-
);
22+
];
1923

2024
try {
2125
// create Telegram API object
2226
$telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);
2327

24-
//Options
25-
28+
////Options
2629
$telegram->enableMySQL($credentials);
30+
31+
////Enable mysql with table prefix
2732
//$telegram->enableMySQL($credentials, $BOT_NAME.'_');
33+
2834
//$telegram->addCommandsPath($COMMANDS_FOLDER);
29-
//here you can set some command specified parameters,
30-
//for example, google geocode/timezone api key for date command:
35+
36+
////Here you can enable admin interface ache the channel you want to manage
37+
//$telegram->enableAdmins(['your_telegram_id']);
38+
//$telegram->setCommandConfig('sendtochannel', ['your_channel'=>'@type_here_your_channel']);
39+
40+
////Here you can set some command specified parameters,
41+
////for example, google geocode/timezone api key for date command:
3142
//$telegram->setCommandConfig('date', array('google_api_key'=>'your_google_api_key_here'));
43+
44+
////Logging
3245
//$telegram->setLogRequests(true);
3346
//$telegram->setLogPath($BOT_NAME.'.log');
3447
//$telegram->setLogVerbosity(3);
48+
3549
//$telegram->setDownloadPath("../Download");
3650
//$telegram->setUploadPath("../Upload");
3751

examples/hook.php

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,57 @@
11
<?php
2+
//README
3+
//This configuration file is intented to run the bot with the webhook method.
4+
//Uncommented parameters must be filled
5+
//Please notice that if you open this file with your browser you'll get the "Input is empty!" Exception.
6+
//This is a normal behaviour because this address has to be reached only by Telegram server
7+
28
//Composer Loader
39
$dir = realpath(__DIR__.'/..');
410
$loader = require $dir.'/vendor/autoload.php';
511

612
$API_KEY = 'your_bot_api_key';
713
$BOT_NAME = 'namebot';
814
//$COMMANDS_FOLDER = __DIR__.'/Commands/';
9-
/*$credentials = array(
10-
'host'=>'localhost',
11-
'user'=>'dbuser',
12-
'password'=>'dbpass',
13-
'database'=>'dbname'
14-
);*/
15+
//$credentials = [
16+
// 'host'=>'localhost',
17+
// 'user'=>'dbuser',
18+
// 'password'=>'dbpass',
19+
// 'database'=>'dbname'
20+
//];
1521

1622
try {
1723
// create Telegram API object
1824
$telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);
1925

20-
//Options
21-
22-
//$telegram->enableMySQL($credentials);
26+
////Options
27+
$telegram->enableMySQL($credentials);
28+
29+
////Enable mysql with table prefix
2330
//$telegram->enableMySQL($credentials, $BOT_NAME.'_');
31+
2432
//$telegram->addCommandsPath($COMMANDS_FOLDER);
25-
// here you can set some command specified parameters,
26-
// for example, google geocode/timezone api key for date command:
33+
34+
////Here you can enable admin interface ache the channel you want to manage
35+
//$telegram->enableAdmins(['your_telegram_id']);
36+
//$telegram->setCommandConfig('sendtochannel', ['your_channel'=>'@type_here_your_channel']);
37+
38+
////Here you can set some command specified parameters,
39+
////for example, google geocode/timezone api key for date command:
2740
//$telegram->setCommandConfig('date', array('google_api_key'=>'your_google_api_key_here'));
41+
42+
////Logging
2843
//$telegram->setLogRequests(true);
2944
//$telegram->setLogPath($BOT_NAME.'.log');
30-
//$telegram->setLogVerbosity(4);
45+
//$telegram->setLogVerbosity(3);
3146

3247
//$telegram->setDownloadPath("../Download");
3348
//$telegram->setUploadPath("../Upload");
49+
3450
// handle telegram webhook request
3551
$telegram->handle();
52+
3653
} catch (Longman\TelegramBot\Exception\TelegramException $e) {
54+
//Silence is gold!
3755
// log telegram errors
3856
// echo $e;
3957
}

src/Admin/SendtochannelCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
class SendtochannelCommand extends Command
2020
{
2121
protected $name = 'sendtochannel';
22-
protected $description = 'Send a message to a channel';
22+
protected $description = 'Send message to a channel';
2323
protected $usage = '/sendchannel <message to send>';
2424
protected $version = '0.1.0';
2525
protected $enabled = true;
@@ -35,10 +35,10 @@ public function execute()
3535
$chat_id = $message->getChat()->getId();
3636
$message_id = $message->getMessageId();
3737
$text = $message->getText(true);
38-
$your_channel = '@yourchannel';
3938
if (empty($text)) {
4039
$text_back = 'Write the message to sent: /sendtochannel <message>';
4140
} else {
41+
$your_channel = $this->getConfig('your_channel');
4242
//Send message to channel
4343
$data = [];
4444
$data['chat_id'] = $your_channel;

0 commit comments

Comments
 (0)