@@ -89,6 +89,7 @@ class Telegram
89
89
private $ updates = [];
90
90
private $ log_errors ;
91
91
private $ proxy ;
92
+ private $ update_type ;
92
93
93
94
/// Class constructor
94
95
@@ -118,7 +119,7 @@ public function __construct($bot_token, $log_errors = true, array $proxy = [])
118
119
*/
119
120
public function endpoint ($ api , array $ content , $ post = true )
120
121
{
121
- $ url = 'https://api.telegram.org/bot ' . $ this ->bot_token . '/ ' . $ api ;
122
+ $ url = 'https://api.telegram.org/bot ' . $ this ->bot_token . '/ ' . $ api ;
122
123
if ($ post ) {
123
124
$ reply = $ this ->sendAPIRequest ($ url , $ content );
124
125
} else {
@@ -740,7 +741,7 @@ public function stopPoll(array $content)
740
741
*/
741
742
public function downloadFile ($ telegram_file_path , $ local_file_path )
742
743
{
743
- $ file_url = 'https://api.telegram.org/file/bot ' . $ this ->bot_token . '/ ' . $ telegram_file_path ;
744
+ $ file_url = 'https://api.telegram.org/file/bot ' . $ this ->bot_token . '/ ' . $ telegram_file_path ;
744
745
$ in = fopen ($ file_url , 'rb ' );
745
746
$ out = fopen ($ local_file_path , 'wb ' );
746
747
@@ -846,6 +847,7 @@ public function ChatID()
846
847
$ chat = $ this ->Chat ();
847
848
return $ chat ['id ' ];
848
849
}
850
+
849
851
/**
850
852
* \return the Array chat.
851
853
*/
@@ -1110,6 +1112,7 @@ public function messageFromGroup()
1110
1112
}
1111
1113
1112
1114
/// Get the contact phone number
1115
+
1113
1116
/**
1114
1117
* \return a String of the contact phone number.
1115
1118
*/
@@ -1148,10 +1151,10 @@ public function messageFromGroupTitle()
1148
1151
public function buildKeyBoard (array $ options , $ onetime = false , $ resize = false , $ selective = true )
1149
1152
{
1150
1153
$ replyMarkup = [
1151
- 'keyboard ' => $ options ,
1154
+ 'keyboard ' => $ options ,
1152
1155
'one_time_keyboard ' => $ onetime ,
1153
- 'resize_keyboard ' => $ resize ,
1154
- 'selective ' => $ selective ,
1156
+ 'resize_keyboard ' => $ resize ,
1157
+ 'selective ' => $ selective ,
1155
1158
];
1156
1159
$ encodedMarkup = json_encode ($ replyMarkup , true );
1157
1160
@@ -1194,7 +1197,8 @@ public function buildInlineKeyboardButton(
1194
1197
$ switch_inline_query_current_chat = null ,
1195
1198
$ callback_game = '' ,
1196
1199
$ pay = ''
1197
- ) {
1200
+ )
1201
+ {
1198
1202
$ replyMarkup = [
1199
1203
'text ' => $ text ,
1200
1204
];
@@ -1226,8 +1230,8 @@ public function buildInlineKeyboardButton(
1226
1230
public function buildKeyboardButton ($ text , $ request_contact = false , $ request_location = false )
1227
1231
{
1228
1232
$ replyMarkup = [
1229
- 'text ' => $ text ,
1230
- 'request_contact ' => $ request_contact ,
1233
+ 'text ' => $ text ,
1234
+ 'request_contact ' => $ request_contact ,
1231
1235
'request_location ' => $ request_location ,
1232
1236
];
1233
1237
@@ -1244,7 +1248,7 @@ public function buildKeyBoardHide($selective = true)
1244
1248
{
1245
1249
$ replyMarkup = [
1246
1250
'remove_keyboard ' => true ,
1247
- 'selective ' => $ selective ,
1251
+ 'selective ' => $ selective ,
1248
1252
];
1249
1253
$ encodedMarkup = json_encode ($ replyMarkup , true );
1250
1254
@@ -1260,7 +1264,7 @@ public function buildForceReply($selective = true)
1260
1264
{
1261
1265
$ replyMarkup = [
1262
1266
'force_reply ' => true ,
1263
- 'selective ' => $ selective ,
1267
+ 'selective ' => $ selective ,
1264
1268
];
1265
1269
$ encodedMarkup = json_encode ($ replyMarkup , true );
1266
1270
@@ -1707,60 +1711,82 @@ public function serveUpdate($update)
1707
1711
*/
1708
1712
public function getUpdateType ()
1709
1713
{
1714
+ if ($ this ->update_type ) {
1715
+ return $ this ->update_type ;
1716
+ }
1717
+
1710
1718
$ update = $ this ->data ;
1711
1719
if (isset ($ update ['inline_query ' ])) {
1712
- return self ::INLINE_QUERY ;
1720
+ $ this ->update_type = self ::INLINE_QUERY ;
1721
+ return $ this ->update_type ;
1713
1722
}
1714
1723
if (isset ($ update ['callback_query ' ])) {
1715
- return self ::CALLBACK_QUERY ;
1724
+ $ this ->update_type = self ::CALLBACK_QUERY ;
1725
+ return $ this ->update_type ;
1716
1726
}
1717
1727
if (isset ($ update ['edited_message ' ])) {
1718
- return self ::EDITED_MESSAGE ;
1728
+ $ this ->update_type = self ::EDITED_MESSAGE ;
1729
+ return $ this ->update_type ;
1719
1730
}
1720
1731
if (isset ($ update ['message ' ]['text ' ])) {
1721
- return self ::MESSAGE ;
1732
+ $ this ->update_type = self ::MESSAGE ;
1733
+ return $ this ->update_type ;
1722
1734
}
1723
1735
if (isset ($ update ['message ' ]['photo ' ])) {
1724
- return self ::PHOTO ;
1736
+ $ this ->update_type = self ::PHOTO ;
1737
+ return $ this ->update_type ;
1725
1738
}
1726
1739
if (isset ($ update ['message ' ]['video ' ])) {
1727
- return self ::VIDEO ;
1740
+ $ this ->update_type = self ::VIDEO ;
1741
+ return $ this ->update_type ;
1728
1742
}
1729
1743
if (isset ($ update ['message ' ]['audio ' ])) {
1730
- return self ::AUDIO ;
1744
+ $ this ->update_type = self ::AUDIO ;
1745
+ return $ this ->update_type ;
1731
1746
}
1732
1747
if (isset ($ update ['message ' ]['voice ' ])) {
1733
- return self ::VOICE ;
1748
+ $ this ->update_type = self ::VOICE ;
1749
+ return $ this ->update_type ;
1734
1750
}
1735
1751
if (isset ($ update ['message ' ]['contact ' ])) {
1736
- return self ::CONTACT ;
1752
+ $ this ->update_type = self ::CONTACT ;
1753
+ return $ this ->update_type ;
1737
1754
}
1738
1755
if (isset ($ update ['message ' ]['location ' ])) {
1739
- return self ::LOCATION ;
1756
+ $ this ->update_type = self ::LOCATION ;
1757
+ return $ this ->update_type ;
1740
1758
}
1741
1759
if (isset ($ update ['message ' ]['reply_to_message ' ])) {
1742
- return self ::REPLY ;
1760
+ $ this ->update_type = self ::REPLY ;
1761
+ return $ this ->update_type ;
1743
1762
}
1744
1763
if (isset ($ update ['message ' ]['animation ' ])) {
1745
- return self ::ANIMATION ;
1764
+ $ this ->update_type = self ::ANIMATION ;
1765
+ return $ this ->update_type ;
1746
1766
}
1747
1767
if (isset ($ update ['message ' ]['sticker ' ])) {
1748
- return self ::STICKER ;
1768
+ $ this ->update_type = self ::STICKER ;
1769
+ return $ this ->update_type ;
1749
1770
}
1750
1771
if (isset ($ update ['message ' ]['document ' ])) {
1751
- return self ::DOCUMENT ;
1772
+ $ this ->update_type = self ::DOCUMENT ;
1773
+ return $ this ->update_type ;
1752
1774
}
1753
1775
if (isset ($ update ['message ' ]['new_chat_member ' ])) {
1754
- return self ::NEW_CHAT_MEMBER ;
1776
+ $ this ->update_type = self ::NEW_CHAT_MEMBER ;
1777
+ return $ this ->update_type ;
1755
1778
}
1756
1779
if (isset ($ update ['message ' ]['left_chat_member ' ])) {
1757
- return self ::LEFT_CHAT_MEMBER ;
1780
+ $ this ->update_type = self ::LEFT_CHAT_MEMBER ;
1781
+ return $ this ->update_type ;
1758
1782
}
1759
1783
if (isset ($ update ['my_chat_member ' ])) {
1760
- return self ::MY_CHAT_MEMBER ;
1784
+ $ this ->update_type = self ::MY_CHAT_MEMBER ;
1785
+ return $ this ->update_type ;
1761
1786
}
1762
1787
if (isset ($ update ['channel_post ' ])) {
1763
- return self ::CHANNEL_POST ;
1788
+ $ this ->update_type = self ::CHANNEL_POST ;
1789
+ return $ this ->update_type ;
1764
1790
}
1765
1791
1766
1792
return false ;
@@ -1769,7 +1795,7 @@ public function getUpdateType()
1769
1795
private function sendAPIRequest ($ url , array $ content , $ post = true )
1770
1796
{
1771
1797
if (isset ($ content ['chat_id ' ])) {
1772
- $ url = $ url. '?chat_id= ' . $ content ['chat_id ' ];
1798
+ $ url = $ url . '?chat_id= ' . $ content ['chat_id ' ];
1773
1799
unset($ content ['chat_id ' ]);
1774
1800
}
1775
1801
$ ch = curl_init ();
@@ -1825,7 +1851,7 @@ private function sendAPIRequest($url, array $content, $post = true)
1825
1851
function curl_file_create ($ filename , $ mimetype = '' , $ postname = '' )
1826
1852
{
1827
1853
return "@ $ filename;filename= "
1828
- .($ postname ?: basename ($ filename ))
1829
- .($ mimetype ? ";type= $ mimetype " : '' );
1854
+ . ($ postname ?: basename ($ filename ))
1855
+ . ($ mimetype ? ";type= $ mimetype " : '' );
1830
1856
}
1831
1857
}
0 commit comments