Closed CryptoTradee closed 4 years ago
@CheshireCaat hey by any chance did you hit this bug?
It does seem like basic functionality and obviously want to minimise the number of times need to enter the auth code from Telegram. If it's a completely new session, it works ok but has the bugs indicated above if not.
@CryptoTradee could you debug it? it certainly seems this should work or has worked in the past
Without going into the source of TLSharp, yes I've debugged as much as I can
Well if it's a TLSharp bug, it needs to be debugged inside TLSharp. Just clone it instead of referencing the nuget.
I don't know anything about how TLSharp works and so even if I clone the repository, not sure I'll get far. Can use my code above and run the first time which will send the code to your Telegram and then run it again and can see if you get the same error?
Sorry I don't have time these days to hack in TLSharp. Should be easy to figure out why it's not picking up the settings from the configured dir (C:) and its session file.
If anyone runs into this problem, can modify the code above:
FileSessionStore fileSessionStore = new FileSessionStore(new DirectoryInfo("c:\"));
TLSharp.Core.TelegramClient client = new TelegramClient(ApiId, ApiHash, fileSessionStore);
await client.ConnectAsync(); //However, this has error "Invalid Packet Length"
if (!client.IsUserAuthorized())
{
var hash = await client.SendCodeRequestAsync(NumberToAuthenticate);
var code = "<code_from_telegram>"; // you can change code in debugger
var user = await client.MakeAuthAsync(NumberToAuthenticate, hash, code);
sessionStore.Save(client.Session);
}
//If skip the Connect above, get error here saying "Not Connected"
TLDialogsSlice dialogs = (TLDialogsSlice) await client.GetUserDialogsAsync();
Hello guys. Hm, this bug looks weird. I've never had this before. But i think that it's not TLSharp bug.
There is one idea - there are not enough rights to store session data in the root of C:\ drive. @CryptoTradee try to store session in other path, if you have more than one logical drive. You also can try to save session to directory like C:\Telegram\xxxx\ etc.
Let me know if it helps.
The c:\ was just for example. I was storing in a different place on my code. Actually, fixed it by adding the line: sessionStore.Save(client.Session);
after the MakeAuthAsync
Wait, maybe this should be done automatically by TLSharp? What do you think @CheshireCaat ?
@CryptoTradee, @knocte There is no need for a manual call for 'sessionStore.Save()' according to the code. Take a look:
I.e. after successfuly auth session should be automatically saved. And by my own experience it works fine. I also tried CryptoTradee code without manual session saving - it works fine too. @CryptoTradee, are you using the latest version of the library?
it seems not all methods call OnUserAuthenticated, @CryptoTradee can you tell us what method were calling in your code so that we can fix TLSharp?
Why is session expires set to int.MaxValue? Maybe the session will never expire if keep requesting otherwise when the client is stopped, the session can expire. My code is above and it seems it does call OnUserAuthenticated from MakeAuthAsync. However, without the extra save, try run my code twice and will see the second time, it doens't work when don't send the code.
@CryptoTradee, as i said before i already tested your code, it's work fine for me. Main problem with this situation it's that i can't reproduce your problem, and can't help you without more additional information.
Oh, so if you run this below code, the first time, it will send the code to your Telegram and works fine. The 2nd time, it should skip the auth code and go straight to getting the dialogs?
FileSessionStore fileSessionStore = new FileSessionStore(new DirectoryInfo("c:\\Programming\\"));
TLSharp.Core.TelegramClient client = new TelegramClient(ApiId, ApiHash, fileSessionStore);
await client.ConnectAsync(); //However, this has error "Invalid Packet Length"
if (!client.IsUserAuthorized())
{
var hash = await client.SendCodeRequestAsync(NumberToAuthenticate);
var code = "<code_from_telegram>"; // you can change code in debugger
var user = await client.MakeAuthAsync(NumberToAuthenticate, hash, code);
}
//If skip the Connect above, get error here saying "Not Connected"
TLDialogsSlice dialogs = (TLDialogsSlice) await client.GetUserDialogsAsync();
I copy-paste your code to my project again. Look at your code with small fixes for reading telegram code from console - https://pastebin.com/N3SvrSdQ
As I said many times, all is OK. It works fine. But i can get dialogs only with cast to TLDialogs, not to slice.
Ok, it seems fine now with the original code. However I still get an intermitten "cannot read packet length" error. I've gotten it on my local and on Azure. What do u want me to capture to help u fix that?
First, to open a new issue to not mix things up.
Ok, it seems fine now with the original code
What was the difference?
Seems I need to authenticate every single time as can't reuse the auth code from a previous session.
Below is the code I was using:
FileSessionStore fileSessionStore = new FileSessionStore(new DirectoryInfo("c:\")); TLSharp.Core.TelegramClient client = new TelegramClient(ApiId, ApiHash, fileSessionStore);