Skip to content

Commit

Permalink
Fix webhook receive
Browse files Browse the repository at this point in the history
  • Loading branch information
Muaath5 committed Oct 8, 2021
1 parent 0a50044 commit 2b899e7
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/TelegramBot.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,20 @@ public function OnWebhookUpdate() : bool
$Update = json_decode(file_get_contents('php://input'));
if (empty($Update))
{
error_log("Empty update");
http_response_code(400);
return false;
}

if ($this->Settings->AutoHandleDuplicateUpdates)
{
# If sooner than 2 weeks
if ($this->Settings->LastUpdateDate < strtotime('-2 week'))
if ($this->Settings->LastUpdateDate > strtotime('-2 week'))
{
if ($this->Settings->LastUpdateID >= $Update->update_id)
{
// This update is fake or duplicate by ID
error_log("Last update ID ({$this->Settings->LastUpdateID}) >= Receieved update ID ({$Update->update_id})");
http_response_code(400);
return false;
}
Expand All @@ -165,6 +167,7 @@ public function OnWebhookUpdate() : bool
if ($_GET['token_hash'] != hash($this->HashingMethod, $this->Token))
{
# Fake update
error_log("Unauthorized, Received token_hash={$_GET['token_hash']}");
http_response_code(401);
return false;
}
Expand Down

0 comments on commit 2b899e7

Please sign in to comment.