php-telegram-bot / core

PHP Telegram Bot based on the official Telegram Bot API
MIT License
3.87k stars 951 forks source link

Checking entities fields dilemma #222

Closed jacklul closed 8 years ago

jacklul commented 8 years ago

I seem to be getting

exception 'Longman\TelegramBot\Exception\TelegramException' with message 'first_name is empty!' in /vendor/longman/telegram-bot/src/Entities/User.php:33

a lot (I assume people have name = '0'), also similar error with 'duration' in Voice entity (half a second recording is still duration = 0 I guess), maybe we shouldn't check for such fields in incoming updates?

Possibly replace empty($this->first_name) with $this->first_name === '' and allow 0 value in duration? Same changes could be applied to other entities.

noplanman commented 8 years ago

@jacklul I agree with you that we shouldn't really be checking the data itself since it's coming from Telegram like that. As an interim solution, I think we do as you suggest, to modify the checks so that errors like that don't pop up 👍

P.S. The entities need to be rewritten at some point anyway, using magic methods to get rid of all the redundant method names.

noplanman commented 8 years ago

Referring to #193 and closing here.