Use case 1/6
Telegram Bot
Webhook handler + async job dispatch
Routing
Queue
PSR-15 middleware
Why Lift fits this
- ▸ PSR-15 middleware verifies Telegram's X-Telegram-Bot-Api-Secret-Token before your code runs
- ▸ Heavy tasks (sending media, calling external APIs) dispatched to a Redis queue — webhook returns 200 instantly
- ▸ Same app runs under RoadRunner for high-throughput bots without restarting PHP per update
telegram-bot.php
<?php
use Lift\App;
use Lift\Http\Request;
use Lift\Http\Response;
use Lift\Queue\RedisQueue;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
class TelegramSecretMiddleware implements MiddlewareInterface
{
public function process(ServerRequestInterface $req, RequestHandlerInterface $next): ResponseInterface
{
if ($req->getHeaderLine('X-Telegram-Bot-Api-Secret-Token') !== $_ENV['TG_SECRET']) {
return Response::json(['error' => 'Forbidden'], 403);
}
return $next->handle($req);
}
}
$app = new App();
$app->setQueue(new RedisQueue($app->make(\Lift\Redis\RedisClient::class)));
$app->use(TelegramSecretMiddleware::class);
$app->post('/webhook', function (Request $req) use ($app) {
$app->dispatch(new HandleTelegramUpdate($req->json()));
return Response::noContent();
});
$app->run();