Python — users, media, image and more
freshgram.users (users.info)
Section titled “freshgram.users (users.info)”info(user), resolve(username) (once per second), photo(user) → {"mime", "data"} (MP4 for a video avatar, otherwise JPEG), block(user) / unblock(user) (contacts.manage).
freshgram.channels (chat.info)
Section titled “freshgram.channels (chat.info)”info(channel), resolve(username), photo(channel).
freshgram.media (media.read)
Section titled “freshgram.media (media.read)”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.
freshgram.image (image.process)
Section titled “freshgram.image (image.process)”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 noreplaceargument: with a non-empty draft it raisesInvalid(“the draft is not empty, pass replace”). To overwrite, use the raw callfreshgram.call({"op": "composer.set_draft", "a": {"chat": chat, "text": text, "replace": True}}).fs.listreturns{"entries": [{"name", "dir", "size", "modified"}], "more"};offsetandlimitpage through it (up to 1000 per page).fs.readreads fromoffsetup tolengthbytes (the whole file by default).fs.writemodeis"replace","create"or"append".fs.rename(source, target)sends the wire argumentsfromandto.files.pickreturns{"name", "data"}orNonewhen cancelled;files.savereturnsTrueorFalse(cancelled).- The failure messages of these calls are listed in Errors and limits.
