grammers
grammers copied to clipboard
Can't get entity if the type is PeerUser.
Going from the examples, entity_set.get(&message.chat()) works fine for PeerChannel but when a it's a User the entity returns as None every time.
Obviously this means
let peer = entity_set
.get(&message.chat())
.expect("failed to find entity");
Fails on every update from a user.
I'm still not sure how I'd like to design dealing with entities and access hashes in the library. The most likely problem here is that Telegram simply doesn't bother to send user information in updates, but for some reason generally sends channel information. If the library is missing an access hash, it's supposed to call getDifference which we don't do yet. The code should handle users just fine were they in the update though:
https://github.com/Lonami/grammers/blob/f4989748aaa1ad401301463f3b565391611a73d0/lib/grammers-client/src/types/entity_set.rs#L35-L42
I see, that makes sense thanks.
Could I then use GetUserInfo with info from the update array?
I see it uses InputUser but I am unsure how and where to get the access_hash for the user or even how it works.
I'm trying to get the usernames from incoming messages and other basic user info but the entity thing kinda snagged me. Otherwise I'm having solid success with Grammers.
Telegram rules are a bit weird. In theory, you need the id and access_hash for some "entity" (user or channel) to be able to use it (like fetch more information). Other times, using 0 as the access hash with the correct id works (I have no idea why, when or how).
The most reliable option is to get the entity in some way you know you can find it. If it's a private conversation, getting dialogs will find the entity there with all the information. If it's a chat, fetch the chat then recent messages to get the sender. Then the access hash may be cached (how to store these access hashes, given their importance, is another detail that needs to be worked out for grammers to be usable).
Thanks for the info I appreciate it. And sorry for asking relatively basic information but which functions/structs should I be looking at to get the dialog from a private conversation?
Pretty much just trying to get user info on message, quite a challenge.
No problem for asking, the library is extremely young, so finding where people struggle is key to work on those rough edges. Dialogs are fetched with messages::GetDialogs. grammers needs to figure out a way to provide asynchronous iterators for all these kind of "get" methods with offsets, much like it works in Telethon.
Once there are more friendly methods, the challenge should become trivial, but raw API is a bit annoying to work with.
Is there another way to use these get methods other than using client.invoke()? Becuase messages::GetDialogs still requires offset_peer (Which I'm of unsure what it is) which in turn needs an access_hash as a result of it being InputPeer.
Not until friendly methods for them are made. You need to use InputPeerEmpty as the first offset.
Worked like an absolute charm, thanks for the help!
Another thing I've noticed, (please do tell me if I'm actually supposed to make a new issue for this) is that the print_dialogs.rs example has a use grammers_client::{AuthorizationError, Client, Dialogs, InvocationError}; but I get the error
error[E0432]: unresolved import `grammers_client::Dialogs`
--> src\main.rs:11:43
|
11 | use grammers_client::{AuthorizationError, Dialogs, Client, Config, InvocationError};
| ^^^^^^^ no `Dialogs` in the root
Yes, that example is broken, I removed the async iterator methods for the time being but forgot to remove that.
Another beginner question because I'm losing my mind,
I run GetDialogs with the following:
let get_dialogs = &func::messages::GetDialogs{
exclude_pinned: false,
folder_id: None,
offset_date: 0,
offset_id: 0,
offset_peer: grammers_tl_types::enums::InputPeer::Empty(grammers_tl_types::types::InputPeerEmpty{}),
limit: 5000,
hash: 0,
};
let dialogs_req = client.invoke(get_dialogs).await?;
dialogs_req returns the enum grammers_tl_types::generated::enums::messages::Dialogs and I can see all the data as a Slice( DialogsSlice{ } )
How do I access the values inside the enum? I've tried a few things now and I can't seem to figure it out.
Let's move to https://t.me/gramme_rs, this usage talk is getting too much for GitHub issues.
it's supposed to call
getDifferencewhich we don't do yet
The library now does this and in general tries to recover missed users (not always possible, but works most of the time now). It also has the concept of PackedChat which eases working with entities.