defstudio / telegraph

Telegraph is a Laravel package for fluently interacting with Telegram Bots
MIT License
697 stars 118 forks source link

I can't get the photo from the message #510

Closed m-petrosyan closed 9 months ago

m-petrosyan commented 9 months ago
    public function handleChatMessage(Stringable $text): void
    {
        /** @var DefStudio\Telegraph\DTO\Message $message */
        Log::info($message);
        Bot::find(1)->store($message->photo(), Storage::path('img'));
    }

Logs

[2024-02-08 16:43:04] local.DEBUG: Telegraph webhook message {"text":""} 
[2024-02-08 16:43:04] local.ERROR: Undefined variable $message {"exception":"[object] (ErrorException(code: 0): Undefined variable $message at D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\app\\Telegram\\TelegramHandler.php:45)
[stacktrace]
fabio-ivona commented 9 months ago

@m-petrosyan could you please paste here a full stack trace?

m-petrosyan commented 9 months ago

Of course here's the whole project https://github.com/m-petrosyan/metal-events-telegram-bot/blob/main/app/Telegram/TelegramHandler.php

fabio-ivona commented 9 months ago

As far as I can see from your first dump, the $message doesn't carry any photo, could you double check it

fabio-ivona commented 9 months ago

And please, paste here the full stacktrace of the exception you receive, can't help without it

m-petrosyan commented 9 months ago

@fabio-ivona I sent the bot a photo. image

[2024-02-08 16:43:04] local.DEBUG: Telegraph webhook message {"text":""} 
[2024-02-08 16:43:04] local.ERROR: Undefined variable $message {"exception":"[object] (ErrorException(code: 0): Undefined variable $message at D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\app\\Telegram\\TelegramHandler.php:45)
[stacktrace]
#0 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Bootstrap\\HandleExceptions.php(255): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(2, 'Undefined varia...', 'D:\\\\wamp64\\\\www\\\\p...', 45)
#1 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\app\\Telegram\\TelegramHandler.php(45): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->Illuminate\\Foundation\\Bootstrap\\{closure}(2, 'Undefined varia...', 'D:\\\\wamp64\\\\www\\\\p...', 45)
#2 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\defstudio\\telegraph\\src\\Handlers\\WebhookHandler.php(131): App\\Telegram\\TelegramHandler->handleChatMessage(Object(Illuminate\\Support\\Stringable))
#3 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\defstudio\\telegraph\\src\\Handlers\\WebhookHandler.php(232): DefStudio\\Telegraph\\Handlers\\WebhookHandler->handleMessage()
#4 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\defstudio\\telegraph\\src\\Controllers\\WebhookController.php(28): DefStudio\\Telegraph\\Handlers\\WebhookHandler->handle(Object(Illuminate\\Http\\Request), Object(App\\Models\\Bot))
#5 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\ControllerDispatcher.php(46): DefStudio\\Telegraph\\Controllers\\WebhookController->handle(Object(Illuminate\\Http\\Request), '6744946968:AAGx...')
#6 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Route.php(259): Illuminate\\Routing\\ControllerDispatcher->dispatch(Object(Illuminate\\Routing\\Route), Object(DefStudio\\Telegraph\\Controllers\\WebhookController), 'handle')
#7 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Route.php(205): Illuminate\\Routing\\Route->runController()
#8 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(806): Illuminate\\Routing\\Route->run()
#9 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(144): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#10 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(119): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#11 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(805): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#12 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(784): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request))
#13 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(748): Illuminate\\Routing\\Router->runRoute(Object(Illuminate\\Http\\Request), Object(Illuminate\\Routing\\Route))
#14 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(737): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request))
#15 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(200): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request))
#16 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(144): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}(Object(Illuminate\\Http\\Request))
#17 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#18 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull.php(31): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#19 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#20 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#21 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TrimStrings.php(40): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#22 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\TrimStrings->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#23 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#24 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#25 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance.php(99): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#26 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#27 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Http\\Middleware\\HandleCors.php(49): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#28 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(183): Illuminate\\Http\\Middleware\\HandleCors->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#29 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Http\\Middleware\\TrustProxies.php(39): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#30 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(183): Illuminate\\Http\\Middleware\\TrustProxies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#31 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(119): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#32 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(175): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#33 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(144): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))
#34 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\public\\index.php(51): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
#35 D:\\wamp64\\www\\projects\\metal-events-telegram-bot\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\resources\\server.php(16): require_once('D:\\\\wamp64\\\\www\\\\p...')
#36 {main}
"} 

image

m-petrosyan commented 9 months ago

I understand, you need to do it like this Bot::find(1)->store($this->message->photos()->last(), 'images')`