Skip to content

Python — users, media, image and more

info(user), resolve(username) (once per second), photo(user) → {"mime", "data"} (MP4 for a video avatar, otherwise JPEG), block(user) / unblock(user) (contacts.manage).

info(channel), resolve(username), photo(channel).

get(chat, message, thumbnail=False, download=False) — the file of a message: kind, mime, name, data (up to 100 MiB). download=True downloads a file that is not on the device yet (up to five minutes; better through aio). list(chat, kind="any", limit=20, before=0) — messages with media; kind: photo, video, photo_video, file, voice, round, audio, gif, any.

The app decodes and encodes pictures: PNG, JPEG, WebP up to 16 MiB; animated pictures are not supported; at most 24 megapixels; at most one call per 100 ms. Every answer is {"format", "width", "height", "data"}.

Method Description
info(data) format and size
resize(data, width=0, height=0, fit="contain", format=None, quality=90) fit: contain, cover, exact; up to 8192 px
convert(data, format, quality=90) to png, jpeg, webp
crop(data, x, y, width, height, format=None, quality=90) crop
Namespace Methods Permissions
account info() account.info
stars balance() stars.balance
composer draft(chat), set_draft(chat, text), insert(chat, text) composer.draft
contacts list(limit=200), add(user, first_name, last_name="") contacts.list, contacts.manage
folders list() folders.list
settings read() settings.read
ghost get(), set(enabled) ghost.control
badges set(user, items), clear() ui.badges
notify show(text, title="") notifications
clipboard write(text), read() clipboard
files (aio only) pick(title="", filter=""), save(name, data) fs.user_selected
fs (aio only) list(path="", offset=0, limit=200), stat(path), read(path, offset=0, length=None), write(path, data, mode="replace"), mkdir(path), remove(path), rename(source, target) fs.folder

Notes:

  • composer.set_draft(chat, text) has no replace argument: with a non-empty draft it raises Invalid (“the draft is not empty, pass replace”). To overwrite, use the raw call freshgram.call({"op": "composer.set_draft", "a": {"chat": chat, "text": text, "replace": True}}).
  • fs.list returns {"entries": [{"name", "dir", "size", "modified"}], "more"}; offset and limit page through it (up to 1000 per page). fs.read reads from offset up to length bytes (the whole file by default). fs.write mode is "replace", "create" or "append". fs.rename(source, target) sends the wire arguments from and to.
  • files.pick returns {"name", "data"} or None when cancelled; files.save returns True or False (cancelled).
  • The failure messages of these calls are listed in Errors and limits.