Commit a812b42e authored by MBoretto's avatar MBoretto

README and phpcs

parent 15aade22
...@@ -23,7 +23,7 @@ all sorts to bring automated interactions to the mobile platform. This ...@@ -23,7 +23,7 @@ all sorts to bring automated interactions to the mobile platform. This
Bot aims to provide a platform where one could simply write a plugin Bot aims to provide a platform where one could simply write a plugin
and have interactions in a matter of minutes. and have interactions in a matter of minutes.
The Bot can: The Bot can:
- retrive update with webhook and by getUpdate methods. - retrive update with webhook and getUpdate methods.
- supports all types and methods according to Telegram API (2015 October 8). - supports all types and methods according to Telegram API (2015 October 8).
- handle commads in chat with other bots. - handle commads in chat with other bots.
...@@ -215,12 +215,49 @@ All types implemented according to Telegram API (2015 October 8). ...@@ -215,12 +215,49 @@ All types implemented according to Telegram API (2015 October 8).
### Methods New! ### Methods New!
All methods implemented according to Telegram API (2015 October 8). All methods implemented according to Telegram API (2015 October 8).
TODO example to use methods ###Send Photo
To send a local photo provide the file path as second param:
```php ```php
$result = Request::sendPhoto($data,'image.jpg'); $data['chat_id'] = $chat_id;
$result = Request::sendPhoto($data,$this->telegram->getUploadPath().'/'.'image.jpg');
``` ```
If you know the file_id of a previously uploaded file, just provide it in the fist param:
```php
$data['chat_id'] = $chat_id;
$data['photo'] = $file_id;
$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
```php
Request::sendChatAction(['chat_id' => $chat_id, 'action' => 'typing']);
```
####getUserProfilePhoto
Retrieve the user photo, see the *WhoamiCommand.php* for a full example.
####GetFile and dowloadFile
Get the file path and download it, see the *WhoamiCommand.php* for a full example.
#### Send message to all active chats
To do this you have to enable the Mysql connection.
Here's an example of use:
```php
$results = $telegram->sendToActiveChats(
'sendMessage', //callback function to execute (see Request.php methods)
array('text'=>'Hey! Checkout the new feature!!'), //Param to evaluate the request
true, //Send to chats (group chat)
true, //Send to users (single chat)
null, //'yyyy-mm-dd hh:mm:ss' date range from
null //'yyyy-mm-dd hh:mm:ss' date range to
);
```
## Utilis ## Utilis
### MySQL storage (Recomended) ### MySQL storage (Recomended)
...@@ -291,21 +328,8 @@ array('google_api_key'=>'your_google_api_key_here')); ...@@ -291,21 +328,8 @@ array('google_api_key'=>'your_google_api_key_here'));
### Upload and Download directory ### Upload and Download directory
You can overwrite the default Upload and download directory with: You can overwrite the default Upload and download directory with:
```php ```php
$telegram->setDownloadPath("yourpath/Download");
``` $telegram->setUploadPath("yourpath../Upload");
### Send message to all active chats
To do this you have to enable the Mysql connection.
Here's an example of use:
```php
$results = $telegram->sendToActiveChats(
'sendMessage', //callback function to execute (see Request.php methods)
array('text'=>'Hey! Checkout the new feature!!'), //Param to evaluate the request
true, //Send to chats (group chat)
true, //Send to users (single chat)
null, //'yyyy-mm-dd hh:mm:ss' date range from
null //'yyyy-mm-dd hh:mm:ss' date range to
);
``` ```
### Logging ### Logging
......
...@@ -66,7 +66,7 @@ class WhoamiCommand extends Command ...@@ -66,7 +66,7 @@ class WhoamiCommand extends Command
$data['chat_id'] = $chat_id; $data['chat_id'] = $chat_id;
$data['reply_to_message_id'] = $message_id; $data['reply_to_message_id'] = $message_id;
if ( $totalcount > 0){ if ($totalcount > 0) {
$photos = $UserProfilePhoto->getPhotos(); $photos = $UserProfilePhoto->getPhotos();
//I pick the latest photo with the hight definition //I pick the latest photo with the hight definition
$photo = $photos[0][2]; $photo = $photos[0][2];
......
<?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\Commands;
use Longman\TelegramBot\Request;
use Longman\TelegramBot\Command;
use Longman\TelegramBot\Entities\Update;
class ImageCommand extends Command
{
protected $name = 'image';
protected $description = 'Send Image';
protected $usage = '/image';
protected $version = '1.0.0';
protected $enabled = true;
protected $public = true;
public function execute()
{
$update = $this->getUpdate();
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$text = $message->getText(true);
$data = array();
$data['chat_id'] = $chat_id;
$data['caption'] = $text;
//$result = Request::sendDocument($data,'structure.sql');
//$result = Request::sendSticker($data, $this->telegram->getUploadPath().'/'.'image.jpg');
$result = Request::sendPhoto($data, $this->telegram->getUploadPath().'/'.'image.jpg');
return $result;
}
}
...@@ -40,7 +40,7 @@ class Chat extends Entity ...@@ -40,7 +40,7 @@ class Chat extends Entity
public function isGroupChat() public function isGroupChat()
{ {
if ($this->type == 'group' || $this->id < 0 ) { if ($this->type == 'group' || $this->id < 0) {
return true; return true;
} else { } else {
return false; return false;
......
...@@ -117,7 +117,8 @@ class ServerResponse extends Entity ...@@ -117,7 +117,8 @@ class ServerResponse extends Entity
{ {
return $this->description; return $this->description;
} }
public function printError(){ public function printError()
{
return 'Error N: '.$this->getErrorCode().' Description: '.$this->getDescription(); return 'Error N: '.$this->getErrorCode().' Description: '.$this->getDescription();
} }
} }
...@@ -178,12 +178,12 @@ class Request ...@@ -178,12 +178,12 @@ class Request
$dirname = dirname($loc_path); $dirname = dirname($loc_path);
if (!is_dir($dirname)) { if (!is_dir($dirname)) {
if(!mkdir($dirname, 0755, true)) { if (!mkdir($dirname, 0755, true)) {
throw new TelegramException('Directory '.$dirname.' cant be created'); throw new TelegramException('Directory '.$dirname.' cant be created');
} }
} }
# open file to write # open file to write
$fp = fopen ($loc_path, 'w+'); $fp = fopen($loc_path, 'w+');
if ($fp === false) { if ($fp === false) {
throw new TelegramException('File cant be created'); throw new TelegramException('File cant be created');
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment