Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download Photo with Maximum quality #197

Open
Azat868 opened this issue Mar 19, 2023 · 8 comments
Open

Download Photo with Maximum quality #197

Azat868 opened this issue Mar 19, 2023 · 8 comments

Comments

@Azat868
Copy link

Azat868 commented Mar 19, 2023

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
Copy link

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
Copy link

harryeffinpotter commented Mar 20, 2023

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
Copy link

harryeffinpotter commented Mar 20, 2023

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
Copy link
Collaborator

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

@Azat868
Copy link
Author

Azat868 commented Mar 20, 2023

@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
Copy link
Author

Azat868 commented Mar 20, 2023

How to know, what message user send to bot?

Example:

User: send audio
Bot: Great music!
User: send pdf file
Bot: Good file!

@Azat868
Copy link
Author

Azat868 commented Mar 20, 2023

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
Copy link
Collaborator

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

@gnadelwartz gnadelwartz self-assigned this Mar 20, 2023
@gnadelwartz gnadelwartz changed the title How to download photo from chat user? Download Photo with Maximum quality Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants