Python — messages and chats
freshgram.messages
Section titled “freshgram.messages”| Method | Permissions | Description |
|---|---|---|
send(chat, text, reply_to=0, topic=0, silent=False, schedule=0, markdown=False, custom_emoji=None, entities=None) |
messages.send |
send; returns Sent |
send_media(chat, data, name, caption="", kind="auto", markdown=False, reply_to, topic, silent, schedule, spoiler, duration, entities) |
messages.send |
a file up to 100 MiB; kind: auto, file, voice (OGG/Opus, needs duration) |
edit(chat, message, text, markdown=False, entities=None) |
messages.edit |
edit your own message |
edit_media(chat, message, data, name, caption="", kind="auto", ...) |
messages.edit |
replace the media, up to 100 MiB |
delete(chat, messages, everyone=True) |
messages.delete |
delete your own messages |
react(chat, message, emoji="", custom_emoji=0) |
messages.react |
a reaction; with no arguments, remove yours |
reactions(chat, message, emoji=None, custom_emoji=0, limit=50) |
messages.read |
who reacted |
forward(from_chat, messages, to_chat, silent=False) |
messages.send, messages.read |
forward |
history(chat, limit=20, before=0, topic=0, from_user=None) |
messages.history |
latest messages, newest first |
search(chat, query, limit=20) |
messages.history |
server-side search |
get(chat, message) |
messages.history |
one message by server id |
reply_chain(chat, message, limit=5) |
messages.history |
reply chain, up to 20 |
pinned(chat, limit=20) |
messages.history |
pinned messages |
scheduled(chat) / scheduled_delete(chat, ids) |
messages.history / messages.delete |
scheduled messages; scheduled returns at most 20 (the Python helper has no limit) |
pin(chat, message, silent=False) / unpin(chat, message) |
chats.manage |
pinning |
send_poll(chat, question, options, anonymous=True, multiple=False, quiz=False, correct=None, explanation="", close_period=0, ...) |
messages.send |
a poll, 2–10 options; close_period 5–600 s |
Only in the synchronous freshgram.messages (inside hooks): set_outgoing, set_incoming, hide_incoming, drop_outgoing. See Message hooks.
Message identifiers
Section titled “Message identifiers”send and send_media return Sent with local_id (known at once, valid until the app restarts) and id (the server one). The server id arrives only with the messages.ids permission — then the call waits for the server, so it is best awaited through aio. Most methods that take message accept both a Sent and a number; forward and scheduled_delete take plain ids only (a Sent is not accepted there: pass numbers such as [sent.id], which is None without messages.ids).
Formatting
Section titled “Formatting”markdown=True | "markdown" | "html". entities is a list of {"type", "offset", "length", ...} (UTF-16); not used together with markdown. custom_emoji is a list of {"offset", "length", "id"} (Premium).
freshgram.chats
Section titled “freshgram.chats”| Method | Permissions | Description |
|---|---|---|
list(limit=100) |
chats.list |
list of chats |
info(chat) |
chat.info |
chat information |
mark_read(chat) |
messages.send |
mark as read |
action(chat, kind="typing", topic=0) |
messages.send |
“typing…” and others; "cancel" stops it |
members(chat, limit=50, offset=0, query=None) |
chat.info, users.info |
members: id, name, username, role, bot |
admins(chat, limit=50, offset=0) |
chat.info, users.info |
administrators |
ban(chat, user) / unban(chat, user) |
chats.moderate |
ban/unban, only within 10 s after a user action |
mute(chat, seconds=0, forever=False) |
chats.manage |
with no arguments, unmute |
archive(chat, archived=True) |
chats.manage |
archive |
pin(chat, pinned=True) |
chats.manage |
pin the chat; limit if the list is full |
Stickers and bots
Section titled “Stickers and bots”freshgram.stickers.search("😀") # [{id, emoji, set, animated, video}]; stickers.* need messages.sendfreshgram.stickers.send(chat, sticker_id, reply_to=0, topic=0, silent=False) # returns Sent (local_id only)freshgram.stickers.recent(20)
results = freshgram.bots.inline_query("@gif", "cats") # permission bots.inlinefreshgram.bots.send_inline_result(chat, results[0]["query_id"], results[0]["id"])freshgram.bots.press_button(chat, message, row, column)