Skip to content

Commit da89c90

Browse files
committed
Adapt functions to deal with channel, API update
1 parent 9b1993a commit da89c90

File tree

2 files changed

+47
-10
lines changed

2 files changed

+47
-10
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# TelegramBotPHP
2-
[![API](https://img.shields.io/badge/Telegram%20Bot%20API-July%2021%2C%202017-36ade1.svg)](https://core.telegram.org/bots/api)
2+
[![API](https://img.shields.io/badge/Telegram%20Bot%20API-August%2023%2C%202017-36ade1.svg)](https://core.telegram.org/bots/api)
33
![PHP](https://img.shields.io/badge/php-%3E%3D5.3-8892bf.svg)
44
![CURL](https://img.shields.io/badge/cURL-required-green.svg)
55

66
[![Total Downloads](https://poser.pugx.org/eleirbag89/telegrambotphp/downloads)](https://packagist.org/packages/eleirbag89/telegrambotphp)
77
[![License](https://poser.pugx.org/eleirbag89/telegrambotphp/license)](https://packagist.org/packages/eleirbag89/telegrambotphp)
88
[![StyleCI](https://styleci.io/repos/38492095/shield?branch=master)](https://styleci.io/repos/38492095)
99

10-
> A very simple PHP [Telegram Bot API](https://core.telegram.org/bots) for sending messages.
11-
> (Almost) Compliant with the July 21, 2017 Telegram Bot API update.
10+
> A very simple PHP [Telegram Bot API](https://core.telegram.org/bots).
11+
> Compliant with the August 23, 2017 Telegram Bot API update.
1212
1313
Requirements
1414
---------

Telegram.php

+44-7
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ class Telegram
5555
* Constant for type Contact.
5656
*/
5757
const CONTACT = 'contact';
58+
/**
59+
* Constant for type Channel Post.
60+
*/
61+
const CHANNEL_POST = 'channel_post';
5862

5963
private $bot_token = '';
6064
private $data = [];
@@ -1379,9 +1383,13 @@ public function setData(array $data)
13791383
*/
13801384
public function Text()
13811385
{
1382-
if ($this->getUpdateType() == self::CALLBACK_QUERY) {
1386+
$type = $this->getUpdateType();
1387+
if ($type == self::CALLBACK_QUERY) {
13831388
return @$this->data['callback_query']['data'];
13841389
}
1390+
if ($type == self::CHANNEL_POST) {
1391+
return @$this->data['channel_post']['text'];
1392+
}
13851393

13861394
return @$this->data['message']['text'];
13871395
}
@@ -1398,9 +1406,13 @@ public function Caption()
13981406
*/
13991407
public function ChatID()
14001408
{
1401-
if ($this->getUpdateType() == self::CALLBACK_QUERY) {
1409+
$type = $this->getUpdateType();
1410+
if ($type == self::CALLBACK_QUERY) {
14021411
return @$this->data['callback_query']['message']['chat']['id'];
14031412
}
1413+
if ($type == self::CHANNEL_POST) {
1414+
return @$this->data['channel_post']['chat']['id'];
1415+
}
14041416

14051417
return $this->data['message']['chat']['id'];
14061418
}
@@ -1412,9 +1424,13 @@ public function ChatID()
14121424
*/
14131425
public function MessageID()
14141426
{
1415-
if ($this->getUpdateType() == self::CALLBACK_QUERY) {
1427+
$type = $this->getUpdateType();
1428+
if ($type == self::CALLBACK_QUERY) {
14161429
return @$this->data['callback_query']['message']['message_id'];
14171430
}
1431+
if ($type == self::CHANNEL_POST) {
1432+
return @$this->data['channel_post']['message_id'];
1433+
}
14181434

14191435
return $this->data['message']['message_id'];
14201436
}
@@ -1472,6 +1488,7 @@ public function Callback_ID()
14721488
/// Get the Get the data of the current callback
14731489

14741490
/**
1491+
* \deprecated Use Text() instead
14751492
* \return the String callback_data.
14761493
*/
14771494
public function Callback_Data()
@@ -1492,6 +1509,7 @@ public function Callback_Message()
14921509
/// Get the Get the chati_id of the current callback
14931510

14941511
/**
1512+
* \deprecated Use ChatId() instead
14951513
* \return the String callback_query.
14961514
*/
14971515
public function Callback_ChatID()
@@ -1512,29 +1530,41 @@ public function Date()
15121530
/// Get the first name of the user
15131531
public function FirstName()
15141532
{
1515-
if ($this->getUpdateType() == self::CALLBACK_QUERY) {
1533+
$type = $this->getUpdateType();
1534+
if ($type == self::CALLBACK_QUERY) {
15161535
return @$this->data['callback_query']['from']['first_name'];
15171536
}
1537+
if ($type == self::CHANNEL_POST) {
1538+
return @$this->data['channel_post']['from']['first_name'];
1539+
}
15181540

15191541
return @$this->data['message']['from']['first_name'];
15201542
}
15211543

15221544
/// Get the last name of the user
15231545
public function LastName()
15241546
{
1525-
if ($this->getUpdateType() == self::CALLBACK_QUERY) {
1547+
$type = $this->getUpdateType();
1548+
if ($type == self::CALLBACK_QUERY) {
15261549
return @$this->data['callback_query']['from']['last_name'];
15271550
}
1551+
if ($type == self::CHANNEL_POST) {
1552+
return @$this->data['channel_post']['from']['last_name'];
1553+
}
15281554

15291555
return @$this->data['message']['from']['last_name'];
15301556
}
15311557

15321558
/// Get the username of the user
15331559
public function Username()
15341560
{
1535-
if ($this->getUpdateType() == self::CALLBACK_QUERY) {
1561+
$type = $this->getUpdateType();
1562+
if ($type == self::CALLBACK_QUERY) {
15361563
return @$this->data['callback_query']['from']['username'];
15371564
}
1565+
if ($type == self::CHANNEL_POST) {
1566+
return @$this->data['channel_post']['from']['username'];
1567+
}
15381568

15391569
return @$this->data['message']['from']['username'];
15401570
}
@@ -1560,9 +1590,13 @@ public function UpdateCount()
15601590
/// Get user's id of current message
15611591
public function UserID()
15621592
{
1563-
if ($this->getUpdateType() == self::CALLBACK_QUERY) {
1593+
$type = $this->getUpdateType();
1594+
if ($type == self::CALLBACK_QUERY) {
15641595
return $this->data['callback_query']['from']['id'];
15651596
}
1597+
if ($type == self::CHANNEL_POST) {
1598+
return $this->data['channel_post']['from']['id'];
1599+
}
15661600

15671601
return $this->data['message']['from']['id'];
15681602
}
@@ -2698,6 +2732,9 @@ public function getUpdateType()
26982732
if (isset($update['message']['location'])) {
26992733
return self::LOCATION;
27002734
}
2735+
if (isset($update['channel_post'])) {
2736+
return self::CHANNEL_POST;
2737+
}
27012738

27022739
return false;
27032740
}

0 commit comments

Comments
 (0)