I use Symfony 6.1 and PHP 8.1. I'm wondering if there is a way to make a Symfony controller return nothing. The why is I'm using Botman and unfortunalty it send itself a response to the client... So I need to make my controller to return nothing.
/**
* @param Request $request
*
* @return Response
*/
#[Route('/botman', methods: 'POST')]
public function test(Request $request): Response
{
DriverManager::loadDriver(WebDriver::class);
$adapter = new FilesystemAdapter();
$botman = BotManFactory::create([], new SymfonyCache($adapter), $request);
$botman->hears('hello', static function (BotMan $bot) {
$bot->reply('Yoooooo'); //<- Send a response to the client
});
$botman->fallback(static function (BotMan $bot) {
$bot->reply('try again'); //<- Send a response to the client
});
$botman->listen(); // Launch the maching callback
return new Response(); //Crash because a response have already been sent
}
This is what I get on my browser inspector.
{
"status": 200,
"messages": [
{
"type": "text",
"text": "try again",
"attachment": null,
"additionalParameters": []
}
]
}{
"type": "https:\/\/tools.ietf.org\/html\/rfc2616#section-10",
"title": "An error occurred",
"status": 500,
"detail": "Warning: Cannot modify header information - headers already sent by (output started at C:\\Users\\cimba\\Documents\\botman\\vendor\\symfony\\http-foundation\\Response.php:1265)",
"class": "ErrorException",
"trace": [...]
}
The only solution I have is to exit();
or die();
instead of the return
but I it's not clean for production... Maybe there is a way to avoid BotMan to send it's response or to tell Symfony that I want my controller to return nothing (because botman does without symfony).