irazasyed / telegram-bot-sdk

🤖 Telegram Bot API PHP SDK. Lets you build Telegram Bots easily! Supports Laravel out of the box.
https://telegram-bot-sdk.com
BSD 3-Clause "New" or "Revised" License
3.03k stars 670 forks source link

Operation timed out #130

Closed muhkuh2005 closed 8 years ago

muhkuh2005 commented 8 years ago

Hey there, I came up with the following Exception:

PHP Fatal error:  Uncaught exception 'Telegram\Bot\Exceptions\TelegramSDKException' with message 'cURL error 28: Operation timed out after 60001 milliseconds with 0 bytes received (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)' in /var/www/clients/client1/web3/private/test/vendor/irazasyed/telegram-bot-sdk/src/HttpClients/GuzzleHttpClient.php:114
Stack trace:
#0 /var/www/clients/client1/web3/private/test/vendor/irazasyed/telegram-bot-sdk/src/TelegramClient.php(117): Telegram\Bot\HttpClients\GuzzleHttpClient->send('https://api.tel...', 'POST', Array, Array, 60, false, 10)
#1 /var/www/clients/client1/web3/private/test/vendor/irazasyed/telegram-bot-sdk/src/Api.php(1014): Telegram\Bot\TelegramClient->sendRequest(Object(Telegram\Bot\TelegramRequest))
#2 /var/www/clients/client1/web3/private/test/vendor/irazasyed/telegram-bot-sdk/src/Api.php(958): Telegram\Bot\Api->sendRequest('POST', 'sendPhoto', Array)
#3 /var/www/clients/client1/web3/private/test/vendor/irazasyed/telegram-bot-sdk/src/Api.php(991): Telegram\Bot\Api->post( in /var/www/clients/client1/web3/private/test/vendor/irazasyed/telegram-bot-sdk/src/HttpClients/GuzzleHttpClient.php on line 114

I tried to use this bot SDK to post an image into a channel. The bot is administrator of the channel and pure text messages can be send without problems. Sending an image though, ends up with an timeout.

jonnywilliamson commented 8 years ago

Please show the code that actually sends the image.

Have you triple checked that the URL to the image REALLY exists?

muhkuh2005 commented 8 years ago

$telegram = new Api($token); $response = $telegram->sendPhoto([ 'chat_id' => $chat_id, 'photo' => $img, 'caption' => $txt ]);

$img is a randomly chosen imagefile from a shimmie2 imageboard. $img results to be similiar to this one: "/var/www/clients/client1/web3/private/thumbs/f4/f42d2b27062054c2aa7b3a757230119e" Its an absolute path to an imagefile. I build in an existance check via PHPs function is_file() They are saved without fileendings though that doesnt seem to be a problem. I tried running the images through Imagemagick first, resizing filesize and imageresolution. But that only helps with 'some' of the images.

All the Images are static ones, no animated GIFs or similiar. The problem occurs with different Filetypes (JPEG, PNG, GIF)

irazasyed commented 8 years ago

The file extension does matter when working with Telegram Bot API.

Without the file extension (.jpg, .png), it doesn't work. Sometime ago, someone (I don't remember now) had a similar issue and the testing showed the file extension is required for it to work. So you gotta test it.

Let me know if that works.

muhkuh2005 commented 8 years ago

Tried runnng 'every' image through imagemagick now. Doesn't succeed either. Heres my debug output:

root@applefritter /var/www/clients/client1/web3/private/test # php telegram.php Starting method selectid Image has passed double-post check. selectID wordked, ID: 1176 Starting method selectfilename Starting method hasArtist filename is: 5716a94ce1495bfdbdff03c2255d2060 Starting method checkSource Thumbnail folder exists generate Thumbnail Thumbnail has been created. Actual filepath: /var/www/clients/client1/web3/private/thumbs/57/5716a94ce1495bfdbdff03c2255d2060.telegram.jpg Send to Telegram

Some raw fileinfo: /var/www/clients/client1/web1/web/img/images/9f/9fa9d3455b7bd2817dd0a74b61dfb7d0: JPEG image data, JFIF standard 1.02, resolution (DPI), density 72x72, segment length 16, baseline, precision 8, 2181x2718, frames 3

And the by imagemagick created thumbnail: /var/www/clients/client1/web3/private/thumbs/9f/9fa9d3455b7bd2817dd0a74b61dfb7d0.telegram.jpg: JPEG image data, JFIF standard 1.01, resolution (DPI), density 72x72, segment length 16, baseline, precision 8, 822x1024, frames 3

irazasyed commented 8 years ago

How large is the file? Can you increase the timeout and test?

jonnywilliamson commented 8 years ago

Could you post/link to one of the problem images so I can download and test?

Also, have you tried with just a plain old non-generated image. Like for example this:

image

(http://www.wkhscounselors.com/images/Pictures/ArticlePics/CollegeCareer/-testing.jpg)

Just tested that image with no issues.

muhkuh2005 commented 8 years ago

Sorry for the slow reply. The Filesize varies but is topped at 3MB.

One of the files tested and failed is this one: One Testimage https://img.sweetappleacr.es/_images/bbec32882ece3abdd6d1515f3ab38e91/2106%20-%20bulged_cheeks%20character%3Atwilight_sparkle%20closed%20cutie_mark%20ears_back%20eyebrows%20eyes%20multicolor_hair%20multicolor_tail%20plain_background%20purple_fur%20saliva%20saliva_drops%20series%3AFriendship_is_Magic%20series%3AMy_Little_Pony%20silly_behave%20species%3AWinged_Unicorn%20species%3Aequine%20species%3Ahorse%20species%3Apony%20tagme%20tongue%20tongue_out.jpg

I tried it out with your test-image and it worked fine when it came as the original file. Though I honestly cannot make out the difference beside the original one and the one that, as far as i know, is renamed file. (Which can be found here: https://img.sweetappleacr.es/_images/126a1755aec40030d1118ddbb667b7cf )

The files are loaded directly from the disc via absolute pathes.

Edit: Something that bugs my mind is, that some of the generated images seem to work just fine...

irazasyed commented 8 years ago

So I just tested your image and it works fine without any issues.

Just to make sure, I also went ahead and tested with this image, which is about 6.7 MB in size. Even that worked fine. I tested multiple such big sized HQ images without any issues and with default settings.

So here are a few things you need to analyze and try:

For now, I'm closing this ticket since there is no issue from the SDK end (Tested multiple times as already mentioned).

Feel free to open another ticket, though.