setMyProfilePhoto
Changes the profile photo of the bot. Returns True on success.
Parameters
The new profile photo to set
Returns
On success, True is returned.
GramIO Usage
ts
// Set a static profile photo from a local file
await bot.api.setMyProfilePhoto({
photo: {
type: "static",
photo: await MediaUpload.path("./avatar.jpg"),
},
});ts
// Set an animated profile photo (MPEG4, up to 5s, 640×640)
await bot.api.setMyProfilePhoto({
photo: {
type: "animated",
animation: await MediaUpload.path("./avatar.mp4"),
main_frame_timestamp: 0,
},
});ts
// Set a static photo from a URL
await bot.api.setMyProfilePhoto({
photo: {
type: "static",
photo: await MediaUpload.url("https://example.com/avatar.jpg"),
},
});Errors
| Code | Error | Cause |
|---|---|---|
| 400 | Bad Request: PHOTO_INVALID_DIMENSIONS | Image dimensions are too large or the aspect ratio is not supported |
| 400 | Bad Request: wrong file identifier/HTTP URL specified | The URL is not accessible by Telegram's servers, or the file_id is invalid |
| 400 | Bad Request: failed to get HTTP URL content | Telegram could not download the file from the provided URL — check the URL is publicly accessible |
| 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
- Profile photos cannot be reused by file_id. Unlike regular media, profile photos must always be uploaded as new files — you cannot pass an existing
file_id. UseMediaUpload.path()orMediaUpload.url(). - Two types:
staticandanimated.staticaccepts a.jpgimage;animatedaccepts an MPEG4 video (up to 5 seconds, 640×640 pixels, 30fps recommended). Set thetypefield accordingly. main_frame_timestampfor animated photos. When uploading an animated photo, setmain_frame_timestampto the second (as a float) that should be used as the static thumbnail. Defaults to0.- Use
removeMyProfilePhototo delete the current photo. To revert to the default Telegram avatar, call removeMyProfilePhoto instead. - File uploads are async.
MediaUpload.path()andMediaUpload.url()return Promises — alwaysawaitthem before passing to the API call.
See Also
- removeMyProfilePhoto — remove the bot's profile photo
- InputProfilePhoto — union type for static and animated profile photos
- InputProfilePhotoStatic — static JPG photo type
- InputProfilePhotoAnimated — animated MPEG4 photo type
- Media Upload guide — how to upload files with GramIO