Sessions
- class grammers.sessions.Session
Bases:
object- cache_peer(peer_info)
- close()
- dc_option(dc_id)
- home_dc_id()
- peer(peer)
- set_dc_option(dc_option)
- set_home_dc_id(dc_id)
- set_update_state(update)
- updates_state()
- class grammers.sessions.SqliteSession(path=':memory:')
Bases:
Session- static from_telethon_string(string, path=':memory:')
- Return type:
Self- Parameters:
string (str)
path (str)
- connection()
- async init()
- Return type:
None
- async close()
- async home_dc_id()
- Return type:
int
- async set_home_dc_id(dc_id)
- Return type:
None- Parameters:
dc_id (int)
- async updates_state()
- Return type:
- async set_update_state(update)
- Return type:
None- Parameters:
update (UpdateState)
- class grammers.sessions.PeerId(id)
Bases:
objectSentinel value used to represent empty chats.
Per <https://core.telegram.org/api/bots/ids>: > […] transformed range for bot API chat dialog IDs is -999999999999 to -1 inclusively > > […] transformed range for bot API channel dialog IDs is -1997852516352 to -1000000000001 inclusively
chat_id parameters are in Telegram’s API use the bare identifier, so there’s no empty constructor, but it can be mimicked by picking the value in the correct range hole. This value is closer to “channel with ID 0” than “chat with ID 0”, but there’s no distinct -0 integer, and channels have a proper constructor for empty already.
- bare_id
Unpacked peer identifier. Panics if [Self::kind] is [PeerKind::UserSelf].
- bot_api_dialog_id
Returns the identity using the Bot API Dialog ID format.
Will return an arbitrary value if [Self::kind] is [PeerKind::UserSelf]. This value should not be relied on and may change between releases.
- static channel(id)
Creates a peer identity for a broadcast channel, megagroup, gigagroup or monoforum.
- static chat(id)
Creates a peer identity for a small group chat.
- kind
Peer kind.
- static self_user()
Creates a peer identity for the currently-logged-in user or bot account.
Internally, this will use a special sentinel value outside of any valid Bot API Dialog ID range.
- to_dict()
- static user(id)
Creates a peer identity for a user or bot account.
- class grammers.sessions.PeerInfo
Bases:
objectAn exploded peer reference along with any known useful information about the peer.
- Channel
alias of
PeerInfoChannel
- Chat
alias of
PeerInfoChat
- User
alias of
PeerInfoUser
- to_dict()
- class grammers.sessions.PeerKind
Bases:
object- Channel = PeerKind.Channel
- Chat = PeerKind.Chat
- User = PeerKind.User
- UserSelf = PeerKind.UserSelf
- to_dict()
- class grammers.sessions.ChannelKind
Bases:
object- Broadcast = ChannelKind.Broadcast
- Gigagroup = ChannelKind.Gigagroup
- Megagroup = ChannelKind.Megagroup
- to_dict()
- class grammers.sessions.DcOption(id, ipv4=None, ipv6=None, auth_key=None)
Bases:
objectA datacenter option.
This is very similar to Telegram’s own dcOption type, except it also contains the permanent authentication key and serves as a stable interface.
- auth_key
Permanent authentication key generated for encrypted communication with this datacenter.
A logged-in user may or not be bound to this authentication key.
- id
Datacenter identifier.
The primary datacenters have IDs from 1 to 5 inclusive, and are known statically by the session.
` let data = grammers_session::SessionData::default(); assert_eq!(data.dc_options.len(), 5); (1..=5).for_each(|dc_id| assert!(data.dc_options.contains_key(&dc_id))); `
- ipv4
IPv4 address corresponding to this datacenter.
- ipv6
IPv6 address corresponding to this datacenter. May actually be embedding the [Self::ipv4] address.
- class grammers.sessions.ChannelState(id, pts)
Bases:
objectUpdate state for a single channel.
- id
The [PeerId::bare_id] of the channel.
- pts
Persistent timestamp value.
- class grammers.sessions.UpdatesState(pts=Ellipsis, qts=0, date=0, seq=0, channels=Ellipsis)
Bases:
UpdateStateFull update state needed to process updates in order without gaps.
- channels
Persistent timestamp of each known channel.
- date
Auxiliary date value.
- pts
Primary persistent timestamp value.
- qts
Secondary persistent timestamp value.
- seq
Auxiliary sequence value.
- class grammers.sessions.UpdateState
Bases:
objectUsed in [crate::Session::set_update_state] to update parts of the overall [UpdatesState].
- All
alias of
UpdatesState
- class Channel(id, pts)
Bases:
UpdateState- id
- pts
- Primary
alias of
Secondary