botman / driver-telegram

BotMan Telegram Driver
MIT License
87 stars 75 forks source link

KeyboardButton with text 0 is filtered #63

Closed xarasbir closed 2 years ago

xarasbir commented 5 years ago

When the following keyboard is added to a message

$keyboard = Keyboard::create(Keyboard::TYPE_KEYBOARD)->oneTimeKeyboard(true)->resizeKeyboard();  
$keyboard->addRow(KeyboardButton::create(0));

it will be translated into

'reply_markup' => '{"keyboard":[[[]]],"one_time_keyboard":true,"resize_keyboard":true}',

which causes Telegram to not relay the message to the intended recipient because of empty keyboard parameter.

As I dig through the code, the cause might be the following filter() inside KeyboardButton@jsonSerialize

public function jsonSerialize()
    {
        return Collection::make([
            'url' => $this->url,
            'callback_data' => $this->callbackData,
            'request_contact' => $this->requestContact,
            'request_location' => $this->requestLocation,
            'text' => $this->text,
        ])->filter()->toArray();
    }
cristianviale commented 3 years ago

Hi @xarasbir, I agree with you.

I solved editing the function jsonSerialize() with: public function jsonSerialize() { return Collection::make([ 'url' => $this->url, 'callback_data' => $this->callbackData, 'request_contact' => $this->requestContact, 'request_location' => $this->requestLocation, 'text' => $this->text, ])->filter(function ($value, $key) { return $value !== false && $value !== null; })->toArray(); }

filippotoso commented 2 years ago

Solved in 2.0.2