Skip to content

Commit 965a976

Browse files
authored
Merge pull request #213 from lyucean/master
A few changes for your repository
2 parents aa9ba83 + 1e334e2 commit 965a976

File tree

2 files changed

+122
-106
lines changed

2 files changed

+122
-106
lines changed

Telegram.php

Lines changed: 117 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Telegram
5454
/**
5555
* Constant for type sticker.
5656
*/
57-
const STICKER = 'sticker';
57+
const STICKER = 'sticker';
5858
/**
5959
* Constant for type Document.
6060
*/
@@ -106,7 +106,7 @@ public function __construct($bot_token, $log_errors = true, array $proxy = [])
106106
*/
107107
public function endpoint($api, array $content, $post = true)
108108
{
109-
$url = 'https://api.telegram.org/bot'.$this->bot_token.'/'.$api;
109+
$url = 'https://api.telegram.org/bot' . $this->bot_token . '/' . $api;
110110
if ($post) {
111111
$reply = $this->sendAPIRequest($url, $content);
112112
} else {
@@ -420,94 +420,94 @@ public function sendDocument(array $content)
420420
{
421421
return $this->endpoint('sendDocument', $content);
422422
}
423-
423+
424424
/// Send an animation
425425

426426
/**
427427
* Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound). On success, the sent Message is returned. Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future.<br/>Values inside $content:<br/>
428-
* </table>
429-
* <tr>
430-
* <th>Parameter</th>
431-
* <th>Type</th>
432-
* <th>Required</th>
433-
* <th>Description</th>
434-
* </tr>
435-
* </thead>
436-
* <tbody>
437-
* <tr>
438-
* <td>chat_id</td>
439-
* <td>Integer or String</td>
440-
* <td>Yes</td>
441-
* <td>Unique identifier for the target chat or username of the target channel (in the format <code>@channelusername</code>)</td>
442-
* </tr>
443-
* <tr>
444-
* <td>animation</td>
445-
* <td><a href="#inputfile">InputFile</a> or String</td>
446-
* <td>Yes</td>
447-
* <td>Animation to send. Pass a file_id as String to send an animation that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an animation from the Internet, or upload a new animation using multipart/form-data. <a href="#sending-files">More info on Sending Files »</a></td>
448-
* </tr>
449-
* <tr>
450-
* <td>duration</td>
451-
* <td>Integer</td>
452-
* <td>Optional</td>
453-
* <td>Duration of sent animation in seconds</td>
454-
* </tr>
455-
* <tr>
456-
* <td>width</td>
457-
* <td>Integer</td>
458-
* <td>Optional</td>
459-
* <td>Animation width</td>
460-
* </tr>
461-
* <tr>
462-
* <td>height</td>
463-
* <td>Integer</td>
464-
* <td>Optional</td>
465-
* <td>Animation height</td>
466-
* </tr>
467-
* <tr>
468-
* <td>thumb</td>
469-
* <td><a href="#inputfile">InputFile</a> or String</td>
470-
* <td>Optional</td>
471-
* <td>Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 90. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://&lt;file_attach_name&gt;” if the thumbnail was uploaded using multipart/form-data under &lt;file_attach_name&gt;. <a href="#sending-files">More info on Sending Files »</a></td>
472-
* </tr>
473-
* <tr>
474-
* <td>caption</td>
475-
* <td>String</td>
476-
* <td>Optional</td>
477-
* <td>Animation caption (may also be used when resending animation by <em>file_id</em>), 0-1024 characters</td>
478-
* </tr>
479-
* <tr>
480-
* <td>parse_mode</td>
481-
* <td>String</td>
482-
* <td>Optional</td>
483-
* <td>Send <a href="#markdown-style"><em>Markdown</em></a> or <a href="#html-style"><em>HTML</em></a>, if you want Telegram apps to show <a href="#formatting-* options">bold, italic, fixed-width text or inline URLs</a> in the media caption.</td>
484-
* </tr>
485-
* <tr>
486-
* <td>disable_notification</td>
487-
* <td>Boolean</td>
488-
* <td>Optional</td>
489-
* <td>Sends the message <a href="https://telegram.org/blog/channels-2-0#silent-messages">silently</a>. Users will receive a notification with no sound.</td>
490-
* </tr>
491-
* <tr>
492-
* <td>reply_to_message_id</td>
493-
* <td>Integer</td>
494-
* <td>Optional</td>
495-
* <td>If the message is a reply, ID of the original message</td>
496-
* </tr>
497-
* <tr>
498-
* <td>reply_markup</td>
499-
* <td><a href="#inlinekeyboardmarkup">InlineKeyboardMarkup</a> or <a href="#replykeyboardmarkup">ReplyKeyboardMarkup</a> or <a href="#replykeyboardremove">ReplyKeyboardRemove</a> or <a href="#forcereply">ForceReply</a></td>
500-
* <td>Optional</td>
501-
* <td>Additional interface options. A JSON-serialized object for an <a href="https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating">inline keyboard</a>, <a href="https://core.telegram.org/bots#keyboards">custom reply keyboard</a>, instructions to remove reply keyboard or to force a reply from the user.</td>
502-
* </tr>
503-
* </table>
428+
* </table>
429+
* <tr>
430+
* <th>Parameter</th>
431+
* <th>Type</th>
432+
* <th>Required</th>
433+
* <th>Description</th>
434+
* </tr>
435+
* </thead>
436+
* <tbody>
437+
* <tr>
438+
* <td>chat_id</td>
439+
* <td>Integer or String</td>
440+
* <td>Yes</td>
441+
* <td>Unique identifier for the target chat or username of the target channel (in the format <code>@channelusername</code>)</td>
442+
* </tr>
443+
* <tr>
444+
* <td>animation</td>
445+
* <td><a href="#inputfile">InputFile</a> or String</td>
446+
* <td>Yes</td>
447+
* <td>Animation to send. Pass a file_id as String to send an animation that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an animation from the Internet, or upload a new animation using multipart/form-data. <a href="#sending-files">More info on Sending Files »</a></td>
448+
* </tr>
449+
* <tr>
450+
* <td>duration</td>
451+
* <td>Integer</td>
452+
* <td>Optional</td>
453+
* <td>Duration of sent animation in seconds</td>
454+
* </tr>
455+
* <tr>
456+
* <td>width</td>
457+
* <td>Integer</td>
458+
* <td>Optional</td>
459+
* <td>Animation width</td>
460+
* </tr>
461+
* <tr>
462+
* <td>height</td>
463+
* <td>Integer</td>
464+
* <td>Optional</td>
465+
* <td>Animation height</td>
466+
* </tr>
467+
* <tr>
468+
* <td>thumb</td>
469+
* <td><a href="#inputfile">InputFile</a> or String</td>
470+
* <td>Optional</td>
471+
* <td>Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 90. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://&lt;file_attach_name&gt;” if the thumbnail was uploaded using multipart/form-data under &lt;file_attach_name&gt;. <a href="#sending-files">More info on Sending Files »</a></td>
472+
* </tr>
473+
* <tr>
474+
* <td>caption</td>
475+
* <td>String</td>
476+
* <td>Optional</td>
477+
* <td>Animation caption (may also be used when resending animation by <em>file_id</em>), 0-1024 characters</td>
478+
* </tr>
479+
* <tr>
480+
* <td>parse_mode</td>
481+
* <td>String</td>
482+
* <td>Optional</td>
483+
* <td>Send <a href="#markdown-style"><em>Markdown</em></a> or <a href="#html-style"><em>HTML</em></a>, if you want Telegram apps to show <a href="#formatting-* options">bold, italic, fixed-width text or inline URLs</a> in the media caption.</td>
484+
* </tr>
485+
* <tr>
486+
* <td>disable_notification</td>
487+
* <td>Boolean</td>
488+
* <td>Optional</td>
489+
* <td>Sends the message <a href="https://telegram.org/blog/channels-2-0#silent-messages">silently</a>. Users will receive a notification with no sound.</td>
490+
* </tr>
491+
* <tr>
492+
* <td>reply_to_message_id</td>
493+
* <td>Integer</td>
494+
* <td>Optional</td>
495+
* <td>If the message is a reply, ID of the original message</td>
496+
* </tr>
497+
* <tr>
498+
* <td>reply_markup</td>
499+
* <td><a href="#inlinekeyboardmarkup">InlineKeyboardMarkup</a> or <a href="#replykeyboardmarkup">ReplyKeyboardMarkup</a> or <a href="#replykeyboardremove">ReplyKeyboardRemove</a> or <a href="#forcereply">ForceReply</a></td>
500+
* <td>Optional</td>
501+
* <td>Additional interface options. A JSON-serialized object for an <a href="https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating">inline keyboard</a>, <a href="https://core.telegram.org/bots#keyboards">custom reply keyboard</a>, instructions to remove reply keyboard or to force a reply from the user.</td>
502+
* </tr>
503+
* </table>
504504
* \param $content the request parameters as array
505505
* \return the JSON Telegram's reply.
506506
*/
507507
public function sendAnimation(array $content)
508508
{
509509
return $this->endpoint('sendAnimation', $content);
510-
}
510+
}
511511

512512
/// Send a sticker
513513

@@ -1022,6 +1022,7 @@ public function sendVenue(array $content)
10221022
}
10231023

10241024
//Send contact
1025+
10251026
/**Use this method to send phone contacts. On success, the sent <a href="https://core.telegram.org/bots/api#message">Message</a> is returned.</p> <br/>Values inside $content:<br/>
10261027
* <table>
10271028
* <tr>
@@ -1683,7 +1684,7 @@ public function editMessageReplyMarkup(array $content)
16831684
*/
16841685
public function downloadFile($telegram_file_path, $local_file_path)
16851686
{
1686-
$file_url = 'https://api.telegram.org/file/bot'.$this->bot_token.'/'.$telegram_file_path;
1687+
$file_url = 'https://api.telegram.org/file/bot' . $this->bot_token . '/' . $telegram_file_path;
16871688
$in = fopen($file_url, 'rb');
16881689
$out = fopen($local_file_path, 'wb');
16891690

@@ -1771,11 +1772,11 @@ public function Text()
17711772

17721773
public function Caption()
17731774
{
1774-
$type = $this->getUpdateType();
1775-
if ($type == self::CHANNEL_POST) {
1776-
return @$this->data['channel_post']['caption'];
1777-
}
1778-
return @$this->data['message']['caption'];
1775+
$type = $this->getUpdateType();
1776+
if ($type == self::CHANNEL_POST) {
1777+
return @$this->data['channel_post']['caption'];
1778+
}
1779+
return @$this->data['message']['caption'];
17791780
}
17801781

17811782
/// Get the chat_id of the current message
@@ -1945,8 +1946,11 @@ public function LastName()
19451946
if ($type == self::EDITED_MESSAGE) {
19461947
return @$this->data['edited_message']['from']['last_name'];
19471948
}
1949+
if ($type == self::MESSAGE) {
1950+
return @$this->data['message']['from']['last_name'];
1951+
}
19481952

1949-
return @$this->data['message']['from']['last_name'];
1953+
return '';
19501954
}
19511955

19521956
/// Get the username of the user
@@ -2037,6 +2041,7 @@ public function messageFromGroupTitle()
20372041
if ($this->data['message']['chat']['type'] != 'private') {
20382042
return $this->data['message']['chat']['title'];
20392043
}
2044+
return '';
20402045
}
20412046

20422047
/// Set a custom keyboard
@@ -2051,10 +2056,10 @@ public function messageFromGroupTitle()
20512056
public function buildKeyBoard(array $options, $onetime = false, $resize = false, $selective = true)
20522057
{
20532058
$replyMarkup = [
2054-
'keyboard' => $options,
2059+
'keyboard' => $options,
20552060
'one_time_keyboard' => $onetime,
2056-
'resize_keyboard' => $resize,
2057-
'selective' => $selective,
2061+
'resize_keyboard' => $resize,
2062+
'selective' => $selective,
20582063
];
20592064
$encodedMarkup = json_encode($replyMarkup, true);
20602065

@@ -2089,8 +2094,15 @@ public function buildInlineKeyBoard(array $options)
20892094
* \param $pay Boolean Optional. Specify True, to send a <a href="https://core.telegram.org/bots/api#payments">Pay button</a>.
20902095
* \return the requested button as Array.
20912096
*/
2092-
public function buildInlineKeyboardButton($text, $url = '', $callback_data = '', $switch_inline_query = null, $switch_inline_query_current_chat = null, $callback_game = '', $pay = '')
2093-
{
2097+
public function buildInlineKeyboardButton(
2098+
$text,
2099+
$url = '',
2100+
$callback_data = '',
2101+
$switch_inline_query = null,
2102+
$switch_inline_query_current_chat = null,
2103+
$callback_game = '',
2104+
$pay = ''
2105+
) {
20942106
$replyMarkup = [
20952107
'text' => $text,
20962108
];
@@ -2122,8 +2134,8 @@ public function buildInlineKeyboardButton($text, $url = '', $callback_data = '',
21222134
public function buildKeyboardButton($text, $request_contact = false, $request_location = false)
21232135
{
21242136
$replyMarkup = [
2125-
'text' => $text,
2126-
'request_contact' => $request_contact,
2137+
'text' => $text,
2138+
'request_contact' => $request_contact,
21272139
'request_location' => $request_location,
21282140
];
21292141

@@ -2140,7 +2152,7 @@ public function buildKeyBoardHide($selective = true)
21402152
{
21412153
$replyMarkup = [
21422154
'remove_keyboard' => true,
2143-
'selective' => $selective,
2155+
'selective' => $selective,
21442156
];
21452157
$encodedMarkup = json_encode($replyMarkup, true);
21462158

@@ -2156,7 +2168,7 @@ public function buildForceReply($selective = true)
21562168
{
21572169
$replyMarkup = [
21582170
'force_reply' => true,
2159-
'selective' => $selective,
2171+
'selective' => $selective,
21602172
];
21612173
$encodedMarkup = json_encode($replyMarkup, true);
21622174

@@ -3075,7 +3087,7 @@ public function getUpdates($offset = 0, $limit = 100, $timeout = 0, $update = tr
30753087
$content = ['offset' => $offset, 'limit' => $limit, 'timeout' => $timeout];
30763088
$this->updates = $this->endpoint('getUpdates', $content);
30773089
if ($update) {
3078-
if (is_array($this->updates['result']) && count($this->updates['result']) >= 1) { //for CLI working.
3090+
if (array_key_exists('result', $this->updates) && is_array($this->updates['result']) && count($this->updates['result']) >= 1) { //for CLI working.
30793091
$last_element_id = $this->updates['result'][count($this->updates['result']) - 1]['update_id'] + 1;
30803092
$content = ['offset' => $last_element_id, 'limit' => '1', 'timeout' => $timeout];
30813093
$this->endpoint('getUpdates', $content);
@@ -3141,9 +3153,9 @@ public function getUpdateType()
31413153
if (isset($update['message']['animation'])) {
31423154
return self::ANIMATION;
31433155
}
3144-
if (isset($update['message']['sticker'])) {
3156+
if (isset($update['message']['sticker'])) {
31453157
return self::STICKER;
3146-
}
3158+
}
31473159
if (isset($update['message']['document'])) {
31483160
return self::DOCUMENT;
31493161
}
@@ -3157,7 +3169,7 @@ public function getUpdateType()
31573169
private function sendAPIRequest($url, array $content, $post = true)
31583170
{
31593171
if (isset($content['chat_id'])) {
3160-
$url = $url.'?chat_id='.$content['chat_id'];
3172+
$url = $url . '?chat_id=' . $content['chat_id'];
31613173
unset($content['chat_id']);
31623174
}
31633175
$ch = curl_init();
@@ -3192,7 +3204,9 @@ private function sendAPIRequest($url, array $content, $post = true)
31923204
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
31933205
$result = curl_exec($ch);
31943206
if ($result === false) {
3195-
$result = json_encode(['ok'=>false, 'curl_error_code' => curl_errno($ch), 'curl_error' => curl_error($ch)]);
3207+
$result = json_encode(
3208+
['ok' => false, 'curl_error_code' => curl_errno($ch), 'curl_error' => curl_error($ch)]
3209+
);
31963210
}
31973211
curl_close($ch);
31983212
if ($this->log_errors) {
@@ -3211,7 +3225,7 @@ private function sendAPIRequest($url, array $content, $post = true)
32113225
function curl_file_create($filename, $mimetype = '', $postname = '')
32123226
{
32133227
return "@$filename;filename="
3214-
.($postname ?: basename($filename))
3215-
.($mimetype ? ";type=$mimetype" : '');
3228+
. ($postname ?: basename($filename))
3229+
. ($mimetype ? ";type=$mimetype" : '');
32163230
}
32173231
}

composer.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "eleirbag89/telegrambotphp",
2+
"name": "lyucean/telegram_bot_php",
33
"description": "A very simple PHP Telegram Bot API",
44
"type": "library",
55
"authors": [
@@ -11,9 +11,11 @@
1111
"license": "MIT",
1212
"minimum-stability": "alpha",
1313
"require": {
14-
"php": ">=5.0"
14+
"php": ">=5.0",
15+
"ext-json": "*",
16+
"ext-curl": "*"
1517
},
1618
"autoload": {
1719
"files": ["Telegram.php", "TelegramErrorLogger.php"]
1820
}
19-
}
21+
}

0 commit comments

Comments
 (0)