Skip to content

Commit

Permalink
Add new event: channel, edited_edited and New debug ouput
Browse files Browse the repository at this point in the history
  • Loading branch information
radyakaze committed Nov 29, 2016
1 parent e717cfa commit 37b5553
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ $bot->on('sticker|photo|document', function() {
- **inline** - inline message
- **callback** - callback message
- **game** - game
- **channel** - channel
- **edited_channel** - edited channel post

## Command with custom regex *(advanced)*

Expand All @@ -201,7 +203,7 @@ Handles events.
##### `regex(<regex>, <answer>)`
Create custom regex for command.
##### `Bot::type()`
Return [message event](#message-events) type.
Return [message event](#supported-events) type.
##### `Bot::message()`
Get [message properties](https://core.telegram.org/bots/api#message).

Expand Down
23 changes: 23 additions & 0 deletions src/Bot.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ class Bot
*
* @return array|bool
*/

/**
* Bot debug
* @var array
*/
public static $debug = '';

public static function send($action = 'sendMessage', $data = [])
{
$upload = false;
Expand Down Expand Up @@ -82,6 +89,12 @@ public static function send($action = 'sendMessage', $data = [])
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if (PHPTelebot::$debug && $action != 'getUpdates') {
self::$debug .= 'Method: '.$action."\n";
self::$debug .= 'Data: '.str_replace("Array\n", '', print_r($data, true))."\n";
self::$debug .= 'Response: '.$result."\n";
}

if ($httpcode == 401) {
throw new Exception('Incorect bot token');

Expand Down Expand Up @@ -170,6 +183,12 @@ public static function message()
return $get['inline_query'];
} elseif (isset($get['edited_message'])) {
return $get['edited_message'];
} elseif (isset($get['channel_post'])) {
return $get['channel_post'];
} elseif (isset($get['edited_channel_post'])) {
return $get['edited_channel_post'];
} else {
return [];
}
}

Expand Down Expand Up @@ -228,6 +247,10 @@ public static function type()
return 'edited';
} elseif (isset($getUpdates['message']['game'])) {
return 'game';
} elseif (isset($getUpdates['channel_post'])) {
return 'channel';
} elseif (isset($getUpdates['edited_channel_post'])) {
return 'edited_channel';
} else {
return 'unknown';
}
Expand Down
9 changes: 6 additions & 3 deletions src/PHPTelebot.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ class PHPTelebot
*
* @var bool
*/
protected static $debug = true;
public static $debug = true;

/**
* PHPTelebot version.
*
* @var string
*/
protected static $version = '1.1';
protected static $version = '1.3';

/**
* PHPTelebot Constructor.
Expand Down Expand Up @@ -186,9 +186,12 @@ private function longPoll()
if (!empty($req['result'])) {
foreach ($req['result'] as $update) {
self::$getUpdates = $update;
$response = $this->process();
$process = $this->process();

if (self::$debug) {
$response = Bot::$debug?: $process;
// reset debug
Bot::$debug = '';
$line = "\n--------------------\n";
$outputFormat = "$line %s $update[update_id] $line%s";
echo sprintf($outputFormat, 'Query ID :', json_encode($update));
Expand Down

0 comments on commit 37b5553

Please sign in to comment.