Completed
Push — master ( 83d5fd...3dcd1f )
by Saeed
01:31
created
src/Smoqadam/Keyboard/Inline.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
   /**
14 14
   * Create new row.
15 15
   *
16
-  * @return object
16
+  * @return Inline
17 17
   */
18 18
   public function addRow(){
19 19
     $this->current_row++;
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
   * @param string $switch_inline_query Optional. If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot‘s username and the specified inline query in the input field. Can be empty, in which case just the bot’s username will be inserted.
31 31
   * @param string $switch_inline_query_current_chat Optional. If set, pressing the button will insert the bot‘s username and the specified inline query in the current chat's input field. Can be empty, in which case only the bot’s username will be inserted.
32 32
   * @param string $callback_game Optional. Description of the game that will be launched when the user presses the button. NOTE: This type of button must always be the first button in the first row.
33
-  * @return object
33
+  * @return Inline
34 34
   */
35 35
   public function addButton(string $text, string $url = '', string $callback_data = '', string $switch_inline_query = '', string $switch_inline_query_current_chat = '', string $callback_game = ''){
36 36
     $btn['text'] = $text;
Please login to merge, or discard this patch.
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -5,51 +5,51 @@
 block discarded – undo
5 5
 class Inline {
6 6
 
7 7
   public
8
-    $inline_keyboard = [];
8
+	$inline_keyboard = [];
9 9
     
10 10
   private
11
-    $current_row = 0;
11
+	$current_row = 0;
12 12
   
13 13
   /**
14
-  * Create new row.
15
-  *
16
-  * @return object
17
-  */
14
+   * Create new row.
15
+   *
16
+   * @return object
17
+   */
18 18
   public function addRow(){
19
-    $this->current_row++;
19
+	$this->current_row++;
20 20
     
21
-    return $this;
21
+	return $this;
22 22
   }
23 23
   
24 24
   /**
25
-  * Add new button to current row.
26
-  *
27
-  * @param string $text Label text on the button
28
-  * @param string $url Optional. HTTP url to be opened when button is pressed
29
-  * @param string $callback_data Optional. Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes
30
-  * @param string $switch_inline_query Optional. If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot‘s username and the specified inline query in the input field. Can be empty, in which case just the bot’s username will be inserted.
31
-  * @param string $switch_inline_query_current_chat Optional. If set, pressing the button will insert the bot‘s username and the specified inline query in the current chat's input field. Can be empty, in which case only the bot’s username will be inserted.
32
-  * @param string $callback_game Optional. Description of the game that will be launched when the user presses the button. NOTE: This type of button must always be the first button in the first row.
33
-  * @return object
34
-  */
25
+   * Add new button to current row.
26
+   *
27
+   * @param string $text Label text on the button
28
+   * @param string $url Optional. HTTP url to be opened when button is pressed
29
+   * @param string $callback_data Optional. Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes
30
+   * @param string $switch_inline_query Optional. If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot‘s username and the specified inline query in the input field. Can be empty, in which case just the bot’s username will be inserted.
31
+   * @param string $switch_inline_query_current_chat Optional. If set, pressing the button will insert the bot‘s username and the specified inline query in the current chat's input field. Can be empty, in which case only the bot’s username will be inserted.
32
+   * @param string $callback_game Optional. Description of the game that will be launched when the user presses the button. NOTE: This type of button must always be the first button in the first row.
33
+   * @return object
34
+   */
35 35
   public function addButton(string $text, string $url = '', string $callback_data = '', string $switch_inline_query = '', string $switch_inline_query_current_chat = '', string $callback_game = ''){
36
-    $btn['text'] = $text;
37
-    if($url != '')
38
-      $btn['url'] = $url;
39
-    elseif($callback_data != '')
40
-      $btn['callback_data'] = $callback_data;
41
-    elseif($switch_inline_query != '')
42
-     $btn['switch_inline_query'] = $switch_inline_query;
43
-    elseif($switch_inline_query_current_chat != '')
44
-      $btn['switch_inline_query_current_chat'] = $switch_inline_query_current_chat;
45
-    elseif($callback_game != '')
46
-      $btn['callback_game'] = $callback_game;
47
-    else
48
-      $btn['callback_data'] = $text;
36
+	$btn['text'] = $text;
37
+	if($url != '')
38
+	  $btn['url'] = $url;
39
+	elseif($callback_data != '')
40
+	  $btn['callback_data'] = $callback_data;
41
+	elseif($switch_inline_query != '')
42
+	 $btn['switch_inline_query'] = $switch_inline_query;
43
+	elseif($switch_inline_query_current_chat != '')
44
+	  $btn['switch_inline_query_current_chat'] = $switch_inline_query_current_chat;
45
+	elseif($callback_game != '')
46
+	  $btn['callback_game'] = $callback_game;
47
+	else
48
+	  $btn['callback_data'] = $text;
49 49
       
50
-    $this->inline_keyboard[$this->current_row][] = $btn;
50
+	$this->inline_keyboard[$this->current_row][] = $btn;
51 51
     
52
-    return $this;
52
+	return $this;
53 53
   }
54 54
 
55 55
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
   *
16 16
   * @return object
17 17
   */
18
-  public function addRow(){
18
+  public function addRow() {
19 19
     $this->current_row++;
20 20
     
21 21
     return $this;
@@ -32,17 +32,17 @@  discard block
 block discarded – undo
32 32
   * @param string $callback_game Optional. Description of the game that will be launched when the user presses the button. NOTE: This type of button must always be the first button in the first row.
33 33
   * @return object
34 34
   */
35
-  public function addButton(string $text, string $url = '', string $callback_data = '', string $switch_inline_query = '', string $switch_inline_query_current_chat = '', string $callback_game = ''){
35
+  public function addButton(string $text, string $url = '', string $callback_data = '', string $switch_inline_query = '', string $switch_inline_query_current_chat = '', string $callback_game = '') {
36 36
     $btn['text'] = $text;
37
-    if($url != '')
37
+    if ($url != '')
38 38
       $btn['url'] = $url;
39
-    elseif($callback_data != '')
39
+    elseif ($callback_data != '')
40 40
       $btn['callback_data'] = $callback_data;
41
-    elseif($switch_inline_query != '')
41
+    elseif ($switch_inline_query != '')
42 42
      $btn['switch_inline_query'] = $switch_inline_query;
43
-    elseif($switch_inline_query_current_chat != '')
43
+    elseif ($switch_inline_query_current_chat != '')
44 44
       $btn['switch_inline_query_current_chat'] = $switch_inline_query_current_chat;
45
-    elseif($callback_game != '')
45
+    elseif ($callback_game != '')
46 46
       $btn['callback_game'] = $callback_game;
47 47
     else
48 48
       $btn['callback_data'] = $text;
Please login to merge, or discard this patch.
Braces   +13 added lines, -12 removed lines patch added patch discarded remove patch
@@ -34,18 +34,19 @@
 block discarded – undo
34 34
   */
35 35
   public function addButton(string $text, string $url = '', string $callback_data = '', string $switch_inline_query = '', string $switch_inline_query_current_chat = '', string $callback_game = ''){
36 36
     $btn['text'] = $text;
37
-    if($url != '')
38
-      $btn['url'] = $url;
39
-    elseif($callback_data != '')
40
-      $btn['callback_data'] = $callback_data;
41
-    elseif($switch_inline_query != '')
42
-     $btn['switch_inline_query'] = $switch_inline_query;
43
-    elseif($switch_inline_query_current_chat != '')
44
-      $btn['switch_inline_query_current_chat'] = $switch_inline_query_current_chat;
45
-    elseif($callback_game != '')
46
-      $btn['callback_game'] = $callback_game;
47
-    else
48
-      $btn['callback_data'] = $text;
37
+    if($url != '') {
38
+          $btn['url'] = $url;
39
+    } elseif($callback_data != '') {
40
+          $btn['callback_data'] = $callback_data;
41
+    } elseif($switch_inline_query != '') {
42
+         $btn['switch_inline_query'] = $switch_inline_query;
43
+    } elseif($switch_inline_query_current_chat != '') {
44
+          $btn['switch_inline_query_current_chat'] = $switch_inline_query_current_chat;
45
+    } elseif($callback_game != '') {
46
+          $btn['callback_game'] = $callback_game;
47
+    } else {
48
+          $btn['callback_data'] = $text;
49
+    }
49 50
       
50 51
     $this->inline_keyboard[$this->current_row][] = $btn;
51 52
     
Please login to merge, or discard this patch.
src/Smoqadam/Telegram.php 4 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 
220 220
     /**
221 221
      * execute telegram api commands
222
-     * @param $command
222
+     * @param string $command
223 223
      * @param array $params
224 224
      */
225 225
     private function exec($command, $params = []) {
@@ -254,9 +254,9 @@  discard block
 block discarded – undo
254 254
 
255 255
     /**
256 256
      * get the $url content with CURL
257
-     * @param $url
257
+     * @param string $url
258 258
      * @param $params
259
-     * @return mixed
259
+     * @return string
260 260
      */
261 261
     private function curl_get_contents($url, $params) {
262 262
         $ch = curl_init();
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
     }
299 299
 
300 300
     /**
301
-     * @param null $offset
301
+     * @param integer $offset
302 302
      * @param int $limit
303 303
      * @param int $timeout
304 304
      */
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
 
454 454
     /**
455 455
      * send chat action : Telegram::ACTION_TYPING , ...
456
-     * @param $action
456
+     * @param string $action
457 457
      * @param null $chat_id
458 458
      */
459 459
     public function sendChatAction($action, $chat_id = null) {
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -105,11 +105,11 @@  discard block
 block discarded – undo
105 105
     }
106 106
 
107 107
 
108
-    public function PDO(){
108
+    public function PDO() {
109 109
 
110
-        $servername ='YOUR_SERVER_NAME';
110
+        $servername = 'YOUR_SERVER_NAME';
111 111
         $username = 'YOUR_USERNAME';
112
-        $password ='YOUR_PASSWORD';
112
+        $password = 'YOUR_PASSWORD';
113 113
         $dbname = 'YOUR_DATABASE_NAME';
114 114
         try {
115 115
             $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password, [PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"]);
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 
118 118
             return $conn;
119 119
         }
120
-        catch(PDOException $e)
120
+        catch (PDOException $e)
121 121
         {
122 122
             return $e->getMessage();
123 123
         }
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
         $result = $this->getUpdates();
143 143
         while (true) {
144 144
             $update_id = isset($result->update_id) ? $result->update_id : 1;
145
-            $result = $this->getUpdates($update_id + 1);
145
+            $result = $this->getUpdates($update_id+1);
146 146
 
147 147
             $this->processPayload($result);
148 148
 
@@ -166,13 +166,13 @@  discard block
 block discarded – undo
166 166
                 $this->result = $result;
167 167
 
168 168
                 // now i select the right triggers for payload received by Telegram
169
-                if( isset($this->result->message->text) ) {
169
+                if (isset($this->result->message->text)) {
170 170
                     $payload = $this->result->message->text;
171 171
                     $triggers = $this->commands;
172
-                } elseif ( isset($this->result->inline_query) ) {
172
+                } elseif (isset($this->result->inline_query)) {
173 173
                     $payload = $this->result->inline_query->query;
174 174
                     $triggers = $this->inlines;
175
-                } else {
175
+                }else {
176 176
                     throw new \Exception("Error Processing Request", 1);
177 177
                 }
178 178
 
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
                     //find args pattern
188 188
                     $args = $this->getArgs($pattern, $payload);
189 189
 
190
-                    $pattern = '/^' . $pattern . '/i';
190
+                    $pattern = '/^'.$pattern.'/i';
191 191
 
192 192
                     preg_match($pattern, $payload, $matches);
193 193
 
@@ -196,11 +196,11 @@  discard block
 block discarded – undo
196 196
                         return call_user_func($func, $args);
197 197
                     }
198 198
                 }
199
-            } catch (\Exception $e) {
199
+            }catch (\Exception $e) {
200 200
                 error_log($e->getMessage());
201
-                echo "\r\n Exception :: " . $e->getMessage();
201
+                echo "\r\n Exception :: ".$e->getMessage();
202 202
             }
203
-        } else {
203
+        }else {
204 204
             echo "\r\nNo new message\r\n";
205 205
         }
206 206
     }
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
             $tmp_args_pattern = str_replace(['<<', '>>'], ['(', ')'], $pattern);
222 222
 
223 223
             //if args set
224
-            if (preg_match('/' . $tmp_args_pattern . '/i', $payload, $matches)) {
224
+            if (preg_match('/'.$tmp_args_pattern.'/i', $payload, $matches)) {
225 225
                 //remove first element
226 226
                 array_shift($matches);
227 227
                 if (isset($matches[0])) {
@@ -244,16 +244,16 @@  discard block
 block discarded – undo
244 244
     private function exec($command, $params = []) {
245 245
         if (in_array($command, $this->available_commands)) {
246 246
             // convert json to array then get the last messages info
247
-            $output = json_decode($this->curl_get_contents($this->api . '/' . $command, $params), true);
247
+            $output = json_decode($this->curl_get_contents($this->api.'/'.$command, $params), true);
248 248
 
249 249
             return $this->convertToObject($output);
250
-        } else {
250
+        }else {
251 251
             echo 'command not found';
252 252
         }
253 253
     }
254 254
 
255
-    private function convertToObject($jsonObject , $webhook = false) {
256
-        if( ! $webhook) {
255
+    private function convertToObject($jsonObject, $webhook = false) {
256
+        if (!$webhook) {
257 257
             if ($jsonObject['ok']) {
258 258
                 //error_log(print_r($jsonObject, true));
259 259
 
@@ -261,12 +261,12 @@  discard block
 block discarded – undo
261 261
                 $output = end($jsonObject);
262 262
 
263 263
                 $result = is_array($output) ? end($output) : $output;
264
-                if ( ! empty($result)) {
264
+                if (!empty($result)) {
265 265
                     // convert to object
266 266
                     return json_decode(json_encode($result));
267 267
                 }
268 268
             }
269
-        } else {
269
+        }else {
270 270
             return json_decode(json_encode($jsonObject));
271 271
         }
272 272
     }
@@ -304,14 +304,14 @@  discard block
 block discarded – undo
304 304
             if ($chat_id)
305 305
                 return $chat_id;
306 306
 
307
-            if( isset($this->result->message) ) {
307
+            if (isset($this->result->message)) {
308 308
                 return $this->result->message->chat->id;
309
-            } elseif ( isset($this->result->inline_query) ) {
309
+            } elseif (isset($this->result->inline_query)) {
310 310
                 return $this->result->inline_query->from->id;
311
-            } else {
311
+            }else {
312 312
                 throw new \Exception("Error Processing Request", 1);
313 313
             }
314
-        } catch (\Exception $e) {
314
+        }catch (\Exception $e) {
315 315
             error_log($e->getMessage());
316 316
         }
317 317
     }
Please login to merge, or discard this patch.
Braces   +7 added lines, -6 removed lines patch added patch discarded remove patch
@@ -116,8 +116,7 @@  discard block
 block discarded – undo
116 116
             $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
117 117
 
118 118
             return $conn;
119
-        }
120
-        catch(PDOException $e)
119
+        } catch(PDOException $e)
121 120
         {
122 121
             return $e->getMessage();
123 122
         }
@@ -146,8 +145,9 @@  discard block
 block discarded – undo
146 145
 
147 146
             $this->processPayload($result);
148 147
 
149
-            if ($sleep !== false)
150
-                sleep($sleep);
148
+            if ($sleep !== false) {
149
+                            sleep($sleep);
150
+            }
151 151
         }
152 152
     }
153 153
 
@@ -301,8 +301,9 @@  discard block
 block discarded – undo
301 301
      */
302 302
     public function getChatId($chat_id = null) {
303 303
         try {
304
-            if ($chat_id)
305
-                return $chat_id;
304
+            if ($chat_id) {
305
+                            return $chat_id;
306
+            }
306 307
 
307 308
             if( isset($this->result->message) ) {
308 309
                 return $this->result->message->chat->id;
Please login to merge, or discard this patch.
Indentation   +515 added lines, -515 removed lines patch added patch discarded remove patch
@@ -11,520 +11,520 @@
 block discarded – undo
11 11
 
12 12
 class Telegram {
13 13
 
14
-    const PARSE_MARKDOWN = 'Markdown';
15
-    const PARSE_HTML     = 'HTML';
16
-
17
-    const ACTION_TYPING         = 'typing';
18
-    const ACTION_UPLOAD_PHOTO   = 'upload_photo';
19
-    const ACTION_RECORD_VIDEO   = 'record_video';
20
-    const ACTION_UPLOAD_VIDEO   = 'upload_video';
21
-    const ACTION_RECORD_AUDIO   = 'record_audio';
22
-    const ACTION_UPLOAD_AUDIO   = 'upload_audio';
23
-    const ACTION_UPLOAD_DOC     = 'upload_document';
24
-    const ACTION_FIND_LOCATION  = 'find_location';
25
-
26
-    public $api = 'https://api.telegram.org/bot';
27
-
28
-    /**
29
-     * returned json from telegram api parse to object and save to result
30
-     * @var
31
-     */
32
-    public $result;
33
-
34
-    /**
35
-     * @name State of bot
36
-     * state of bot
37
-     * @var object
38
-     */
39
-    public $state;
40
-
41
-    /**
42
-     * commands in regex and callback
43
-     * @var array
44
-     */
45
-    private $commands = [];
46
-
47
-    /**
48
-     * InlineQuery in regex and callback
49
-     * @var array
50
-     */
51
-    private $inlines = [];
52
-
53
-    /**
54
-     * callbacks
55
-     * @var array
56
-     */
57
-    private $callbacks = [];
58
-
59
-    /**
60
-     * available telegram bot commands
61
-     * @var array
62
-     */
63
-    private $available_commands = [
64
-        'getMe',
65
-        'sendMessage',
66
-        'forwardMessage',
67
-        'sendPhoto',
68
-        'sendAudio',
69
-        'sendDocument',
70
-        'sendSticker',
71
-        'sendVideo',
72
-        'sendLocation',
73
-        'sendChatAction',
74
-        'getUserProfilePhotos',
75
-        'answerInlineQuery',
76
-        'getUpdates',
77
-        'setWebhook',
78
-    ];
79
-
80
-    /**
81
-     * pre patterns you can use in regex
82
-     * @var array
83
-     */
84
-    private $patterns = [
85
-        ':any' => '.*',
86
-        ':num' => '[0-9]{0,}',
87
-        ':str' => '[a-zA-z]{0,}',
88
-    ];
89
-
90
-    /**
91
-     *
92
-     * @param String $token Telegram api token , taken by botfather
93
-     */
94
-    public function __construct($token) {
95
-        $this->api .= $token;
96
-    }
97
-
98
-    /**
99
-     * add new command to the bot
100
-     * @param String $cmd
101
-     * @param \Closure $func
102
-     */
103
-    public function cmd($cmd, $func) {
104
-        $this->commands[] = new Trigger($cmd, $func);
105
-    }
106
-
107
-
108
-    public function PDO(){
109
-
110
-        $servername ='YOUR_SERVER_NAME';
111
-        $username = 'YOUR_USERNAME';
112
-        $password ='YOUR_PASSWORD';
113
-        $dbname = 'YOUR_DATABASE_NAME';
114
-        try {
115
-            $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password, [PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"]);
116
-            $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
117
-
118
-            return $conn;
119
-        }
120
-        catch(PDOException $e)
121
-        {
122
-            return $e->getMessage();
123
-        }
124
-    }
125
-
126
-    /**
127
-     * add new InlineQuery to the bot
128
-     * @param String $cmd
129
-     * @param \Closure $func
130
-     */
131
-    public function inlineQuery($cmd, $func) {
132
-        $this->inlines[] = new Trigger($cmd, $func);
133
-    }
134
-
135
-    /**
136
-     * this method check for received payload(command, inlinequery and so on) and
137
-     * then execute the correct function
138
-     *
139
-     * @param bool $sleep
140
-     */
141
-    public function run($sleep = false) {
142
-        $result = $this->getUpdates();
143
-        while (true) {
144
-            $update_id = isset($result->update_id) ? $result->update_id : 1;
145
-            $result = $this->getUpdates($update_id + 1);
146
-
147
-            $this->processPayload($result);
148
-
149
-            if ($sleep !== false)
150
-                sleep($sleep);
151
-        }
152
-    }
153
-
154
-    /**
155
-     * this method used for setWebhook sended payload
156
-     */
157
-    public function process($payload) {
158
-        $result = $this->convertToObject($payload, true);
159
-
160
-        return $this->processPayload($result);
161
-    }
162
-
163
-    private function processPayload($result) {
164
-        if ($result) {
165
-            try {
166
-                $this->result = $result;
167
-
168
-                // now i select the right triggers for payload received by Telegram
169
-                if( isset($this->result->message->text) ) {
170
-                    $payload = $this->result->message->text;
171
-                    $triggers = $this->commands;
172
-                } elseif ( isset($this->result->inline_query) ) {
173
-                    $payload = $this->result->inline_query->query;
174
-                    $triggers = $this->inlines;
175
-                } else {
176
-                    throw new \Exception("Error Processing Request", 1);
177
-                }
178
-
179
-                $args = null;
180
-
181
-                foreach ($triggers as &$trigger) {
182
-                    // replace public patterns to regex pattern
183
-                    $searchs = array_keys($this->patterns);
184
-                    $replaces = array_values($this->patterns);
185
-                    $pattern = str_replace($searchs, $replaces, $trigger->pattern);
186
-
187
-                    //find args pattern
188
-                    $args = $this->getArgs($pattern, $payload);
189
-
190
-                    $pattern = '/^' . $pattern . '/i';
191
-
192
-                    preg_match($pattern, $payload, $matches);
193
-
194
-                    if (isset($matches[0])) {
195
-                        $func = $trigger->callback;
196
-                        return call_user_func($func, $args);
197
-                    }
198
-                }
199
-            } catch (\Exception $e) {
200
-                error_log($e->getMessage());
201
-                echo "\r\n Exception :: " . $e->getMessage();
202
-            }
203
-        } else {
204
-            echo "\r\nNo new message\r\n";
205
-        }
206
-    }
207
-
208
-    /**
209
-     * get arguments part in regex
210
-     * @param $pattern
211
-     * @param $payload
212
-     * @return mixed|null
213
-     */
214
-    private function getArgs(&$pattern, $payload) {
215
-        $args = null;
216
-        // if command has argument
217
-        if (preg_match('/<<.*>>/', $pattern, $matches)) {
218
-
219
-            $args_pattern = $matches[0];
220
-            //remove << and >> from patterns
221
-            $tmp_args_pattern = str_replace(['<<', '>>'], ['(', ')'], $pattern);
222
-
223
-            //if args set
224
-            if (preg_match('/' . $tmp_args_pattern . '/i', $payload, $matches)) {
225
-                //remove first element
226
-                array_shift($matches);
227
-                if (isset($matches[0])) {
228
-                    //set args
229
-                    $args = array_shift($matches);
230
-
231
-                    //remove args pattern from main pattern
232
-                    $pattern = str_replace($args_pattern, '', $pattern);
233
-                }
234
-            }
235
-        }
236
-        return $args;
237
-    }
238
-
239
-    /**
240
-     * execute telegram api commands
241
-     * @param $command
242
-     * @param array $params
243
-     */
244
-    private function exec($command, $params = []) {
245
-        if (in_array($command, $this->available_commands)) {
246
-            // convert json to array then get the last messages info
247
-            $output = json_decode($this->curl_get_contents($this->api . '/' . $command, $params), true);
248
-
249
-            return $this->convertToObject($output);
250
-        } else {
251
-            echo 'command not found';
252
-        }
253
-    }
254
-
255
-    private function convertToObject($jsonObject , $webhook = false) {
256
-        if( ! $webhook) {
257
-            if ($jsonObject['ok']) {
258
-                //error_log(print_r($jsonObject, true));
259
-
260
-                // remove unwanted array elements
261
-                $output = end($jsonObject);
262
-
263
-                $result = is_array($output) ? end($output) : $output;
264
-                if ( ! empty($result)) {
265
-                    // convert to object
266
-                    return json_decode(json_encode($result));
267
-                }
268
-            }
269
-        } else {
270
-            return json_decode(json_encode($jsonObject));
271
-        }
272
-    }
273
-
274
-    /**
275
-     * get the $url content with CURL
276
-     * @param $url
277
-     * @param $params
278
-     * @return mixed
279
-     */
280
-    private function curl_get_contents($url, $params) {
281
-        $ch = curl_init();
282
-
283
-        curl_setopt($ch, CURLOPT_URL, $url);
284
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
285
-        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
286
-        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
287
-        curl_setopt($ch, CURLOPT_POST, count($params));
288
-        curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
289
-
290
-        $result = curl_exec($ch);
291
-
292
-        curl_close($ch);
293
-
294
-        return $result;
295
-    }
296
-
297
-    /**
298
-     * Get current chat id
299
-     * @param null $chat_id
300
-     * @return int
301
-     */
302
-    public function getChatId($chat_id = null) {
303
-        try {
304
-            if ($chat_id)
305
-                return $chat_id;
306
-
307
-            if( isset($this->result->message) ) {
308
-                return $this->result->message->chat->id;
309
-            } elseif ( isset($this->result->inline_query) ) {
310
-                return $this->result->inline_query->from->id;
311
-            } else {
312
-                throw new \Exception("Error Processing Request", 1);
313
-            }
314
-        } catch (\Exception $e) {
315
-            error_log($e->getMessage());
316
-        }
317
-    }
318
-
319
-    /**
320
-     * @param null $offset
321
-     * @param int $limit
322
-     * @param int $timeout
323
-     */
324
-    public function getUpdates($offset = null, $limit = 1, $timeout = 1) {
325
-        return $this->exec('getUpdates', [
326
-            'offset' => $offset,
327
-            'limit' => $limit,
328
-            'timeout' => $timeout
329
-        ]);
330
-    }
331
-
332
-    /**
333
-     * send message
334
-     * @param $text
335
-     * @param $chat_id
336
-     * @param bool $disable_web_page_preview
337
-     * @param null $reply_to_message_id
338
-     * @param null $reply_markup
339
-     * @param null $parse_mode
340
-     */
341
-    public function sendMessage($text, $chat_id = null, $disable_web_page_preview = false, $reply_to_message_id = null, $reply_markup = null, $parse_mode = null) {
342
-        $this->sendChatAction(self::ACTION_TYPING, $chat_id);
343
-        return $this->exec('sendMessage', [
344
-            'chat_id' => $this->getChatId($chat_id),
345
-            'text' => $text,
346
-            'parse_mode' => $parse_mode,
347
-            'disable_web_page_preview' => $disable_web_page_preview,
348
-            'reply_to_message_id' => $reply_to_message_id,
349
-            'reply_markup' => json_encode($reply_markup)
350
-        ]);
351
-    }
352
-
353
-    /**
354
-     * Get me
355
-     */
356
-    public function getMe() {
357
-        return $this->exec('getMe');
358
-    }
359
-
360
-    /**
361
-     * @param $from_id
362
-     * @param $message_id
363
-     * @param null $chat_id
364
-     */
365
-    public function forwardMessage($from_id, $message_id, $chat_id = null) {
366
-        return $this->exec('forwardMessage', [
367
-            'chat_id' => $this->getChatId($chat_id),
368
-            'from_chat_id' => $from_id,
369
-            'message_id' => $message_id,
370
-        ]);
371
-    }
372
-
373
-    /**
374
-     * @param $photo photo file patch
375
-     * @param null $chat_id
376
-     * @param null $caption
377
-     * @param null $reply_to_message_id
378
-     * @param null $reply_markup
379
-     */
380
-    public function sendPhoto($photo, $chat_id = null, $caption = null, $reply_to_message_id = null, $reply_markup = null) {
381
-        $res = $this->exec('sendPhoto', [
382
-            'chat_id' => $this->getChatId($chat_id),
383
-            'photo' => $photo,
384
-            'caption' => $caption,
385
-            'reply_to_message_id' => $reply_to_message_id,
386
-            'reply_markup' => json_encode($reply_markup)
387
-        ]);
388
-
389
-        return $res;
390
-    }
391
-
392
-    /**
393
-     * @param $video video file path
394
-     * @param null $chat_id
395
-     * @param null $reply_to_message_id
396
-     * @param null $reply_markup
397
-     */
398
-    public function sendVideo($video, $chat_id = null, $reply_to_message_id = null, $reply_markup = null) {
399
-        $res = $this->exec('sendVideo', [
400
-            'chat_id' => $this->getChatId($chat_id),
401
-            'video' => $video,
402
-            'reply_to_message_id' => $reply_to_message_id,
403
-            'reply_markup' => json_encode($reply_markup)
404
-        ]);
405
-
406
-        return $res;
407
-    }
408
-
409
-    /**
410
-     *
411
-     * @param $sticker
412
-     * @param null $chat_id
413
-     * @param null $reply_to_message_id
414
-     * @param null $reply_markup
415
-     */
416
-    public function sendSticker($sticker, $chat_id = null, $reply_to_message_id = null, $reply_markup = null) {
417
-        $res = $this->exec('sendSticker', [
418
-            'chat_id' => $this->getChatId($chat_id),
419
-            'sticker' => $sticker,
420
-            'reply_to_message_id' => $reply_to_message_id,
421
-            'reply_markup' => json_encode($reply_markup)
422
-        ]);
423
-
424
-        return $res;
425
-        // as soons as possible
426
-    }
427
-
428
-    /**
429
-     * @param $latitude
430
-     * @param $longitude
431
-     * @param null $chat_id
432
-     * @param null $reply_to_message_id
433
-     * @param null $reply_markup
434
-     */
435
-    public function sendLocation($latitude, $longitude, $chat_id = null, $reply_to_message_id = null, $reply_markup = null) {
436
-        $res = $this->exec('sendLocation', [
437
-            'chat_id' => $this->getChatId($chat_id),
438
-            'latitude' => $latitude,
439
-            'longitude' => $longitude,
440
-            'reply_to_message_id' => $reply_to_message_id,
441
-            'reply_markup' => json_encode($reply_markup)
442
-        ]);
443
-
444
-        return $res;
445
-    }
446
-
447
-    /**
448
-     * @param $document
449
-     * @param null $chat_id
450
-     * @param null $reply_to_message_id
451
-     * @param null $reply_markup
452
-     */
453
-    public function sendDocument($document, $chat_id = null, $reply_to_message_id = null, $reply_markup = null) {
454
-        $res = $this->exec('sendDocument', [
455
-            'chat_id' => $this->getChatId($chat_id),
456
-            'document' => $document,
457
-            'reply_to_message_id' => $reply_to_message_id,
458
-            'reply_markup' => json_encode($reply_markup)
459
-        ]);
460
-
461
-        return $res;
462
-    }
463
-
464
-    public function sendAudio($audio, $chat_id = null, $reply_to_message_id = null, $reply_markup = null) {
465
-        $res = $this->exec('sendAudio', [
466
-            'chat_id' => $this->getChatId($chat_id),
467
-            'audio' => $audio,
468
-            'reply_to_message_id' => $reply_to_message_id,
469
-            'reply_markup' => json_encode($reply_markup)
470
-        ]);
471
-
472
-        return $res;
473
-    }
474
-
475
-    /**
476
-     * send chat action : Telegram::ACTION_TYPING , ...
477
-     * @param $action
478
-     * @param null $chat_id
479
-     */
480
-    public function sendChatAction($action, $chat_id = null) {
481
-        $res = $this->exec('sendChatAction', [
482
-            'chat_id' => $this->getChatId($chat_id),
483
-            'action' => $action
484
-        ]);
485
-
486
-        return $res;
487
-    }
488
-
489
-    /**
490
-     * @param $user_id
491
-     * @param null $offset
492
-     * @param null $limit
493
-     */
494
-    public function getUserProfilePhotos($user_id, $offset = null, $limit = null) {
495
-        $res = $this->exec('getUserProfilePhotos', [
496
-            'user_id' => $user_id,
497
-            'offset' => $offset,
498
-            'limit' => $limit
499
-        ]);
500
-
501
-        return $res;
502
-    }
503
-
504
-
505
-    public function answerInlineQuery($inline_query_id, $results, $cache_time = 0, $is_personal = false, $next_offset = '', $switch_pm_text = '', $switch_pm_parameter = '') {
506
-        $res = $this->exec('answerInlineQuery', [
507
-            'inline_query_id' => $inline_query_id,
508
-            'results' => json_encode($results),
509
-            'cache_time' => $cache_time,
510
-            'is_personal' => $is_personal,
511
-            'next_offset' => $next_offset,
512
-            'switch_pm_text' => $switch_pm_text,
513
-            'switch_pm_parameter' => $switch_pm_parameter
514
-        ]);
515
-
516
-        return $res;
517
-    }
518
-
519
-    /**
520
-     * @param $url
521
-     */
522
-    public function setWebhook($url) {
523
-        $res = $this->exec('setWebhook', [
524
-            'url' => $url
525
-        ]);
526
-
527
-        return $res;
528
-    }
14
+	const PARSE_MARKDOWN = 'Markdown';
15
+	const PARSE_HTML     = 'HTML';
16
+
17
+	const ACTION_TYPING         = 'typing';
18
+	const ACTION_UPLOAD_PHOTO   = 'upload_photo';
19
+	const ACTION_RECORD_VIDEO   = 'record_video';
20
+	const ACTION_UPLOAD_VIDEO   = 'upload_video';
21
+	const ACTION_RECORD_AUDIO   = 'record_audio';
22
+	const ACTION_UPLOAD_AUDIO   = 'upload_audio';
23
+	const ACTION_UPLOAD_DOC     = 'upload_document';
24
+	const ACTION_FIND_LOCATION  = 'find_location';
25
+
26
+	public $api = 'https://api.telegram.org/bot';
27
+
28
+	/**
29
+	 * returned json from telegram api parse to object and save to result
30
+	 * @var
31
+	 */
32
+	public $result;
33
+
34
+	/**
35
+	 * @name State of bot
36
+	 * state of bot
37
+	 * @var object
38
+	 */
39
+	public $state;
40
+
41
+	/**
42
+	 * commands in regex and callback
43
+	 * @var array
44
+	 */
45
+	private $commands = [];
46
+
47
+	/**
48
+	 * InlineQuery in regex and callback
49
+	 * @var array
50
+	 */
51
+	private $inlines = [];
52
+
53
+	/**
54
+	 * callbacks
55
+	 * @var array
56
+	 */
57
+	private $callbacks = [];
58
+
59
+	/**
60
+	 * available telegram bot commands
61
+	 * @var array
62
+	 */
63
+	private $available_commands = [
64
+		'getMe',
65
+		'sendMessage',
66
+		'forwardMessage',
67
+		'sendPhoto',
68
+		'sendAudio',
69
+		'sendDocument',
70
+		'sendSticker',
71
+		'sendVideo',
72
+		'sendLocation',
73
+		'sendChatAction',
74
+		'getUserProfilePhotos',
75
+		'answerInlineQuery',
76
+		'getUpdates',
77
+		'setWebhook',
78
+	];
79
+
80
+	/**
81
+	 * pre patterns you can use in regex
82
+	 * @var array
83
+	 */
84
+	private $patterns = [
85
+		':any' => '.*',
86
+		':num' => '[0-9]{0,}',
87
+		':str' => '[a-zA-z]{0,}',
88
+	];
89
+
90
+	/**
91
+	 *
92
+	 * @param String $token Telegram api token , taken by botfather
93
+	 */
94
+	public function __construct($token) {
95
+		$this->api .= $token;
96
+	}
97
+
98
+	/**
99
+	 * add new command to the bot
100
+	 * @param String $cmd
101
+	 * @param \Closure $func
102
+	 */
103
+	public function cmd($cmd, $func) {
104
+		$this->commands[] = new Trigger($cmd, $func);
105
+	}
106
+
107
+
108
+	public function PDO(){
109
+
110
+		$servername ='YOUR_SERVER_NAME';
111
+		$username = 'YOUR_USERNAME';
112
+		$password ='YOUR_PASSWORD';
113
+		$dbname = 'YOUR_DATABASE_NAME';
114
+		try {
115
+			$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password, [PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"]);
116
+			$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
117
+
118
+			return $conn;
119
+		}
120
+		catch(PDOException $e)
121
+		{
122
+			return $e->getMessage();
123
+		}
124
+	}
125
+
126
+	/**
127
+	 * add new InlineQuery to the bot
128
+	 * @param String $cmd
129
+	 * @param \Closure $func
130
+	 */
131
+	public function inlineQuery($cmd, $func) {
132
+		$this->inlines[] = new Trigger($cmd, $func);
133
+	}
134
+
135
+	/**
136
+	 * this method check for received payload(command, inlinequery and so on) and
137
+	 * then execute the correct function
138
+	 *
139
+	 * @param bool $sleep
140
+	 */
141
+	public function run($sleep = false) {
142
+		$result = $this->getUpdates();
143
+		while (true) {
144
+			$update_id = isset($result->update_id) ? $result->update_id : 1;
145
+			$result = $this->getUpdates($update_id + 1);
146
+
147
+			$this->processPayload($result);
148
+
149
+			if ($sleep !== false)
150
+				sleep($sleep);
151
+		}
152
+	}
153
+
154
+	/**
155
+	 * this method used for setWebhook sended payload
156
+	 */
157
+	public function process($payload) {
158
+		$result = $this->convertToObject($payload, true);
159
+
160
+		return $this->processPayload($result);
161
+	}
162
+
163
+	private function processPayload($result) {
164
+		if ($result) {
165
+			try {
166
+				$this->result = $result;
167
+
168
+				// now i select the right triggers for payload received by Telegram
169
+				if( isset($this->result->message->text) ) {
170
+					$payload = $this->result->message->text;
171
+					$triggers = $this->commands;
172
+				} elseif ( isset($this->result->inline_query) ) {
173
+					$payload = $this->result->inline_query->query;
174
+					$triggers = $this->inlines;
175
+				} else {
176
+					throw new \Exception("Error Processing Request", 1);
177
+				}
178
+
179
+				$args = null;
180
+
181
+				foreach ($triggers as &$trigger) {
182
+					// replace public patterns to regex pattern
183
+					$searchs = array_keys($this->patterns);
184
+					$replaces = array_values($this->patterns);
185
+					$pattern = str_replace($searchs, $replaces, $trigger->pattern);
186
+
187
+					//find args pattern
188
+					$args = $this->getArgs($pattern, $payload);
189
+
190
+					$pattern = '/^' . $pattern . '/i';
191
+
192
+					preg_match($pattern, $payload, $matches);
193
+
194
+					if (isset($matches[0])) {
195
+						$func = $trigger->callback;
196
+						return call_user_func($func, $args);
197
+					}
198
+				}
199
+			} catch (\Exception $e) {
200
+				error_log($e->getMessage());
201
+				echo "\r\n Exception :: " . $e->getMessage();
202
+			}
203
+		} else {
204
+			echo "\r\nNo new message\r\n";
205
+		}
206
+	}
207
+
208
+	/**
209
+	 * get arguments part in regex
210
+	 * @param $pattern
211
+	 * @param $payload
212
+	 * @return mixed|null
213
+	 */
214
+	private function getArgs(&$pattern, $payload) {
215
+		$args = null;
216
+		// if command has argument
217
+		if (preg_match('/<<.*>>/', $pattern, $matches)) {
218
+
219
+			$args_pattern = $matches[0];
220
+			//remove << and >> from patterns
221
+			$tmp_args_pattern = str_replace(['<<', '>>'], ['(', ')'], $pattern);
222
+
223
+			//if args set
224
+			if (preg_match('/' . $tmp_args_pattern . '/i', $payload, $matches)) {
225
+				//remove first element
226
+				array_shift($matches);
227
+				if (isset($matches[0])) {
228
+					//set args
229
+					$args = array_shift($matches);
230
+
231
+					//remove args pattern from main pattern
232
+					$pattern = str_replace($args_pattern, '', $pattern);
233
+				}
234
+			}
235
+		}
236
+		return $args;
237
+	}
238
+
239
+	/**
240
+	 * execute telegram api commands
241
+	 * @param $command
242
+	 * @param array $params
243
+	 */
244
+	private function exec($command, $params = []) {
245
+		if (in_array($command, $this->available_commands)) {
246
+			// convert json to array then get the last messages info
247
+			$output = json_decode($this->curl_get_contents($this->api . '/' . $command, $params), true);
248
+
249
+			return $this->convertToObject($output);
250
+		} else {
251
+			echo 'command not found';
252
+		}
253
+	}
254
+
255
+	private function convertToObject($jsonObject , $webhook = false) {
256
+		if( ! $webhook) {
257
+			if ($jsonObject['ok']) {
258
+				//error_log(print_r($jsonObject, true));
259
+
260
+				// remove unwanted array elements
261
+				$output = end($jsonObject);
262
+
263
+				$result = is_array($output) ? end($output) : $output;
264
+				if ( ! empty($result)) {
265
+					// convert to object
266
+					return json_decode(json_encode($result));
267
+				}
268
+			}
269
+		} else {
270
+			return json_decode(json_encode($jsonObject));
271
+		}
272
+	}
273
+
274
+	/**
275
+	 * get the $url content with CURL
276
+	 * @param $url
277
+	 * @param $params
278
+	 * @return mixed
279
+	 */
280
+	private function curl_get_contents($url, $params) {
281
+		$ch = curl_init();
282
+
283
+		curl_setopt($ch, CURLOPT_URL, $url);
284
+		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
285
+		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
286
+		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
287
+		curl_setopt($ch, CURLOPT_POST, count($params));
288
+		curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
289
+
290
+		$result = curl_exec($ch);
291
+
292
+		curl_close($ch);
293
+
294
+		return $result;
295
+	}
296
+
297
+	/**
298
+	 * Get current chat id
299
+	 * @param null $chat_id
300
+	 * @return int
301
+	 */
302
+	public function getChatId($chat_id = null) {
303
+		try {
304
+			if ($chat_id)
305
+				return $chat_id;
306
+
307
+			if( isset($this->result->message) ) {
308
+				return $this->result->message->chat->id;
309
+			} elseif ( isset($this->result->inline_query) ) {
310
+				return $this->result->inline_query->from->id;
311
+			} else {
312
+				throw new \Exception("Error Processing Request", 1);
313
+			}
314
+		} catch (\Exception $e) {
315
+			error_log($e->getMessage());
316
+		}
317
+	}
318
+
319
+	/**
320
+	 * @param null $offset
321
+	 * @param int $limit
322
+	 * @param int $timeout
323
+	 */
324
+	public function getUpdates($offset = null, $limit = 1, $timeout = 1) {
325
+		return $this->exec('getUpdates', [
326
+			'offset' => $offset,
327
+			'limit' => $limit,
328
+			'timeout' => $timeout
329
+		]);
330
+	}
331
+
332
+	/**
333
+	 * send message
334
+	 * @param $text
335
+	 * @param $chat_id
336
+	 * @param bool $disable_web_page_preview
337
+	 * @param null $reply_to_message_id
338
+	 * @param null $reply_markup
339
+	 * @param null $parse_mode
340
+	 */
341
+	public function sendMessage($text, $chat_id = null, $disable_web_page_preview = false, $reply_to_message_id = null, $reply_markup = null, $parse_mode = null) {
342
+		$this->sendChatAction(self::ACTION_TYPING, $chat_id);
343
+		return $this->exec('sendMessage', [
344
+			'chat_id' => $this->getChatId($chat_id),
345
+			'text' => $text,
346
+			'parse_mode' => $parse_mode,
347
+			'disable_web_page_preview' => $disable_web_page_preview,
348
+			'reply_to_message_id' => $reply_to_message_id,
349
+			'reply_markup' => json_encode($reply_markup)
350
+		]);
351
+	}
352
+
353
+	/**
354
+	 * Get me
355
+	 */
356
+	public function getMe() {
357
+		return $this->exec('getMe');
358
+	}
359
+
360
+	/**
361
+	 * @param $from_id
362
+	 * @param $message_id
363
+	 * @param null $chat_id
364
+	 */
365
+	public function forwardMessage($from_id, $message_id, $chat_id = null) {
366
+		return $this->exec('forwardMessage', [
367
+			'chat_id' => $this->getChatId($chat_id),
368
+			'from_chat_id' => $from_id,
369
+			'message_id' => $message_id,
370
+		]);
371
+	}
372
+
373
+	/**
374
+	 * @param $photo photo file patch
375
+	 * @param null $chat_id
376
+	 * @param null $caption
377
+	 * @param null $reply_to_message_id
378
+	 * @param null $reply_markup
379
+	 */
380
+	public function sendPhoto($photo, $chat_id = null, $caption = null, $reply_to_message_id = null, $reply_markup = null) {
381
+		$res = $this->exec('sendPhoto', [
382
+			'chat_id' => $this->getChatId($chat_id),
383
+			'photo' => $photo,
384
+			'caption' => $caption,
385
+			'reply_to_message_id' => $reply_to_message_id,
386
+			'reply_markup' => json_encode($reply_markup)
387
+		]);
388
+
389
+		return $res;
390
+	}
391
+
392
+	/**
393
+	 * @param $video video file path
394
+	 * @param null $chat_id
395
+	 * @param null $reply_to_message_id
396
+	 * @param null $reply_markup
397
+	 */
398
+	public function sendVideo($video, $chat_id = null, $reply_to_message_id = null, $reply_markup = null) {
399
+		$res = $this->exec('sendVideo', [
400
+			'chat_id' => $this->getChatId($chat_id),
401
+			'video' => $video,
402
+			'reply_to_message_id' => $reply_to_message_id,
403
+			'reply_markup' => json_encode($reply_markup)
404
+		]);
405
+
406
+		return $res;
407
+	}
408
+
409
+	/**
410
+	 *
411
+	 * @param $sticker
412
+	 * @param null $chat_id
413
+	 * @param null $reply_to_message_id
414
+	 * @param null $reply_markup
415
+	 */
416
+	public function sendSticker($sticker, $chat_id = null, $reply_to_message_id = null, $reply_markup = null) {
417
+		$res = $this->exec('sendSticker', [
418
+			'chat_id' => $this->getChatId($chat_id),
419
+			'sticker' => $sticker,
420
+			'reply_to_message_id' => $reply_to_message_id,
421
+			'reply_markup' => json_encode($reply_markup)
422
+		]);
423
+
424
+		return $res;
425
+		// as soons as possible
426
+	}
427
+
428
+	/**
429
+	 * @param $latitude
430
+	 * @param $longitude
431
+	 * @param null $chat_id
432
+	 * @param null $reply_to_message_id
433
+	 * @param null $reply_markup
434
+	 */
435
+	public function sendLocation($latitude, $longitude, $chat_id = null, $reply_to_message_id = null, $reply_markup = null) {
436
+		$res = $this->exec('sendLocation', [
437
+			'chat_id' => $this->getChatId($chat_id),
438
+			'latitude' => $latitude,
439
+			'longitude' => $longitude,
440
+			'reply_to_message_id' => $reply_to_message_id,
441
+			'reply_markup' => json_encode($reply_markup)
442
+		]);
443
+
444
+		return $res;
445
+	}
446
+
447
+	/**
448
+	 * @param $document
449
+	 * @param null $chat_id
450
+	 * @param null $reply_to_message_id
451
+	 * @param null $reply_markup
452
+	 */
453
+	public function sendDocument($document, $chat_id = null, $reply_to_message_id = null, $reply_markup = null) {
454
+		$res = $this->exec('sendDocument', [
455
+			'chat_id' => $this->getChatId($chat_id),
456
+			'document' => $document,
457
+			'reply_to_message_id' => $reply_to_message_id,
458
+			'reply_markup' => json_encode($reply_markup)
459
+		]);
460
+
461
+		return $res;
462
+	}
463
+
464
+	public function sendAudio($audio, $chat_id = null, $reply_to_message_id = null, $reply_markup = null) {
465
+		$res = $this->exec('sendAudio', [
466
+			'chat_id' => $this->getChatId($chat_id),
467
+			'audio' => $audio,
468
+			'reply_to_message_id' => $reply_to_message_id,
469
+			'reply_markup' => json_encode($reply_markup)
470
+		]);
471
+
472
+		return $res;
473
+	}
474
+
475
+	/**
476
+	 * send chat action : Telegram::ACTION_TYPING , ...
477
+	 * @param $action
478
+	 * @param null $chat_id
479
+	 */
480
+	public function sendChatAction($action, $chat_id = null) {
481
+		$res = $this->exec('sendChatAction', [
482
+			'chat_id' => $this->getChatId($chat_id),
483
+			'action' => $action
484
+		]);
485
+
486
+		return $res;
487
+	}
488
+
489
+	/**
490
+	 * @param $user_id
491
+	 * @param null $offset
492
+	 * @param null $limit
493
+	 */
494
+	public function getUserProfilePhotos($user_id, $offset = null, $limit = null) {
495
+		$res = $this->exec('getUserProfilePhotos', [
496
+			'user_id' => $user_id,
497
+			'offset' => $offset,
498
+			'limit' => $limit
499
+		]);
500
+
501
+		return $res;
502
+	}
503
+
504
+
505
+	public function answerInlineQuery($inline_query_id, $results, $cache_time = 0, $is_personal = false, $next_offset = '', $switch_pm_text = '', $switch_pm_parameter = '') {
506
+		$res = $this->exec('answerInlineQuery', [
507
+			'inline_query_id' => $inline_query_id,
508
+			'results' => json_encode($results),
509
+			'cache_time' => $cache_time,
510
+			'is_personal' => $is_personal,
511
+			'next_offset' => $next_offset,
512
+			'switch_pm_text' => $switch_pm_text,
513
+			'switch_pm_parameter' => $switch_pm_parameter
514
+		]);
515
+
516
+		return $res;
517
+	}
518
+
519
+	/**
520
+	 * @param $url
521
+	 */
522
+	public function setWebhook($url) {
523
+		$res = $this->exec('setWebhook', [
524
+			'url' => $url
525
+		]);
526
+
527
+		return $res;
528
+	}
529 529
 
530 530
 }
Please login to merge, or discard this patch.
src/Smoqadam/InlineQuery/Result/Article.php 2 patches
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -5,15 +5,15 @@
 block discarded – undo
5 5
 class Article {
6 6
 
7 7
   public
8
-    $type = 'article',
9
-    $id,
10
-    $title,
11
-    $input_message_content;
8
+	$type = 'article',
9
+	$id,
10
+	$title,
11
+	$input_message_content;
12 12
 
13 13
   public function __construct($title, $content) {
14
-    $this->title = $title;
15
-    $this->input_message_content = $content;
16
-    $this->id = '' . rand();
14
+	$this->title = $title;
15
+	$this->input_message_content = $content;
16
+	$this->id = '' . rand();
17 17
   }
18 18
 
19 19
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
   public function __construct($title, $content) {
14 14
     $this->title = $title;
15 15
     $this->input_message_content = $content;
16
-    $this->id = '' . rand();
16
+    $this->id = ''.rand();
17 17
   }
18 18
 
19 19
 }
Please login to merge, or discard this patch.
src/Smoqadam/Keyboard/Standard.php 2 patches
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -5,47 +5,47 @@
 block discarded – undo
5 5
 class Standard {
6 6
 
7 7
   public
8
-    $keyboard = [],
9
-    $resize_keyboard,
10
-    $one_time_keyboard,
11
-    $selective;
8
+	$keyboard = [],
9
+	$resize_keyboard,
10
+	$one_time_keyboard,
11
+	$selective;
12 12
     
13 13
   private
14
-    $current_row = 0;
14
+	$current_row = 0;
15 15
 
16 16
   public function __construct($resize_keyboard = false, $one_time_keyboard = false, $selective = false) {
17
-    $this->resize_keyboard    = $resize_keyboard;
18
-    $this->one_time_keyboard  = $one_time_keyboard;
19
-    $this->selective          = $selective;
17
+	$this->resize_keyboard    = $resize_keyboard;
18
+	$this->one_time_keyboard  = $one_time_keyboard;
19
+	$this->selective          = $selective;
20 20
   }
21 21
   
22 22
   /**
23
-  * Create new row.
24
-  *
25
-  * @return object Standard
26
-  */
23
+   * Create new row.
24
+   *
25
+   * @return object Standard
26
+   */
27 27
   public function addRow(){
28
-    $this->current_row++;
28
+	$this->current_row++;
29 29
     
30
-    return $this;
30
+	return $this;
31 31
   }
32 32
   
33 33
   /**
34
-  * Add new button to current row.
35
-  *
36
-  * @param string $text 	Text of the button. If none of the optional fields are used, it will be sent to the bot as a message when the button is pressed
37
-  * @param boolean $request_contact Optional. If True, the user's phone number will be sent as a contact when the button is pressed. Available in private chats only
38
-  * @param boolean $request_location Optional. If True, the user's current location will be sent when the button is pressed. Available in private chats only
39
-  * @return object
40
-  */
34
+   * Add new button to current row.
35
+   *
36
+   * @param string $text 	Text of the button. If none of the optional fields are used, it will be sent to the bot as a message when the button is pressed
37
+   * @param boolean $request_contact Optional. If True, the user's phone number will be sent as a contact when the button is pressed. Available in private chats only
38
+   * @param boolean $request_location Optional. If True, the user's current location will be sent when the button is pressed. Available in private chats only
39
+   * @return object
40
+   */
41 41
   public function addButton(string $text, boolean $request_contact = null, boolean $request_location = null){
42
-    $this->keyboard[$this->current_row][] = [
43
-      'text' => $text,
44
-      'request_contact' => ($request_contact != null) ? $request_contact : false,
45
-      'request_location' => ($request_location != null) ? $request_location : false
46
-    ];
42
+	$this->keyboard[$this->current_row][] = [
43
+	  'text' => $text,
44
+	  'request_contact' => ($request_contact != null) ? $request_contact : false,
45
+	  'request_location' => ($request_location != null) ? $request_location : false
46
+	];
47 47
     
48
-    return $this;
48
+	return $this;
49 49
   }
50 50
 
51 51
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
   *
25 25
   * @return object Standard
26 26
   */
27
-  public function addRow(){
27
+  public function addRow() {
28 28
     $this->current_row++;
29 29
     
30 30
     return $this;
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
   * @param boolean $request_location Optional. If True, the user's current location will be sent when the button is pressed. Available in private chats only
39 39
   * @return object
40 40
   */
41
-  public function addButton(string $text, boolean $request_contact = null, boolean $request_location = null){
41
+  public function addButton(string $text, boolean $request_contact = null, boolean $request_location = null) {
42 42
     $this->keyboard[$this->current_row][] = [
43 43
       'text' => $text,
44 44
       'request_contact' => ($request_contact != null) ? $request_contact : false,
Please login to merge, or discard this patch.
src/Smoqadam/Keyboard/Remove.php 2 patches
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -4,16 +4,16 @@
 block discarded – undo
4 4
 
5 5
 class Remove {
6 6
     
7
-    public
8
-        $remove_keyboard = true,
9
-        $selective;
7
+	public
8
+		$remove_keyboard = true,
9
+		$selective;
10 10
         
11
-    /*
11
+	/*
12 12
     * Telegram clients will remove the current custom keyboard and display the default letter-keyboard.
13 13
     *
14 14
     * @param boolean $selective Optional. Use this parameter if you want to remove the keyboard for specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.
15 15
     */
16
-    public function __construct($selective = false){
17
-        $this->selective        = $selective;
18
-    }
16
+	public function __construct($selective = false){
17
+		$this->selective        = $selective;
18
+	}
19 19
 }
20 20
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
     *
14 14
     * @param boolean $selective Optional. Use this parameter if you want to remove the keyboard for specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.
15 15
     */
16
-    public function __construct($selective = false){
17
-        $this->selective        = $selective;
16
+    public function __construct($selective = false) {
17
+        $this->selective = $selective;
18 18
     }
19 19
 }
20 20
\ No newline at end of file
Please login to merge, or discard this patch.
src/Smoqadam/Trigger.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -5,12 +5,12 @@
 block discarded – undo
5 5
 class Trigger {
6 6
   
7 7
   public
8
-    $pattern,
9
-    $callback;
8
+	$pattern,
9
+	$callback;
10 10
 
11 11
   public function __construct($pattern, $callback) {
12
-    $this->pattern  = $pattern;
13
-    $this->callback = $callback;
12
+	$this->pattern  = $pattern;
13
+	$this->callback = $callback;
14 14
   }
15 15
 
16 16
 }
Please login to merge, or discard this patch.
src/Smoqadam/Input/TextMessageContent.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -6,14 +6,14 @@
 block discarded – undo
6 6
 class TextMessageContent {
7 7
 
8 8
   public
9
-    $message_text,
10
-    $parse_mode,
11
-    $disable_web_page_preview;
9
+	$message_text,
10
+	$parse_mode,
11
+	$disable_web_page_preview;
12 12
 
13 13
   public function __construct($message_text, $parse_mode = Telegram::PARSE_MARKDOWN, $disable_web_page_preview = false) {
14
-    $this->message_text             = $message_text;
15
-    $this->parse_mode               = $parse_mode;
16
-    $this->disable_web_page_preview = $disable_web_page_preview;
14
+	$this->message_text             = $message_text;
15
+	$this->parse_mode               = $parse_mode;
16
+	$this->disable_web_page_preview = $disable_web_page_preview;
17 17
   }
18 18
 
19 19
 }
Please login to merge, or discard this patch.
index.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -7,14 +7,14 @@
 block discarded – undo
7 7
 
8 8
 $tg = new Telegram('API_TOKEN');
9 9
 
10
-$tg->cmd('name:<<[a-zA-Z]{0,}>>', function ($args) use ($tg){
10
+$tg->cmd('name:<<[a-zA-Z]{0,}>>', function($args) use ($tg){
11 11
 	
12
-		$tg->sendMessage("my username is @".$args , $tg->getChatId());
12
+		$tg->sendMessage("my username is @".$args, $tg->getChatId());
13 13
 });
14 14
 
15 15
 
16
-$tg->cmd('<<:any>>',function ($arg) use ($tg){
17
-	$tg->sendMessage("You Message is : " . $arg, $tg->getChatId()); 
16
+$tg->cmd('<<:any>>', function($arg) use ($tg){
17
+	$tg->sendMessage("You Message is : ".$arg, $tg->getChatId()); 
18 18
 });
19 19
 
20 20
 $tg->run();
Please login to merge, or discard this patch.