irazasyed / telegram-bot-sdk

🤖 Telegram Bot API PHP SDK. Lets you build Telegram Bots easily! Supports Laravel out of the box.
https://telegram-bot-sdk.com
BSD 3-Clause "New" or "Revised" License
3.04k stars 671 forks source link

The Telegram::getWebhookUpdate() result always empty array [] #1097

Closed untillnesss closed 8 months ago

untillnesss commented 1 year ago

PHP version

PHP 8.2

irazasyed/telegram-bot-sdk version

versions : * v3.13.0

Laravel version (if any)

versions : * v10.25.2

Code To Reproduce the bug

image

I have code like the one above, namely the code to run the webhook sent by Telegram, but the result is always an empty array.

image

I have checked the Telegram Bot token many times, there is nothing wrong, it is correct, and I have installed the webhook URL properly.

Is there anything I missed?

Error stacktrace (if any)

No response

Freezon commented 12 months ago

I had the same problem) Steps to fix:

  1. Require psr-7 requests, from src: https://laravel.com/docs/10.x/requests#psr7-requests
  2. Pass request, like this:
    public function __invoke(ServerRequestInterface $request)
    {
    $update = Telegram::getWebhookUpdate(request: $request);
    }
riettotek commented 9 months ago

doesnt work anyway. even installing psr7 request interface. nothing at all!!!

irazasyed commented 8 months ago

Method signature is getWebhookUpdate(bool $shouldDispatchEvents = true, ?RequestInterface $request = null).

Behind the scene it relies on file_get_contents('php://input') to retrieve the REQUEST body sent from Telegram, so you need to use this method directly within your webhook where this gets invoked or if you wish to wrap it inside other classes/methods, then pass the PSR7 Request.