async private void Go() { string proxy = "5.101.82.125:8000:Bj9BvB:fGtkgw"; TcpClient TcpHandler(string address, int port) { string[] split = proxy.Split(':'); var socksProxy = new HttpProxyClient(split[0], int.Parse(split[1]), split[2], split[3]); var tcpClient = socksProxy.CreateConnection(address, port); return(tcpClient); } if (File.Exists("session.dat")) { var client = new TelegramClient(apiId, apiHash, sessionUserId: "session", handler: TcpHandler); await client.ConnectAsync(); FileSessionStore store = new FileSessionStore(); TLSharp.Core.Session s = null; s = store.Load("session"); //var hash = await client.SendCodeRequestAsync("79029828756"); //string code = await GetCode(); //var user = await client.MakeAuthAsync("79029828756", hash, code); var userByPhoneId = await client.SearchUserAsync("79029828756"); } else { var client = new TelegramClient(apiId, apiHash, handler: TcpHandler); await client.ConnectAsync(); var hash = await client.SendCodeRequestAsync("79029828756"); string code = await GetCode(); var user = await client.MakeAuthAsync("79029828756", hash, code); } }
public void Save(Session session) { using (var stream = new FileStream($"{session.SessionUserId}.dat", FileMode.OpenOrCreate)) { var result = session.ToBytes(); stream.Write(result, 0, result.Length); } }
public TelegramClient(ISessionStore store, string sessionUserId) { if (_apiId == 0) throw new InvalidOperationException("Your API_ID is invalid. Do a configuration first https://github.com/sochix/TLSharp#quick-configuration"); if (string.IsNullOrEmpty(_apiHash)) throw new InvalidOperationException("Your API_ID is invalid. Do a configuration first https://github.com/sochix/TLSharp#quick-configuration"); _transport = new TcpTransport(); _session = Session.TryLoadOrCreateNew(store, sessionUserId); }
public void Save(Session session) { }
public static Session TryLoadOrCreateNew(ISessionStore store, string sessionUserId) { Session session; try { session = store.Load(sessionUserId); } catch { session = new Session(store) { Id = GenerateRandomUlong(), SessionUserId = sessionUserId }; } return session; }
public TelegramClient(ISessionStore store, string sessionUserId) { _transport = new TcpTransport(); _session = Session.TryLoadOrCreateNew(store, sessionUserId); }
public static Session TryLoadOrCreateNew(ISessionStore store, string sessionUserId) { Session session; try { session = store.Load(sessionUserId); } catch { session = new Session(store) { Id = GenerateRandomUlong(), SessionUserId = sessionUserId, ServerAddress = defaultConnectionAddress, Port = defaultConnectionPort }; } return session; }