GramJS

photos.UploadProfilePhoto

Updates current user profile photo.

Example

const { Api, TelegramClient } = require("telegram");
const { StringSession } = require("telegram/sessions");

const session = new StringSession(""); // You should put your string session here
const client = new TelegramClient(session, apiId, apiHash, {});

(async function run() {
  await client.connect(); // This assumes you have already authenticated with .start()

  const result = await client.invoke(
    new Api.photos.UploadProfilePhoto({
      file: await client.uploadFile({
        file: new CustomFile(
          "file.bin",
          fs.statSync("../file.bin").size,
          "../file.bin"
        ),
        workers: 1,
      }),
      video: await client.uploadFile({
        file: new CustomFile(
          "video.mp4",
          fs.statSync("../video.mp4").size,
          "../video.mp4"
        ),
        workers: 1,
      }),
      videoStartTs: 8.24,
    })
  );
  console.log(result); // prints the result
})();
import { Api, TelegramClient } from "telegram";
import { StringSession } from "telegram/sessions";

const session = new StringSession(""); // You should put your string session here
const client = new TelegramClient(session, apiId, apiHash, {});

(async function run() {
  await client.connect(); // This assumes you have already authenticated with .start()

  const result: Api.photos.Photo = await client.invoke(
    new Api.photos.UploadProfilePhoto({
      file: await client.uploadFile({
        file: new CustomFile(
          "file.bin",
          fs.statSync("../file.bin").size,
          "../file.bin"
        ),
        workers: 1,
      }),
      video: await client.uploadFile({
        file: new CustomFile(
          "video.mp4",
          fs.statSync("../video.mp4").size,
          "../video.mp4"
        ),
        workers: 1,
      }),
      videoStartTs: 8.24,
    })
  );
  console.log(result); // prints the result
})();

Parameters

NameTypeDescription
flags#Flags, see TL conditional fields
fileflags.0?InputFileFile saved in parts by means of upload.saveFilePart method
videoflags.1?InputFileAnimated profile picture video
videoStartTsflags.2?doubleFloating point UNIX timestamp in seconds, indicating the frame of the video that should be used as static preview.

Result

photos.Photo

Possible errors

CodeTypeDescription
400FILE_PARTS_INVALIDThe number of file parts is invalid
400IMAGE_PROCESS_FAILEDFailure while processing image
400PHOTO_CROP_FILE_MISSINGPhoto crop file missing
400PHOTO_CROP_SIZE_SMALLPhoto is too small
400PHOTO_EXT_INVALIDThe extension of the photo is invalid
400PHOTO_FILE_MISSINGProfile photo file missing
400VIDEO_FILE_INVALIDThe specified video file is invalid

Can bots use this method?

No

upload.saveFilePart

Saves a part of file for futher sending to one of the methods.

Uploading and Downloading Files

How to transfer large data batches correctly.