Skip to content

sendPhoto

Use this method to send photos. On success, the sent Message is returned.

Parameters

business_connection_idStringOptional
Unique identifier of the business connection on behalf of which the message will be sent
chat_idIntegerStringRequired
Unique identifier for the target chat or username of the target channel (in the format @channelusername)
message_thread_idIntegerOptional
Unique 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_idIntegerOptional
Identifier of the direct messages topic to which the message will be sent; required if the message is sent to a direct messages chat
photoInputFileStringRequired📎 Files
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 »
captionStringOptional✏️ FormattableminLen 0maxLen 1024
Photo caption (may also be used when resending photos by file\_id), 0-1024 characters after entities parsing
parse_modeStringOptional
Mode for parsing entities in the photo caption. See formatting options for more details.
caption_entitiesMessageEntity[]Optional
A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse\_mode
show_caption_above_mediaBooleanOptional
Pass True, if the caption must be shown above the message media
has_spoilerBooleanOptional
Pass True if the photo needs to be covered with a spoiler animation
disable_notificationBooleanOptional
Sends the message silently. Users will receive a notification with no sound.
protect_contentBooleanOptional
Protects the contents of the sent message from forwarding and saving
allow_paid_broadcastBooleanOptional
Pass 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_idStringOptional
Unique identifier of the message effect to be added to the message; for private chats only
suggested_post_parametersSuggestedPostParametersOptional
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.
reply_parametersReplyParametersOptional
Description of the message to reply to
Additional 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

CodeErrorCause
400Bad Request: chat not foundchat_id is invalid or the bot has no access to that chat
400Bad Request: wrong file identifier/HTTP URL specifiedphoto is a malformed file_id or the URL is inaccessible
400Bad Request: failed to get HTTP URL contentTelegram could not download the photo from the URL — ensure it is publicly accessible
400Bad Request: PHOTO_INVALID_DIMENSIONSPhoto exceeds 10,000 total width+height or 20:1 aspect ratio — resize before sending
400Bad Request: can't parse entitiesMalformed caption_entities or bad parse_mode markup
403Forbidden: bot was blocked by the userUser blocked the bot — catch and mark as inactive
403Forbidden: not enough rights to send photosBot lacks can_send_photos permission in a restricted group
429Too Many Requests: retry after NRate 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_id after first upload. The returned Message.photo is an array of PhotoSize objects (different resolutions). Save the largest one's file_id for instant resends with no re-upload. The media-cache plugin can automate this.
  • caption vs parse_mode / caption_entities. They are mutually exclusive. GramIO's format helper produces caption_entities — never add parse_mode alongside it.
  • has_spoiler blurs the photo. Users must tap/click to reveal it. Works in private chats, groups, and channels.
  • show_caption_above_media floats the caption above the photo. The default is caption below. Useful for image gallery presentations where context should appear first.

See Also