laravel/serializable-closure

Unable to find the called function

devdasher opened this issue · 2 comments

Serializable Closure Version

1.3.0

PHP Version

8.2.4

Description

I don't know how to explain the problem. so i try with an example:

This is my code:

use function DevDasher\PTB\_endConversation;
use function DevDasher\PTB\_input;
use function DevDasher\PTB\_row;
use function DevDasher\PTB\_text;
use function DevDasher\PTB\configurePTB;
use function DevDasher\PTB\KeyboardButton;
use function DevDasher\PTB\onMessage;
use function DevDasher\PTB\onMessageText;
use function DevDasher\PTB\ReplyKeyboardMarkup;
use function DevDasher\PTB\run;
use function DevDasher\PTB\sendMessage;

//...
//...
//...
//...
    _input(
        prompt: 'Send your name:',
        next_step: function() {
            _input(
                conversation_data: ['name' => _text()],
                prompt: 'Send your age:',
                next_step: function($name) {
                    _input(
                        conversation_data: ['age' => _text()],
                        prompt: fn() => sendMessage(
                            text: 'Pick your gender:',
                            reply_markup: ReplyKeyboardMarkup(
                                keyboard: [
                                    _row(KeyboardButton(text: 'Male'), KeyboardButton(text: 'Female')),
                                ],
                                resize_keyboard: true,
                            ),
                        ),
                        next_step: function($name, $age) {
                            $gender = _text();
                            $validGenders = ['male', 'female'];
                            if (!in_array(strtolower($gender), $validGenders)) {
                                return sendMessage(text: 'Invalid gender!');
                            }
                            sendMessage(text: "Thank you!\n\nName: {$name}\nAge: {$age}\nGender: {$gender}");
                            _endConversation();
                        },
                    );
                },
            );
        }
    );
//...
//...
//...
//...

In the above code:

  • I'm sterilizing the value of the parameter next_step in the _input function each time and I store that in cache
  • In subsequent requests, I deserialize that and call the closure and pass some parameters to it.

But i get this long error:

PS D:\Documents\Code\ptb-php> php .\temp\bot.php
Listening...
PHP Fatal error:  Uncaught Error: Call to undefined function ReplyKeyboardMarkup() in laravel-serializable-closure://function($name) {
                \DevDasher\PTB\_input(
                    prompt: fn() => \DevDasher\PTB\sendMessage(
                        text: 'Pick your gender:',
                        reply_markup: ReplyKeyboardMarkup(
                            keyboard: [
                                \DevDasher\PTB\_row(\DevDasher\PTB\KeyboardButton(text: 'Male'), \DevDasher\PTB\KeyboardButton('Female')),
                            ],
                            resize_keyboard: true,
                        )
                    ),
                    next_step: function($name, $age) {
                        $gender = \DevDasher\PTB\_text();
                        $validGenders = ['male', 'female'];
                        if (!\in_array(\strtolower($gender), $validGenders)) {
                            return \DevDasher\PTB\sendMessage(text: 'Invalid gender!');
                        }
                        \DevDasher\PTB\sendMessage(text: "Thank you!\n\nName: {$name}\nAge: {$age}\nGender: $gender");
                        \DevDasher\PTB\_endConversation();
                    },
                    conversation_data: ['age' => \DevDasher\PTB\_text()],
                );
            }:6
Stack trace:
#0 D:\Documents\Code\ptb-php\src\PTB.php(6617): {closure}()
#1 laravel-serializable-closure://function($name) {
                \DevDasher\PTB\_input(
                    prompt: fn() => \DevDasher\PTB\sendMessage(
                        text: 'Pick your gender:',
                        reply_markup: ReplyKeyboardMarkup(
                            keyboard: [
                                \DevDasher\PTB\_row(\DevDasher\PTB\KeyboardButton(text: 'Male'), \DevDasher\PTB\KeyboardButton('Female')),
                            ],
                            resize_keyboard: true,
                        )
                    ),
                    next_step: function($name, $age) {
                        $gender = \DevDasher\PTB\_text();
                        $validGenders = ['male', 'female'];
                        if (!\in_array(\strtolower($gender), $validGenders)) {
                            return \DevDasher\PTB\sendMessage(text: 'Invalid gender!');
                        }
                        \DevDasher\PTB\sendMessage(text: "Thank you!\n\nName: {$name}\nAge: {$age}\nGender: $gender");
                        \DevDasher\PTB\_endConversation();
                    },
                    conversation_data: ['age' => \DevDasher\PTB\_text()],
                );
            }(3): DevDasher\PTB\_input(Object(Closure), Object(Closure), Array)
#2 D:\Documents\Code\ptb-php\src\PTB.php(6472): {closure}('Pooria')
#3 D:\Documents\Code\ptb-php\src\PTB.php(6380): DevDasher\PTB\__fireHandlers(Array)
#4 D:\Documents\Code\ptb-php\src\PTB.php(6728): DevDasher\PTB\__processCurrentUpdate()
#5 D:\Documents\Code\ptb-php\temp\bot.php(97): DevDasher\PTB\run()
#6 {main}
  thrown in laravel-serializable-closure://function($name) {
                \DevDasher\PTB\_input(
                    prompt: fn() => \DevDasher\PTB\sendMessage(
                        text: 'Pick your gender:',
                        reply_markup: ReplyKeyboardMarkup(
                            keyboard: [
                                \DevDasher\PTB\_row(\DevDasher\PTB\KeyboardButton(text: 'Male'), \DevDasher\PTB\KeyboardButton('Female')),
                            ],
                            resize_keyboard: true,
                        )
                    ),
                    next_step: function($name, $age) {
                        $gender = \DevDasher\PTB\_text();
                        $validGenders = ['male', 'female'];
                        if (!\in_array(\strtolower($gender), $validGenders)) {
                            return \DevDasher\PTB\sendMessage(text: 'Invalid gender!');
                        }
                        \DevDasher\PTB\sendMessage(text: "Thank you!\n\nName: {$name}\nAge: {$age}\nGender: $gender");
                        \DevDasher\PTB\_endConversation();
                    },
                    conversation_data: ['age' => \DevDasher\PTB\_text()],
                );
            } on line 6

Fatal error: Uncaught Error: Call to undefined function ReplyKeyboardMarkup() in laravel-serializable-closure://function($name) {
                \DevDasher\PTB\_input(
                    prompt: fn() => \DevDasher\PTB\sendMessage(
                        text: 'Pick your gender:',
                        reply_markup: ReplyKeyboardMarkup(
                            keyboard: [
                                \DevDasher\PTB\_row(\DevDasher\PTB\KeyboardButton(text: 'Male'), \DevDasher\PTB\KeyboardButton('Female')),
                            ],
                            resize_keyboard: true,
                        )
                    ),
                    next_step: function($name, $age) {
                        $gender = \DevDasher\PTB\_text();
                        $validGenders = ['male', 'female'];
                        if (!\in_array(\strtolower($gender), $validGenders)) {
                            return \DevDasher\PTB\sendMessage(text: 'Invalid gender!');
                        }
                        \DevDasher\PTB\sendMessage(text: "Thank you!\n\nName: {$name}\nAge: {$age}\nGender: $gender");
                        \DevDasher\PTB\_endConversation();
                    },
                    conversation_data: ['age' => \DevDasher\PTB\_text()],
                );
            }:6
Stack trace:
#0 D:\Documents\Code\ptb-php\src\PTB.php(6617): {closure}()
#1 laravel-serializable-closure://function($name) {
                \DevDasher\PTB\_input(
                    prompt: fn() => \DevDasher\PTB\sendMessage(
                        text: 'Pick your gender:',
                        reply_markup: ReplyKeyboardMarkup(
                            keyboard: [
                                \DevDasher\PTB\_row(\DevDasher\PTB\KeyboardButton(text: 'Male'), \DevDasher\PTB\KeyboardButton('Female')),
                            ],
                            resize_keyboard: true,
                        )
                    ),
                    next_step: function($name, $age) {
                        $gender = \DevDasher\PTB\_text();
                        $validGenders = ['male', 'female'];
                        if (!\in_array(\strtolower($gender), $validGenders)) {
                            return \DevDasher\PTB\sendMessage(text: 'Invalid gender!');
                        }
                        \DevDasher\PTB\sendMessage(text: "Thank you!\n\nName: {$name}\nAge: {$age}\nGender: $gender");
                        \DevDasher\PTB\_endConversation();
                    },
                    conversation_data: ['age' => \DevDasher\PTB\_text()],
                );
            }(3): DevDasher\PTB\_input(Object(Closure), Object(Closure), Array)
#2 D:\Documents\Code\ptb-php\src\PTB.php(6472): {closure}('Pooria')
#3 D:\Documents\Code\ptb-php\src\PTB.php(6380): DevDasher\PTB\__fireHandlers(Array)
#4 D:\Documents\Code\ptb-php\src\PTB.php(6728): DevDasher\PTB\__processCurrentUpdate()
#5 D:\Documents\Code\ptb-php\temp\bot.php(97): DevDasher\PTB\run()
#6 {main}
  thrown in laravel-serializable-closure://function($name) {
                \DevDasher\PTB\_input(
                    prompt: fn() => \DevDasher\PTB\sendMessage(
                        text: 'Pick your gender:',
                        reply_markup: ReplyKeyboardMarkup(
                            keyboard: [
                                \DevDasher\PTB\_row(\DevDasher\PTB\KeyboardButton(text: 'Male'), \DevDasher\PTB\KeyboardButton('Female')),
                            ],
                            resize_keyboard: true,
                        )
                    ),
                    next_step: function($name, $age) {
                        $gender = \DevDasher\PTB\_text();
                        if (!\in_array(\strtolower($gender), $validGenders)) {
                            return \DevDasher\PTB\sendMessage(text: 'Invalid gender!');
                        }
                        \DevDasher\PTB\sendMessage(text: "Thank you!\n\nName: {$name}\nAge: {$age}\nGender: $gender");
                        \DevDasher\PTB\_endConversation();
                    },
                    conversation_data: ['age' => \DevDasher\PTB\_text()],
                );
            } on line 6

The problem is that it looks like the package laravel/serializable-closure can not find this function: ReplyKeyboardMarkup

But as you can see, at the above of the code I added the use function DevDasher\PTB\ReplyKeyboardMarkup;, But i don't know why it can't find that!

I hope you understand what I am saying and solve the problem

Thank you.

Steps To Reproduce

.................................................................................

Can someone help me please?!

Hey there,

Can you first please try one of the support channels below? If you can actually identify this as a bug, feel free to open up a new issue with a link to the original one and we'll gladly help you out.

Thanks!