@@ -79,12 +79,17 @@ class Telegram
79
79
* Constant for type Left Chat Member.
80
80
*/
81
81
const LEFT_CHAT_MEMBER = 'left_chat_member ' ;
82
+ /**
83
+ * Constant for type My Chat Member.
84
+ */
85
+ const MY_CHAT_MEMBER = 'my_chat_member ' ;
82
86
83
87
private $ bot_token = '' ;
84
88
private $ data = [];
85
89
private $ updates = [];
86
90
private $ log_errors ;
87
91
private $ proxy ;
92
+ private $ update_type ;
88
93
89
94
/// Class constructor
90
95
@@ -114,7 +119,7 @@ public function __construct($bot_token, $log_errors = true, array $proxy = [])
114
119
*/
115
120
public function endpoint ($ api , array $ content , $ post = true )
116
121
{
117
- $ url = 'https://api.telegram.org/bot ' . $ this ->bot_token . '/ ' . $ api ;
122
+ $ url = 'https://api.telegram.org/bot ' . $ this ->bot_token . '/ ' . $ api ;
118
123
if ($ post ) {
119
124
$ reply = $ this ->sendAPIRequest ($ url , $ content );
120
125
} else {
@@ -736,7 +741,7 @@ public function stopPoll(array $content)
736
741
*/
737
742
public function downloadFile ($ telegram_file_path , $ local_file_path )
738
743
{
739
- $ 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 ;
740
745
$ in = fopen ($ file_url , 'rb ' );
741
746
$ out = fopen ($ local_file_path , 'wb ' );
742
747
@@ -838,22 +843,34 @@ public function Caption()
838
843
* \return the String users's chat_id.
839
844
*/
840
845
public function ChatID ()
846
+ {
847
+ $ chat = $ this ->Chat ();
848
+ return $ chat ['id ' ];
849
+ }
850
+
851
+ /**
852
+ * \return the Array chat.
853
+ */
854
+ public function Chat ()
841
855
{
842
856
$ type = $ this ->getUpdateType ();
843
857
if ($ type == self ::CALLBACK_QUERY ) {
844
- return @$ this ->data ['callback_query ' ]['message ' ]['chat ' ][ ' id ' ] ;
858
+ return @$ this ->data ['callback_query ' ]['message ' ]['chat ' ];
845
859
}
846
860
if ($ type == self ::CHANNEL_POST ) {
847
- return @$ this ->data ['channel_post ' ]['chat ' ][ ' id ' ] ;
861
+ return @$ this ->data ['channel_post ' ]['chat ' ];
848
862
}
849
863
if ($ type == self ::EDITED_MESSAGE ) {
850
- return @$ this ->data ['edited_message ' ]['chat ' ][ ' id ' ] ;
864
+ return @$ this ->data ['edited_message ' ]['chat ' ];
851
865
}
852
866
if ($ type == self ::INLINE_QUERY ) {
853
- return @$ this ->data ['inline_query ' ]['from ' ]['id ' ];
867
+ return @$ this ->data ['inline_query ' ]['from ' ];
868
+ }
869
+ if ($ type == self ::MY_CHAT_MEMBER ) {
870
+ return @$ this ->data ['my_chat_member ' ]['chat ' ];
854
871
}
855
872
856
- return $ this ->data ['message ' ]['chat ' ][ ' id ' ] ;
873
+ return $ this ->data ['message ' ]['chat ' ];
857
874
}
858
875
859
876
/// Get the message_id of the current message
@@ -1095,6 +1112,7 @@ public function messageFromGroup()
1095
1112
}
1096
1113
1097
1114
/// Get the contact phone number
1115
+
1098
1116
/**
1099
1117
* \return a String of the contact phone number.
1100
1118
*/
@@ -1133,10 +1151,10 @@ public function messageFromGroupTitle()
1133
1151
public function buildKeyBoard (array $ options , $ onetime = false , $ resize = false , $ selective = true )
1134
1152
{
1135
1153
$ replyMarkup = [
1136
- 'keyboard ' => $ options ,
1154
+ 'keyboard ' => $ options ,
1137
1155
'one_time_keyboard ' => $ onetime ,
1138
- 'resize_keyboard ' => $ resize ,
1139
- 'selective ' => $ selective ,
1156
+ 'resize_keyboard ' => $ resize ,
1157
+ 'selective ' => $ selective ,
1140
1158
];
1141
1159
$ encodedMarkup = json_encode ($ replyMarkup , true );
1142
1160
@@ -1179,7 +1197,8 @@ public function buildInlineKeyboardButton(
1179
1197
$ switch_inline_query_current_chat = null ,
1180
1198
$ callback_game = '' ,
1181
1199
$ pay = ''
1182
- ) {
1200
+ )
1201
+ {
1183
1202
$ replyMarkup = [
1184
1203
'text ' => $ text ,
1185
1204
];
@@ -1211,8 +1230,8 @@ public function buildInlineKeyboardButton(
1211
1230
public function buildKeyboardButton ($ text , $ request_contact = false , $ request_location = false )
1212
1231
{
1213
1232
$ replyMarkup = [
1214
- 'text ' => $ text ,
1215
- 'request_contact ' => $ request_contact ,
1233
+ 'text ' => $ text ,
1234
+ 'request_contact ' => $ request_contact ,
1216
1235
'request_location ' => $ request_location ,
1217
1236
];
1218
1237
@@ -1229,7 +1248,7 @@ public function buildKeyBoardHide($selective = true)
1229
1248
{
1230
1249
$ replyMarkup = [
1231
1250
'remove_keyboard ' => true ,
1232
- 'selective ' => $ selective ,
1251
+ 'selective ' => $ selective ,
1233
1252
];
1234
1253
$ encodedMarkup = json_encode ($ replyMarkup , true );
1235
1254
@@ -1245,7 +1264,7 @@ public function buildForceReply($selective = true)
1245
1264
{
1246
1265
$ replyMarkup = [
1247
1266
'force_reply ' => true ,
1248
- 'selective ' => $ selective ,
1267
+ 'selective ' => $ selective ,
1249
1268
];
1250
1269
$ encodedMarkup = json_encode ($ replyMarkup , true );
1251
1270
@@ -1692,57 +1711,82 @@ public function serveUpdate($update)
1692
1711
*/
1693
1712
public function getUpdateType ()
1694
1713
{
1714
+ if ($ this ->update_type ) {
1715
+ return $ this ->update_type ;
1716
+ }
1717
+
1695
1718
$ update = $ this ->data ;
1696
1719
if (isset ($ update ['inline_query ' ])) {
1697
- return self ::INLINE_QUERY ;
1720
+ $ this ->update_type = self ::INLINE_QUERY ;
1721
+ return $ this ->update_type ;
1698
1722
}
1699
1723
if (isset ($ update ['callback_query ' ])) {
1700
- return self ::CALLBACK_QUERY ;
1724
+ $ this ->update_type = self ::CALLBACK_QUERY ;
1725
+ return $ this ->update_type ;
1701
1726
}
1702
1727
if (isset ($ update ['edited_message ' ])) {
1703
- return self ::EDITED_MESSAGE ;
1728
+ $ this ->update_type = self ::EDITED_MESSAGE ;
1729
+ return $ this ->update_type ;
1704
1730
}
1705
1731
if (isset ($ update ['message ' ]['text ' ])) {
1706
- return self ::MESSAGE ;
1732
+ $ this ->update_type = self ::MESSAGE ;
1733
+ return $ this ->update_type ;
1707
1734
}
1708
1735
if (isset ($ update ['message ' ]['photo ' ])) {
1709
- return self ::PHOTO ;
1736
+ $ this ->update_type = self ::PHOTO ;
1737
+ return $ this ->update_type ;
1710
1738
}
1711
1739
if (isset ($ update ['message ' ]['video ' ])) {
1712
- return self ::VIDEO ;
1740
+ $ this ->update_type = self ::VIDEO ;
1741
+ return $ this ->update_type ;
1713
1742
}
1714
1743
if (isset ($ update ['message ' ]['audio ' ])) {
1715
- return self ::AUDIO ;
1744
+ $ this ->update_type = self ::AUDIO ;
1745
+ return $ this ->update_type ;
1716
1746
}
1717
1747
if (isset ($ update ['message ' ]['voice ' ])) {
1718
- return self ::VOICE ;
1748
+ $ this ->update_type = self ::VOICE ;
1749
+ return $ this ->update_type ;
1719
1750
}
1720
1751
if (isset ($ update ['message ' ]['contact ' ])) {
1721
- return self ::CONTACT ;
1752
+ $ this ->update_type = self ::CONTACT ;
1753
+ return $ this ->update_type ;
1722
1754
}
1723
1755
if (isset ($ update ['message ' ]['location ' ])) {
1724
- return self ::LOCATION ;
1756
+ $ this ->update_type = self ::LOCATION ;
1757
+ return $ this ->update_type ;
1725
1758
}
1726
1759
if (isset ($ update ['message ' ]['reply_to_message ' ])) {
1727
- return self ::REPLY ;
1760
+ $ this ->update_type = self ::REPLY ;
1761
+ return $ this ->update_type ;
1728
1762
}
1729
1763
if (isset ($ update ['message ' ]['animation ' ])) {
1730
- return self ::ANIMATION ;
1764
+ $ this ->update_type = self ::ANIMATION ;
1765
+ return $ this ->update_type ;
1731
1766
}
1732
1767
if (isset ($ update ['message ' ]['sticker ' ])) {
1733
- return self ::STICKER ;
1768
+ $ this ->update_type = self ::STICKER ;
1769
+ return $ this ->update_type ;
1734
1770
}
1735
1771
if (isset ($ update ['message ' ]['document ' ])) {
1736
- return self ::DOCUMENT ;
1772
+ $ this ->update_type = self ::DOCUMENT ;
1773
+ return $ this ->update_type ;
1737
1774
}
1738
1775
if (isset ($ update ['message ' ]['new_chat_member ' ])) {
1739
- return self ::NEW_CHAT_MEMBER ;
1776
+ $ this ->update_type = self ::NEW_CHAT_MEMBER ;
1777
+ return $ this ->update_type ;
1740
1778
}
1741
1779
if (isset ($ update ['message ' ]['left_chat_member ' ])) {
1742
- return self ::LEFT_CHAT_MEMBER ;
1780
+ $ this ->update_type = self ::LEFT_CHAT_MEMBER ;
1781
+ return $ this ->update_type ;
1782
+ }
1783
+ if (isset ($ update ['my_chat_member ' ])) {
1784
+ $ this ->update_type = self ::MY_CHAT_MEMBER ;
1785
+ return $ this ->update_type ;
1743
1786
}
1744
1787
if (isset ($ update ['channel_post ' ])) {
1745
- return self ::CHANNEL_POST ;
1788
+ $ this ->update_type = self ::CHANNEL_POST ;
1789
+ return $ this ->update_type ;
1746
1790
}
1747
1791
1748
1792
return false ;
@@ -1751,7 +1795,7 @@ public function getUpdateType()
1751
1795
private function sendAPIRequest ($ url , array $ content , $ post = true )
1752
1796
{
1753
1797
if (isset ($ content ['chat_id ' ])) {
1754
- $ url = $ url. '?chat_id= ' . $ content ['chat_id ' ];
1798
+ $ url = $ url . '?chat_id= ' . $ content ['chat_id ' ];
1755
1799
unset($ content ['chat_id ' ]);
1756
1800
}
1757
1801
$ ch = curl_init ();
@@ -1807,7 +1851,7 @@ private function sendAPIRequest($url, array $content, $post = true)
1807
1851
function curl_file_create ($ filename , $ mimetype = '' , $ postname = '' )
1808
1852
{
1809
1853
return "@ $ filename;filename= "
1810
- .($ postname ?: basename ($ filename ))
1811
- .($ mimetype ? ";type= $ mimetype " : '' );
1854
+ . ($ postname ?: basename ($ filename ))
1855
+ . ($ mimetype ? ";type= $ mimetype " : '' );
1812
1856
}
1813
1857
}
0 commit comments