botman: Serialization of 'Closure' is not allowed
I’m using botman with laravel 5.4 when I try to run some conversation with ask function. It will result to Serialization of ‘Closure’ is not allowed. Example conversation:
<?php
namespace App\Conversations;
use Illuminate\Foundation\Inspiring;
use Mpociot\BotMan\Answer;
use Mpociot\BotMan\Button;
use Mpociot\BotMan\Conversation;
use Mpociot\BotMan\Question;
class ReservationConversation extends Conversation
{
/**
* First question
*/
public function askReason()
{
$question = Question::create("Ahoj, ako ti pomozem?")
->fallback('Unable to ask question')
->addButtons([
Button::create('Tell a joke')->value('joke'),
Button::create('Give me a fancy quote')->value('quote'),
]);
return $this->ask($question, function (Answer $answer) {
$this->say('Hello');
});
}
/**
* Start the conversation
*/
public function run()
{
$this->askReason();
}
}
When I take a look to stack trace I see that error comes from FileStore.php
public function put($key, $value, $minutes)
{
$this->ensureCacheDirectoryExists($path = $this->path($key));
$this->files->put(
$path, $this->expiration($minutes).serialize($value), true
);
}
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 19 (7 by maintainers)
It depends on how you pass / initialize the dependencies. But you can do something like this in your conversation class:
@mpociot thanks for your answer.
And you’re right, dependencies are problematic. I’ve removed that one dependency class from constructor (it’s an API wrapper), and it works now. So’ll have to figure out some kind of different method 😃