I’m building a telegram bot that needs to post multiple photos, each with its own unique caption. Right now my bot sends all the pictures correctly but every single one gets the same caption text instead of different ones.
The issue is that every photo gets sent with the entire caption_list instead of just one caption from the list. How can I make each image use a different caption from my list?
Easy fix. You’re passing the whole caption_list array instead of individual captions.
Change your loop to use enumerate or zip:
for i, image_link in enumerate(image_links):
time.sleep(2)
params = {
"chat_id": "-123456789",
"photo": image_link,
"caption": caption_list[i] # Use index to get single caption
}
response = requests.get(api_endpoint, data=params)
print(response.text)
Or cleaner with zip:
for image_link, caption in zip(image_links, caption_list):
# rest of your code
But managing telegram bots manually gets messy once you add more features.
I switched to Latenode for bot automation. You can set up workflows visually, handle multiple images with different captions without loops, and add conditional logic for different image types.
It handles API calls, errors, and rate limiting automatically. Way less debugging than Python scripts.
Had the exact same issue building my first Telegram bot for workout photos. You’re passing the entire caption_list array to the caption field in your params dictionary. Telegram just converts that whole array to a string, so every photo gets the same caption.
Easy fix: use enumerate in your loop like for index, image_link in enumerate(image_links): then grab caption_list[index] for your params.
Couple other things - check that both lists are the same length before looping or you’ll hit index errors. Also try requests.post instead of requests.get for better handling of special characters. Good call on the time.sleep though, Telegram’s rate limits will block you if you spam too fast.
You’ve got the exact issue etherealEthan42 mentioned - you’re passing the entire list as a caption instead of individual strings. Telegram’s API just takes that whole array and turns it into a string representation. I’ve hit this same problem with bulk photo uploads. The zip approach works way better, but watch out for mismatched list lengths. If your image_links and caption_list don’t match up, zip will just cut off at the shorter one without telling you. Also, switch to POST requests instead of GET. GET works for basic stuff, but POST handles data better and won’t choke on special characters or spaces in your captions like GET does with URL encoding. One more thing - add error handling to those API calls. Telegram throws 429 errors when you’re hitting them hard, and right now you’re just printing the error with no retry logic.
yeah, you’re sending the entire array to telegram instead of individual captions. you could try caption_list[image_links.index(image_link)] but just use for img, cap in zip(image_links, caption_list): like everyone else suggested. much cleaner and won’t break on you.