Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

marcoplus's avatar

laravel telegram bot webhook doesn't it work

I have configured everything and I send messages and they arrive in the group, I see the names of the users in the group, but I can't receive the messages written in the group I have a 419 error with webhook

{"ok":true,"result":{"url":"/telegram/webhook","has_custom_certificate":false,"pending_update_count":0,"last_error_date":1747810709,"last_error_message":"Wrong response from the webhook: 419 unknown status","max_connections":40,"ip_addr

I inserted it into the bootstrap/app.php file

->withMiddleware(function (Middleware $middleware) { 
	$middleware->validateCsrfTokens(except:[ 
		'*telegram/webhook', 
	]); 
})

I created the file

app/Http/Middleware/VerifyCsrfToken.php

<?php

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;

class VerifyCsrfToken extends Middleware
{

}

and I created the file

app/Http/Kernel.php

<?php

namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
{
    protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\VerifyCsrfToken::class,
        ],

        'api' => [],
    ];
}

what did i do wrong or what did i forget? why doesn't it work?

0 likes
1 reply
Glukinho's avatar

What URL the webhook is pointed to? It should be /api/telegram/webhook, but now it is /telegram/webhook so the VerifyCsrfToken middleware is applied (as the route is in 'web' group, not 'api').

Also, you should not recreate your custom VerifyCsrfToken class, just point telegram webhook to URL starting with /api/... and it will be handled right by default.

Please or to participate in this conversation.