Skip to content

Commit

Permalink
update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
MBoretto committed Dec 20, 2015
1 parent d8103c3 commit f94f06e
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 40 deletions.
56 changes: 36 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ The Bot can:
- retrive update with webhook and getUpdate methods.
- supports all types and methods according to Telegram API (2015 October 28).
- handle commands in chat with other bots.

It is ready for the channels support.

- manage Channel from the bot admin interface (**new!**)

## Instructions
### Create your first bot
Expand Down Expand Up @@ -208,11 +206,12 @@ then run
./getUpdateCLI.php
```
### Types
All types implemented according to Telegram API (2015 October 8).
All types implemented according to Telegram API (2015 October 28).

### Methods New!
All methods implemented according to Telegram API (2015 October 8).
###Send Photo
### Methods
All methods implemented according to Telegram API (2015 October 28).

####Send Photo
To send a local photo provide the file path as second param:

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

*sendAudio*, *sendDocument*, *sendSticker*, *sendVideo* and *sendVoice* works in the same way.
See *ImageCommand.php* for a full example.
###Send Chat Action
####Send Chat Action

```php
Request::sendChatAction(['chat_id' => $chat_id, 'action' => 'typing']);
```
###getUserProfilePhoto
####getUserProfilePhoto
Retrieve the user photo, see the *WhoamiCommand.php* for a full example.

###GetFile and dowloadFile
####GetFile and dowloadFile
Get the file path and download it, see the *WhoamiCommand.php* for a full example.

### Send message to all active chats
#### Send message to all active chats
To do this you have to enable the Mysql connection.
Here's an example of use:

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

```php
$credentials = array('host'=>'localhost', 'user'=>'dbuser',
'password'=>'dbpass', 'database'=>'dbname');
$credentials = ['host'=>'localhost', 'user'=>'dbuser',
'password'=>'dbpass', 'database'=>'dbname'];

$telegram->enableMySQL($credentials);
```
Expand All @@ -273,6 +272,11 @@ You can set a custom prefix to all the tables while you are enabling Mysql:
```php
$telegram->enableMySQL($credentials, $BOT_NAME.'_');
```
Consider to use the utf8mb4 branch if you find some special characters problems.

### Channels Support
All methods implemented can be used to manage channels.
(**new!**) With admin interface you can manage your channel directly with your bot private chat.

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

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

#### Commands Configuration
With this method you can set some command specified parameters, for
example, google geocode/timezone api key for date command:
```php
$telegram->setCommandConfig('date',
['google_api_key'=>'your_google_api_key_here']);
```

### Admin Commands
Enabling this feature, the admin bot can perform some super user command like:
- Send message to all chats */sendtoall*
- List all the chats started with the bot */chats*

- Send a message to a channel */sendtochannel* (NEW! see below how to configure it)
You can specify one or more admin with this option:

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

### Commands Configuration
With this method you can set some command specified parameters, for
example, google geocode/timezone api key for date command:
#### Channel Administration (NEW!)
Follow those steps:
- Add your bot as channel administrator, this can be done with any telegram client.
- Enable admin interface for your user as explained in the admin section above.
- Enter your channel name as a param for the sendtoall command:
```php
$telegram->setCommandConfig('date',
array('google_api_key'=>'your_google_api_key_here'));
$telegram->setCommandConfig('sendtochannel', ['your_channel'=>'@type_here_your_channel']);
```
### Upload and Download directory
- Enjoy!

### Upload and Download directory path
You can overwrite the default Upload and Download directory with:
```php
$telegram->setDownloadPath("yourpath/Download");
$telegram->setUploadPath("yourpath../Upload");
```
###Unset Webhook
Edit *example/unset.php* with your credential and execute it.

### Logging
Thrown Exception are stored in *TelegramException.log* file (in the base directory).

Expand Down
26 changes: 20 additions & 6 deletions examples/getUpdatesCLI.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env php
<?php
//README
//This configuration file is intented to run the bot with the webhook method
//Uncommented parameters must be filled

#bash script
#while true; do ./getUpdatesCLI.php; done

Expand All @@ -10,28 +14,38 @@
$API_KEY = 'your_bot_api_key';
$BOT_NAME = 'namebot';
//$COMMANDS_FOLDER = __DIR__.'/Commands/';
$credentials = array(
$credentials = [
'host'=>'localhost',
'user'=>'dbuser',
'password'=>'dbpass',
'database'=>'dbname'
);
];

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

//Options

////Options
$telegram->enableMySQL($credentials);

////Enable mysql with table prefix
//$telegram->enableMySQL($credentials, $BOT_NAME.'_');

//$telegram->addCommandsPath($COMMANDS_FOLDER);
//here you can set some command specified parameters,
//for example, google geocode/timezone api key for date command:

////Here you can enable admin interface ache the channel you want to manage
//$telegram->enableAdmins(['your_telegram_id']);
//$telegram->setCommandConfig('sendtochannel', ['your_channel'=>'@type_here_your_channel']);

////Here you can set some command specified parameters,
////for example, google geocode/timezone api key for date command:
//$telegram->setCommandConfig('date', array('google_api_key'=>'your_google_api_key_here'));

////Logging
//$telegram->setLogRequests(true);
//$telegram->setLogPath($BOT_NAME.'.log');
//$telegram->setLogVerbosity(3);

//$telegram->setDownloadPath("../Download");
//$telegram->setUploadPath("../Upload");

Expand Down
42 changes: 30 additions & 12 deletions examples/hook.php
Original file line number Diff line number Diff line change
@@ -1,39 +1,57 @@
<?php
//README
//This configuration file is intented to run the bot with the webhook method.
//Uncommented parameters must be filled
//Please notice that if you open this file with your browser you'll get the "Input is empty!" Exception.
//This is a normal behaviour because this address has to be reached only by Telegram server

//Composer Loader
$dir = realpath(__DIR__.'/..');
$loader = require $dir.'/vendor/autoload.php';

$API_KEY = 'your_bot_api_key';
$BOT_NAME = 'namebot';
//$COMMANDS_FOLDER = __DIR__.'/Commands/';
/*$credentials = array(
'host'=>'localhost',
'user'=>'dbuser',
'password'=>'dbpass',
'database'=>'dbname'
);*/
//$credentials = [
// 'host'=>'localhost',
// 'user'=>'dbuser',
// 'password'=>'dbpass',
// 'database'=>'dbname'
//];

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

//Options

//$telegram->enableMySQL($credentials);
////Options
$telegram->enableMySQL($credentials);

////Enable mysql with table prefix
//$telegram->enableMySQL($credentials, $BOT_NAME.'_');

//$telegram->addCommandsPath($COMMANDS_FOLDER);
// here you can set some command specified parameters,
// for example, google geocode/timezone api key for date command:

////Here you can enable admin interface ache the channel you want to manage
//$telegram->enableAdmins(['your_telegram_id']);
//$telegram->setCommandConfig('sendtochannel', ['your_channel'=>'@type_here_your_channel']);

////Here you can set some command specified parameters,
////for example, google geocode/timezone api key for date command:
//$telegram->setCommandConfig('date', array('google_api_key'=>'your_google_api_key_here'));

////Logging
//$telegram->setLogRequests(true);
//$telegram->setLogPath($BOT_NAME.'.log');
//$telegram->setLogVerbosity(4);
//$telegram->setLogVerbosity(3);

//$telegram->setDownloadPath("../Download");
//$telegram->setUploadPath("../Upload");

// handle telegram webhook request
$telegram->handle();

} catch (Longman\TelegramBot\Exception\TelegramException $e) {
//Silence is gold!
// log telegram errors
// echo $e;
}
4 changes: 2 additions & 2 deletions src/Admin/SendtochannelCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class SendtochannelCommand extends Command
{
protected $name = 'sendtochannel';
protected $description = 'Send a message to a channel';
protected $description = 'Send message to a channel';
protected $usage = '/sendchannel <message to send>';
protected $version = '0.1.0';
protected $enabled = true;
Expand All @@ -35,10 +35,10 @@ public function execute()
$chat_id = $message->getChat()->getId();
$message_id = $message->getMessageId();
$text = $message->getText(true);
$your_channel = '@yourchannel';
if (empty($text)) {
$text_back = 'Write the message to sent: /sendtochannel <message>';
} else {
$your_channel = $this->getConfig('your_channel');
//Send message to channel
$data = [];
$data['chat_id'] = $your_channel;
Expand Down

0 comments on commit f94f06e

Please sign in to comment.