Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Crashpad received a malformed value as an update. #11

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/CrashPad.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static function enableCrashHandler(): void
{
$handler = function (Throwable $throwable) {
if (Telegram::getAdminId() !== -1) {
$input = getenv('TG_CURRENT_UPDATE') ?? Telegram::getInput();
$input = Telegram::getInput();
CrashPad::sendCrash(Telegram::getAdminId(), $throwable, $input);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Entities/InlineKeyboardButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ class InlineKeyboardButton extends KeyboardButton
/**
* Creates instance of InlineKeyboardButton
*
* @param string $string
* @param string|null $label
* @return InlineKeyboardButton
*/
public static function make(string $string): InlineKeyboardButton
public static function make(string|null $label = null): InlineKeyboardButton
{
return new self($string);
return new self($label);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Entities/KeyboardButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ public function __construct($data)
$data = ['text' => $data];
}

parent::__construct($data);
parent::__construct($data ?? []);
}

/**
* Creates instance of KeyboardButton
*
* @param string $string
* @param string|null $label
* @return KeyboardButton
*/
public static function make(string $string): KeyboardButton
public static function make(string|null $label = null): KeyboardButton
{
return new self($string);
return new self($label);
}

/**
Expand Down
12 changes: 11 additions & 1 deletion src/Telegram.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,17 @@ public static function getUpdate(): Update|null
*/
public static function getInput(): string|null
{
return file_get_contents('php://input') ?? null;
$input = file_get_contents('php://input');
if (!empty($input)) {
return $input;
}

$env = getenv('TG_CURRENT_UPDATE');
if (!empty($env) && is_string($env)) {
return $env;
}

return null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/KeyboardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@ public function test_create_for_answer_query(): void
$this->assertEquals(json_encode($raw_data), $result['options']['query']['reply_markup']);
}

}
}
Loading