Skip to content

Commit a812b42

Browse files
committed
README and phpcs
1 parent 15aade2 commit a812b42

File tree

6 files changed

+96
-26
lines changed

6 files changed

+96
-26
lines changed

README.md

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ all sorts to bring automated interactions to the mobile platform. This
2323
Bot aims to provide a platform where one could simply write a plugin
2424
and have interactions in a matter of minutes.
2525
The Bot can:
26-
- retrive update with webhook and by getUpdate methods.
26+
- retrive update with webhook and getUpdate methods.
2727
- supports all types and methods according to Telegram API (2015 October 8).
2828
- handle commads in chat with other bots.
2929

@@ -215,12 +215,49 @@ All types implemented according to Telegram API (2015 October 8).
215215

216216
### Methods New!
217217
All methods implemented according to Telegram API (2015 October 8).
218-
TODO example to use methods
218+
###Send Photo
219+
To send a local photo provide the file path as second param:
219220

220221
```php
221-
$result = Request::sendPhoto($data,'image.jpg');
222+
$data['chat_id'] = $chat_id;
223+
$result = Request::sendPhoto($data,$this->telegram->getUploadPath().'/'.'image.jpg');
222224
```
223225

226+
If you know the file_id of a previously uploaded file, just provide it in the fist param:
227+
228+
```php
229+
$data['chat_id'] = $chat_id;
230+
$data['photo'] = $file_id;
231+
$result = Request::sendPhoto($data);
232+
```
233+
234+
*sendAudio*, *sendDocument*, *sendSticker*, *sendVideo* and *sendVoice* works in the same way.
235+
See *ImageCommand.php* for a full example.
236+
####Send Chat Action
237+
238+
```php
239+
Request::sendChatAction(['chat_id' => $chat_id, 'action' => 'typing']);
240+
```
241+
####getUserProfilePhoto
242+
Retrieve the user photo, see the *WhoamiCommand.php* for a full example.
243+
244+
####GetFile and dowloadFile
245+
Get the file path and download it, see the *WhoamiCommand.php* for a full example.
246+
247+
#### Send message to all active chats
248+
To do this you have to enable the Mysql connection.
249+
Here's an example of use:
250+
251+
```php
252+
$results = $telegram->sendToActiveChats(
253+
'sendMessage', //callback function to execute (see Request.php methods)
254+
array('text'=>'Hey! Checkout the new feature!!'), //Param to evaluate the request
255+
true, //Send to chats (group chat)
256+
true, //Send to users (single chat)
257+
null, //'yyyy-mm-dd hh:mm:ss' date range from
258+
null //'yyyy-mm-dd hh:mm:ss' date range to
259+
);
260+
```
224261

225262
## Utilis
226263
### MySQL storage (Recomended)
@@ -291,21 +328,8 @@ array('google_api_key'=>'your_google_api_key_here'));
291328
### Upload and Download directory
292329
You can overwrite the default Upload and download directory with:
293330
```php
294-
295-
```
296-
### Send message to all active chats
297-
To do this you have to enable the Mysql connection.
298-
Here's an example of use:
299-
300-
```php
301-
$results = $telegram->sendToActiveChats(
302-
'sendMessage', //callback function to execute (see Request.php methods)
303-
array('text'=>'Hey! Checkout the new feature!!'), //Param to evaluate the request
304-
true, //Send to chats (group chat)
305-
true, //Send to users (single chat)
306-
null, //'yyyy-mm-dd hh:mm:ss' date range from
307-
null //'yyyy-mm-dd hh:mm:ss' date range to
308-
);
331+
$telegram->setDownloadPath("yourpath/Download");
332+
$telegram->setUploadPath("yourpath../Upload");
309333
```
310334

311335
### Logging

src/Commands/WhoamiCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function execute()
6666
$data['chat_id'] = $chat_id;
6767
$data['reply_to_message_id'] = $message_id;
6868

69-
if ( $totalcount > 0){
69+
if ($totalcount > 0) {
7070
$photos = $UserProfilePhoto->getPhotos();
7171
//I pick the latest photo with the hight definition
7272
$photo = $photos[0][2];
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the TelegramBot package.
5+
*
6+
* (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
namespace Longman\TelegramBot\Commands;
12+
13+
use Longman\TelegramBot\Request;
14+
use Longman\TelegramBot\Command;
15+
use Longman\TelegramBot\Entities\Update;
16+
17+
class ImageCommand extends Command
18+
{
19+
protected $name = 'image';
20+
protected $description = 'Send Image';
21+
protected $usage = '/image';
22+
protected $version = '1.0.0';
23+
protected $enabled = true;
24+
protected $public = true;
25+
26+
public function execute()
27+
{
28+
$update = $this->getUpdate();
29+
$message = $this->getMessage();
30+
31+
$chat_id = $message->getChat()->getId();
32+
$text = $message->getText(true);
33+
34+
$data = array();
35+
$data['chat_id'] = $chat_id;
36+
$data['caption'] = $text;
37+
38+
39+
//$result = Request::sendDocument($data,'structure.sql');
40+
//$result = Request::sendSticker($data, $this->telegram->getUploadPath().'/'.'image.jpg');
41+
42+
$result = Request::sendPhoto($data, $this->telegram->getUploadPath().'/'.'image.jpg');
43+
return $result;
44+
}
45+
}

src/Entities/Chat.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct(array $data)
4040

4141
public function isGroupChat()
4242
{
43-
if ($this->type == 'group' || $this->id < 0 ) {
43+
if ($this->type == 'group' || $this->id < 0) {
4444
return true;
4545
} else {
4646
return false;

src/Entities/ServerResponse.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(array $data, $bot_name)
2828
if (isset($data['ok']) & isset($data['result'])) {
2929
if (is_array($data['result'])) {
3030
if ($data['ok'] & !$this->isAssoc($data['result'])) {
31-
//get update
31+
//get update
3232
foreach ($data['result'] as $update) {
3333
$this->result[] = new Update($update, $bot_name);
3434
}
@@ -40,7 +40,7 @@ public function __construct(array $data, $bot_name)
4040
//Response getFile
4141
$this->result = new File($data['result']);
4242
} else {
43-
//Response from sendMessage
43+
//Response from sendMessage
4444
$this->result = new Message($data['result'], $bot_name);
4545
}
4646
}
@@ -117,7 +117,8 @@ public function getDescription()
117117
{
118118
return $this->description;
119119
}
120-
public function printError(){
120+
public function printError()
121+
{
121122
return 'Error N: '.$this->getErrorCode().' Description: '.$this->getDescription();
122123
}
123124
}

src/Request.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,12 @@ public static function downloadFile(File $file)
178178

179179
$dirname = dirname($loc_path);
180180
if (!is_dir($dirname)) {
181-
if(!mkdir($dirname, 0755, true)) {
181+
if (!mkdir($dirname, 0755, true)) {
182182
throw new TelegramException('Directory '.$dirname.' cant be created');
183183
}
184184
}
185185
# open file to write
186-
$fp = fopen ($loc_path, 'w+');
186+
$fp = fopen($loc_path, 'w+');
187187
if ($fp === false) {
188188
throw new TelegramException('File cant be created');
189189
}
@@ -199,7 +199,7 @@ public static function downloadFile(File $file)
199199
CURLOPT_HEADER => 0,
200200
CURLOPT_BINARYTRANSFER => true,
201201
CURLOPT_CONNECTTIMEOUT => 10,
202-
CURLOPT_FILE => $fp
202+
CURLOPT_FILE => $fp
203203
);
204204

205205
curl_setopt_array($ch, $curlConfig);

0 commit comments

Comments
 (0)