westacks / telebot

Easy way to create Telegram bots in PHP
https://westacks.github.io/telebot/
MIT License
282 stars 44 forks source link

Error when bot receives files #24

Closed aizekjohn closed 3 years ago

aizekjohn commented 3 years ago

I'm using laravel + telebot to create my telegram bot. While testing I found that when user sends a file to the bot, it fails and webhook responses with 500 internal server error. In the laravel.log file we can see that it says: local.ERROR: Undefined array key "text" {"exception":"[object] (ErrorException(code: 0): Undefined array key \"text\" at C:\\Users\\aizek\\Documents\\*********\\vendor\\westacks\\telebot\\src\\Interfaces\\TelegramObject.php:37)

Here is 37th line of that file: return $this->properties[$key];

We have to add ?? NULL in order to solve the problem. So it'll be: return $this->properties[$key] ?? NULL;

Then everything would be fine with files.

I would ask the author to fix this in the next commits :) Bless you.

punyflash commented 3 years ago

Hello! For now it's duplicate of #15. I still think that this is fine to throw exception if there was an attempt to access an undefined variable. But as this is not the first time this feature was requested, I will consider about adding null coalescing by default. Please locate your code where exception was thrown and provide an example.

aizekjohn commented 3 years ago

Thank you. I found that dot-notation works fine with undefined variables. What I did was to send entire incoming update("text" => (string)$update) to my telegram account so that I could check what's coming from telegram. This is why exception was thrown.