@@ -55,6 +55,10 @@ class Telegram
55
55
* Constant for type Contact.
56
56
*/
57
57
const CONTACT = 'contact ' ;
58
+ /**
59
+ * Constant for type Channel Post.
60
+ */
61
+ const CHANNEL_POST = 'channel_post ' ;
58
62
59
63
private $ bot_token = '' ;
60
64
private $ data = [];
@@ -1379,9 +1383,13 @@ public function setData(array $data)
1379
1383
*/
1380
1384
public function Text ()
1381
1385
{
1382
- if ($ this ->getUpdateType () == self ::CALLBACK_QUERY ) {
1386
+ $ type = $ this ->getUpdateType ();
1387
+ if ($ type == self ::CALLBACK_QUERY ) {
1383
1388
return @$ this ->data ['callback_query ' ]['data ' ];
1384
1389
}
1390
+ if ($ type == self ::CHANNEL_POST ) {
1391
+ return @$ this ->data ['channel_post ' ]['text ' ];
1392
+ }
1385
1393
1386
1394
return @$ this ->data ['message ' ]['text ' ];
1387
1395
}
@@ -1398,9 +1406,13 @@ public function Caption()
1398
1406
*/
1399
1407
public function ChatID ()
1400
1408
{
1401
- if ($ this ->getUpdateType () == self ::CALLBACK_QUERY ) {
1409
+ $ type = $ this ->getUpdateType ();
1410
+ if ($ type == self ::CALLBACK_QUERY ) {
1402
1411
return @$ this ->data ['callback_query ' ]['message ' ]['chat ' ]['id ' ];
1403
1412
}
1413
+ if ($ type == self ::CHANNEL_POST ) {
1414
+ return @$ this ->data ['channel_post ' ]['chat ' ]['id ' ];
1415
+ }
1404
1416
1405
1417
return $ this ->data ['message ' ]['chat ' ]['id ' ];
1406
1418
}
@@ -1412,9 +1424,13 @@ public function ChatID()
1412
1424
*/
1413
1425
public function MessageID ()
1414
1426
{
1415
- if ($ this ->getUpdateType () == self ::CALLBACK_QUERY ) {
1427
+ $ type = $ this ->getUpdateType ();
1428
+ if ($ type == self ::CALLBACK_QUERY ) {
1416
1429
return @$ this ->data ['callback_query ' ]['message ' ]['message_id ' ];
1417
1430
}
1431
+ if ($ type == self ::CHANNEL_POST ) {
1432
+ return @$ this ->data ['channel_post ' ]['message_id ' ];
1433
+ }
1418
1434
1419
1435
return $ this ->data ['message ' ]['message_id ' ];
1420
1436
}
@@ -1472,6 +1488,7 @@ public function Callback_ID()
1472
1488
/// Get the Get the data of the current callback
1473
1489
1474
1490
/**
1491
+ * \deprecated Use Text() instead
1475
1492
* \return the String callback_data.
1476
1493
*/
1477
1494
public function Callback_Data ()
@@ -1492,6 +1509,7 @@ public function Callback_Message()
1492
1509
/// Get the Get the chati_id of the current callback
1493
1510
1494
1511
/**
1512
+ * \deprecated Use ChatId() instead
1495
1513
* \return the String callback_query.
1496
1514
*/
1497
1515
public function Callback_ChatID ()
@@ -1512,29 +1530,41 @@ public function Date()
1512
1530
/// Get the first name of the user
1513
1531
public function FirstName ()
1514
1532
{
1515
- if ($ this ->getUpdateType () == self ::CALLBACK_QUERY ) {
1533
+ $ type = $ this ->getUpdateType ();
1534
+ if ($ type == self ::CALLBACK_QUERY ) {
1516
1535
return @$ this ->data ['callback_query ' ]['from ' ]['first_name ' ];
1517
1536
}
1537
+ if ($ type == self ::CHANNEL_POST ) {
1538
+ return @$ this ->data ['channel_post ' ]['from ' ]['first_name ' ];
1539
+ }
1518
1540
1519
1541
return @$ this ->data ['message ' ]['from ' ]['first_name ' ];
1520
1542
}
1521
1543
1522
1544
/// Get the last name of the user
1523
1545
public function LastName ()
1524
1546
{
1525
- if ($ this ->getUpdateType () == self ::CALLBACK_QUERY ) {
1547
+ $ type = $ this ->getUpdateType ();
1548
+ if ($ type == self ::CALLBACK_QUERY ) {
1526
1549
return @$ this ->data ['callback_query ' ]['from ' ]['last_name ' ];
1527
1550
}
1551
+ if ($ type == self ::CHANNEL_POST ) {
1552
+ return @$ this ->data ['channel_post ' ]['from ' ]['last_name ' ];
1553
+ }
1528
1554
1529
1555
return @$ this ->data ['message ' ]['from ' ]['last_name ' ];
1530
1556
}
1531
1557
1532
1558
/// Get the username of the user
1533
1559
public function Username ()
1534
1560
{
1535
- if ($ this ->getUpdateType () == self ::CALLBACK_QUERY ) {
1561
+ $ type = $ this ->getUpdateType ();
1562
+ if ($ type == self ::CALLBACK_QUERY ) {
1536
1563
return @$ this ->data ['callback_query ' ]['from ' ]['username ' ];
1537
1564
}
1565
+ if ($ type == self ::CHANNEL_POST ) {
1566
+ return @$ this ->data ['channel_post ' ]['from ' ]['username ' ];
1567
+ }
1538
1568
1539
1569
return @$ this ->data ['message ' ]['from ' ]['username ' ];
1540
1570
}
@@ -1560,9 +1590,13 @@ public function UpdateCount()
1560
1590
/// Get user's id of current message
1561
1591
public function UserID ()
1562
1592
{
1563
- if ($ this ->getUpdateType () == self ::CALLBACK_QUERY ) {
1593
+ $ type = $ this ->getUpdateType ();
1594
+ if ($ type == self ::CALLBACK_QUERY ) {
1564
1595
return $ this ->data ['callback_query ' ]['from ' ]['id ' ];
1565
1596
}
1597
+ if ($ type == self ::CHANNEL_POST ) {
1598
+ return $ this ->data ['channel_post ' ]['from ' ]['id ' ];
1599
+ }
1566
1600
1567
1601
return $ this ->data ['message ' ]['from ' ]['id ' ];
1568
1602
}
@@ -2698,6 +2732,9 @@ public function getUpdateType()
2698
2732
if (isset ($ update ['message ' ]['location ' ])) {
2699
2733
return self ::LOCATION ;
2700
2734
}
2735
+ if (isset ($ update ['channel_post ' ])) {
2736
+ return self ::CHANNEL_POST ;
2737
+ }
2701
2738
2702
2739
return false ;
2703
2740
}
0 commit comments