topkecleon / telegram-bot-bash

Telegram bot written in bash
Other
431 stars 123 forks source link

Download Photo with Maximum quality #197

Open Azat868 opened 1 year ago

Azat868 commented 1 year ago

Hi, pls help me User send to chat photo/images, how to download this photos? I read docs:

# download from Telegram server
# photo received in a chat
photo="${URLS[PHOTO]}")"
echo "$photo" -> photo/file_1234.jpg

# first download
file="$(download_file "${photo}"
echo "$file" -> ./data-bot-bash/photo-file_1234.jpg

but this code has syntax error: photo="${URLS[PHOTO]}")"

And im try to paste:


            if user_is_allowed "${USER[ID]}" "info" "${CHAT[ID]}" ; then

            send_normal_message "${CHAT[ID]}" "$(date)"
            # download from Telegram server
            # photo received in a chat
            photo="${URLS[PHOTO]}"
            echo "$photo" -> photo/file_1234.jpg
            # first download
            file=$"(download_file ${photo})"
            echo "$file" -> ./data-bot-bash/photo-file_1234.jpg
            return 0
            else
                #send_normal_message "${CHAT[ID]}" "You are not allowed to start Bot."
            echo "test"
            fi
            ;;```

but its not work

and second question, where edit this message:
```This is @name_bot, the Telegram example bot written entirely in bash.
Edit commands and messages in mycommands.sh!```
harryeffinpotter commented 1 year ago

Oh boy from the looks of it you need a lot of help. Have you committed your most recent changes to your fork? I can take a look later or tomorrow if so! I just submitted a PR to fix the topic group messages and stumbled upon this cry for help here lmao

harryeffinpotter commented 1 year ago

The error is giving you exactly what you did wrong, check your brackets there, theyre heavily screwed up.

Clearly you didnt just copy paste, or it wouldn't be messed up like that,

here is what you have: photo="${URLS[PHOTO]}")"

Here is the correct writing: photo="${URLS[PHOTO]}"

notice on yours you have a rogue additional )" Look closely at your bracket ratios, always, it is the most essential thing when it comes to scripting. You need to get Visual Studio code and you need to open the telegram-bot-bash directory as a project folder in Visual Studio code. Then you need to add the bash extension known as Shell Check and for better looking errors you should also install the extension Error Lens. The end result will help you SO much. You can also even get an SSH extension that allows you to edit files on an ubuntu server in real time, I will attatch a short gif of how obvious this would have been if you had my setup.

harryeffinpotter commented 1 year ago

This is why you need VIsual Studio Code with Shell Check and Error Lens ASAP

GTwFHlsqAY

This is my list of extensions, the only other ones I use are cosmetic (the blue theme is Winter Is Coming and looks sooo much better when not washed out by dumb HDR bug):

image

The SSH stuff is so you can go from vs code direct to server, it literally installs the modules on the server so that everything is real time, it's a game changer!

gnadelwartz commented 1 year ago

@harryeffinpotter thanks for helping, i'll have a look on your PR later on

Azat868 commented 1 year ago

@gnadelwartz @harryeffinpotter How to download high resolution image? Im tryied:

        *)  
            photo="${URLS[PHOTO]}"
            send_normal_message "${CHAT[ID]}" "$photo"
            send_normal_message "${CHAT[ID]}" "test"

            # first download
            file=$(download_file ${photo})
        ;;

And send image to bot, image size 24kb: изображение

But bot download 1kb preview image: изображение изображение

Pls tell me how to download full image...the usally its:

#Get file_id
curl  https://api.telegram.org/bot$BOT_TOKEN/getFile?file_id=$file_id | jq .
# Ask by file_path to file_id
result=$(curl "https://api.telegram.org/bot$BOT_TOKEN/getFile?file_id=$file_id")
file_path=$(echo "$result" | jq -r .result.file_path)
#Download by file_path
curl -o "/root/photoshop/ClientImage.jpg" "https://api.telegram.org/file/bot$BOT_TOKEN/$file_path"
echo "Image saved at /root/photoshop/ClientImage.jpg"

But, how its work this bot and code?

And how to create next dialog with user:

Bot: Hi! Pls send me image
User: send photo
Bot: download image
Bot: Thx you, good bye
Azat868 commented 1 year ago

How to know, what message user send to bot?

Example:

User: send audio
Bot: Great music!
User: send pdf file
Bot: Good file!
Azat868 commented 1 year ago

Okay, im found... изображение its not correct my friend because the first telegram sen low resolution file_id: изображение

to fix this problem, im edit telegram-bot-bash\modules\processUpdates.sh : URLS[PHOTO]="$(get_file "${UPD["result,${num},message,photo,0,file_id"]}")" to: URLS[PHOTO]="$(get_file "${UPD["result,${num},message,photo,2,file_id"]}")" and now im get high resolution image

gnadelwartz commented 1 year ago

thanks for the hint, i'll add something similar in the next releases