telegram-bot-sdk
telegram-bot-sdk copied to clipboard
The Telegram::getWebhookUpdate() result always empty array []
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
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.
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
I had the same problem) Steps to fix:
- Require psr-7 requests, from src: https://laravel.com/docs/10.x/requests#psr7-requests
- Pass request, like this:
public function __invoke(ServerRequestInterface $request)
{
$update = Telegram::getWebhookUpdate(request: $request);
}
doesnt work anyway. even installing psr7 request interface. nothing at all!!!
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.