sendPhoto
Use this method to send photos. On success, the sent Message is returned.
Parameters
business_connection_idStringOptionalUnique identifier of the business connection on behalf of which the message will be sent
chat_idIntegerStringRequiredUnique identifier for the target chat or username of the target channel (in the format
@channelusername)message_thread_idIntegerOptionalUnique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only
direct_messages_topic_idIntegerOptionalIdentifier of the direct messages topic to which the message will be sent; required if the message is sent to a direct messages chat
Photo to send. Pass a file\_id as String to send a photo that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a photo from the Internet, or upload a new photo using multipart/form-data. The photo must be at most 10 MB in size. The photo's width and height must not exceed 10000 in total. Width and height ratio must be at most 20. More information on Sending Files »
Photo caption (may also be used when resending photos by file\_id), 0-1024 characters after entities parsing
parse_modeStringOptionalMode for parsing entities in the photo caption. See formatting options for more details.
A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse\_mode
show_caption_above_mediaBooleanOptionalPass True, if the caption must be shown above the message media
has_spoilerBooleanOptionalPass True if the photo needs to be covered with a spoiler animation
disable_notificationBooleanOptionalSends the message silently. Users will receive a notification with no sound.
protect_contentBooleanOptionalProtects the contents of the sent message from forwarding and saving
allow_paid_broadcastBooleanOptionalPass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance
message_effect_idStringOptionalUnique identifier of the message effect to be added to the message; for private chats only
A JSON-serialized object containing the parameters of the suggested post to send; for direct messages chats only. If the message is sent as a reply to another suggested post, then that suggested post is automatically declined.
Description of the message to reply to
reply_markupInlineKeyboardMarkupReplyKeyboardMarkupReplyKeyboardRemoveForceReplyOptional⌨️ KeyboardsAdditional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user
Returns
On success, the Message object is returned.
GramIO Usage
ts
// Send a photo by file_id (fastest — no re-upload)
bot.command("photo", (ctx) => ctx.sendPhoto("file_id_here"));ts
// Upload from disk and reply to the current message
bot.command("snapshot", async (ctx) =>
ctx.replyWithPhoto(await MediaUpload.path("./snapshot.jpg"), {
caption: "Here is your snapshot!",
})
);ts
// Send a spoiler photo with formatted caption
bot.command("spoiler", async (ctx) =>
ctx.sendPhoto(await MediaUpload.path("./reveal.jpg"), {
caption: format`${bold("Spoiler alert!")} Click to reveal`,
has_spoiler: true,
})
);ts
// Fetch a photo from a URL (Telegram downloads it server-side)
bot.command("avatar", async (ctx) =>
ctx.sendPhoto(await MediaUpload.url("https://example.com/avatar.jpg"), {
caption: "Profile photo",
})
);ts
// Direct API call with an inline keyboard
await bot.api.sendPhoto({
chat_id: 123456789,
photo: "file_id_here",
caption: "Check out this photo!",
reply_markup: new InlineKeyboard()
.text("Like", "like")
.text("Share", "share"),
});Errors
| Code | Error | Cause |
|---|---|---|
| 400 | Bad Request: chat not found | chat_id is invalid or the bot has no access to that chat |
| 400 | Bad Request: wrong file identifier/HTTP URL specified | photo is a malformed file_id or the URL is inaccessible |
| 400 | Bad Request: failed to get HTTP URL content | Telegram could not download the photo from the URL — ensure it is publicly accessible |
| 400 | Bad Request: PHOTO_INVALID_DIMENSIONS | Photo exceeds 10,000 total width+height or 20:1 aspect ratio — resize before sending |
| 400 | Bad Request: can't parse entities | Malformed caption_entities or bad parse_mode markup |
| 403 | Forbidden: bot was blocked by the user | User blocked the bot — catch and mark as inactive |
| 403 | Forbidden: not enough rights to send photos | Bot lacks can_send_photos permission in a restricted group |
| 429 | Too Many Requests: retry after N | Rate limit hit — check retry_after, use auto-retry plugin |
TIP
Use GramIO's auto-retry plugin to handle 429 errors automatically.
Tips & Gotchas
- 10 MB file limit. Photos larger than 10 MB cannot be sent via the Bot API. For larger images, send as a document via
sendDocument(50 MB limit) — the image won't be displayed inline but can be downloaded. - Dimension constraints. Total width+height must not exceed 10,000 and the aspect ratio must not exceed 20:1. Very wide panoramas or extreme crops trigger
PHOTO_INVALID_DIMENSIONS— resize before sending. - Cache
file_idafter first upload. The returnedMessage.photois an array ofPhotoSizeobjects (different resolutions). Save the largest one'sfile_idfor instant resends with no re-upload. The media-cache plugin can automate this. captionvsparse_mode/caption_entities. They are mutually exclusive. GramIO'sformathelper producescaption_entities— never addparse_modealongside it.has_spoilerblurs the photo. Users must tap/click to reveal it. Works in private chats, groups, and channels.show_caption_above_mediafloats the caption above the photo. The default is caption below. Useful for image gallery presentations where context should appear first.
See Also
- sendDocument — Send any file (50 MB limit, no dimension constraints)
- sendVideo — Send a video
- sendMediaGroup — Send multiple photos as an album
- sendPaidMedia — Send a paid photo/video requiring Stars
- Message — The returned message object
- Files & MediaUpload — How to upload files in GramIO
- Formatting guide — Format captions with
formatand entities - Keyboards guide — Add inline keyboard to photo messages
- auto-retry plugin — Handle rate limits automatically
- media-cache plugin — Cache
file_idvalues automatically