#!/bin/bash TOKEN='' URL='https://api.telegram.org/bot'$TOKEN FILE='https://api.telegram.org/file/bot'$TOKEN POLL_TIME=30 IMG_DIR='./tg_imgs' while true; do { objs="$( curl -s "$URL/getUpdates" \ -d "offset=${offset:-0}" \ -d "timeout=${POLL_TIME}" \ -d 'allowed_updates=["message"]' \ -m ${POLL_TIME} | jq '.result []' )" offset="$(($(jq '.update_id' <<< "$objs" | tail -n1) + 1))" jq -cr '.message | .photo, .from' <<< "$objs" }; done | while read photo; do { read user [ "$photo" = null ] && continue jq -cr '.[] | .file_id, .width, .height, .file_size' <<< "$photo" | while read fid; do { read w; read h; read file_size; jq -cr '.id, .first_name, .last_name, .username' <<< "$user" | { read uid; read fname; read lname; read uname curl -s "$URL/getFile" -d "file_id=$fid" | jq -cr '.result .file_path' | { read path echo "[$(date)] Got image from $fname $lname (@$uname, id $uid), ID: $fid, ${w}x${h} $file_size bytes." ext="$(rev <<< "$path" | cut -d. -f1 | rev)" curl -s $FILE/$path > $IMG_DIR/$uid-$fid.$ext & } } }; done }; done