public async Task SignUpNewUser() { var store = new FileSessionStore(); var client = new TelegramClient(store, "session", apiId, apiHash); await client.Connect(); var hash = await client.SendCodeRequest(NotRegisteredNumberToSignUp); var code = ""; var registeredUser = await client.SignUp(NotRegisteredNumberToSignUp, hash, code, "TLSharp", "User"); Assert.IsNotNull(registeredUser); Assert.IsTrue(client.IsUserAuthorized()); var loggedInUser = await client.MakeAuth(NotRegisteredNumberToSignUp, hash, code); Assert.IsNotNull(loggedInUser); }
public TelegramClient(int apiId, string apiHash, ISessionStore store = null, string sessionUserId = "session", string AppVersion = "1.0", string DeviceModel = "PC", string LangCode = "en", string SystemVersion = "Windows", TcpClientConnectionHandler handler = null) { try { if (apiId == default(int)) { throw new MissingApiConfigurationException("API_ID"); } if (string.IsNullOrEmpty(apiHash)) { throw new MissingApiConfigurationException("API_HASH"); } if (store == null) { store = new FileSessionStore(); } TLContext.Init(); _apiHash = apiHash; _apiId = apiId; _appVersion = AppVersion; _DeviceModel = DeviceModel; _LangCode = LangCode; _SystemVersion = SystemVersion; _handler = handler; _session = Session.TryLoadOrCreateNew(store, sessionUserId); _transport = new TcpTransport(_session.ServerAddress, _session.Port, _handler); } catch { throw new Exception("Not connected to the internet"); } }
public TelegramClient(int apiId, string apiHash, ISessionStore store = null, string sessionUserId = "session", TcpClientConnectionHandler handler = null) { if (apiId == default(int)) { throw new MissingApiConfigurationException("API_ID"); } if (string.IsNullOrEmpty(apiHash)) { throw new MissingApiConfigurationException("API_HASH"); } if (store == null) { store = new FileSessionStore(); } TLContext.Init(); _apiHash = apiHash; _apiId = apiId; _handler = handler; _session = Session.TryLoadOrCreateNew(store, sessionUserId); _transport = new TcpTransport(_session.ServerAddress, _session.Port, _handler); }
public TelegramClient() { var store = new FileSessionStore(); _transport = new TcpTransport(); _session = Session.TryLoadOrCreateNew(store, sessionUserId); }
/// <summary> /// Creates a new TelegramClient /// </summary> /// <param name="apiId">The API ID provided by Telegram. Get one at https://my.telegram.org </param> /// <param name="apiHash">The API Hash provided by Telegram. Get one at https://my.telegram.org </param> /// <param name="store">An ISessionStore object that will handle the session</param> /// <param name="sessionUserId">The name of the session that tracks login info about this TelegramClient connection</param> /// <param name="handler">A delegate to invoke when a connection is needed and that will return a TcpClient that will be used to connect</param> /// <param name="dcIpVersion">Indicates the preferred IpAddress version to use to connect to a Telegram server</param> public TelegramClient(int apiId, string apiHash, ISessionStore store = null, string sessionUserId = "session", TcpClientConnectionHandler handler = null, DataCenterIPVersion dcIpVersion = DataCenterIPVersion.Default) { if (apiId == default(int)) { throw new MissingApiConfigurationException("API_ID"); } if (string.IsNullOrEmpty(apiHash)) { throw new MissingApiConfigurationException("API_HASH"); } if (store == null) { store = new FileSessionStore(); } this.apiHash = apiHash; this.apiId = apiId; this.handler = handler; this.dcIpVersion = dcIpVersion; session = Session.TryLoadOrCreateNew(store, sessionUserId); transport = new TcpTransport(session.DataCenter.Address, session.DataCenter.Port, this.handler); }
public MainWindow() { InitializeComponent(); TLSharp.Core.FileSessionStore store = new TLSharp.Core.FileSessionStore(); client = new TelegramClient(api_id, api_hash, store, "session"); }
public async Task CheckPhones() { var store = new FileSessionStore(); var client = new TelegramClient(store, "session"); await client.Connect(); var result = await client.IsPhoneRegistered(NumberToAuthenticate); Assert.IsTrue(result); }
public async Task AuthUser() { var store = new FileSessionStore(); var client = new TelegramClient(store, "session"); await client.Connect(); var hash = await client.SendCodeRequest(NumberToAuthenticate); var code = "123"; // you can change code in debugger var user = await client.MakeAuth(NumberToAuthenticate, hash, code); Assert.IsNotNull(user); }
public async Task ImportContact() { // User should be already authenticated! var store = new FileSessionStore(); var client = new Core.TelegramClient(store, "session"); await client.Connect(); Assert.IsTrue(client.IsUserAuthorized()); var res = await client.ImportContact(RegisteredNumber); Assert.IsNotNull(res); }
public async Task ImportContactByPhoneNumber() { // User should be already authenticated! var store = new FileSessionStore(); var client = new TelegramClient(store, "session"); await client.Connect(); Assert.IsTrue(client.IsUserAuthorized()); var res = await client.ImportContactByPhoneNumber(NumberToSendMessage); Assert.IsNotNull(res); }
public async Task AuthUser() { var store = new FileSessionStore(); var client = new TelegramClient(store, "session"); await client.Connect(); var hash = await client.SendCodeRequest("375257307554"); var code = "70342"; // you can change code in debugger var t = Console.ReadLine(); code = t; var user = await client.MakeAuth("375257307554", hash, code); Console.WriteLine("fdfdfdfd"); var userByPhoneId = await client.ImportContactByPhoneNumber("375293088998"); await client.SendMessage(userByPhoneId.Value, "Hello Habr!"); Assert.IsNotNull(user); var hist = await client.GetMessagesHistoryForContact(userByPhoneId.Value, 0, 1000); hist.Count(); }
public async Task CheckPhones() { var store = new FileSessionStore(); var client = new Core.TelegramClient(store, "session"); await client.Connect(); var phoneList = new string[] { RegisteredNumber, NumberToAuthenticate }; var rand = new Random(); foreach (var phone in phoneList) { var result = await client.IsPhoneRegistered(phone); Thread.Sleep(rand.Next(9) * 1000); if (result) Console.WriteLine($"{phone} - OK"); } }
public TelegramClient(int apiId, string apiHash, ISessionStore store = null, string sessionUserId = "session") { if (store == null) { store = new FileSessionStore(); } TLContext.Init(); _apiHash = apiHash; _apiId = apiId; 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"); } _session = Session.TryLoadOrCreateNew(store, sessionUserId); _transport = new TcpTransport(_session.ServerAddress, _session.Port); }
public TlSharpCl() { Store = new FileSessionStore(); Client = new TelegramClient(Store, "session"); }
public async Task GetHistory() { var store = new FileSessionStore(); var client = new TelegramClient(store, "session"); await client.Connect(); Assert.IsTrue(client.IsUserAuthorized()); var res = await client.ImportContactByPhoneNumber(NumberToSendMessage); Assert.IsNotNull(res); var hist = await client.GetMessagesHistoryForContact(res.Value, 0, 5); Assert.IsNotNull(hist); }
public async Task ImportByUserNameAndSendMessage() { var store = new FileSessionStore(); var client = new TelegramClient(store, "session"); await client.Connect(); Assert.IsTrue(client.IsUserAuthorized()); var res = await client.ImportByUserName(UserNameToSendMessage); Assert.IsNotNull(res); await client.SendMessage(res.Value, "Test message from TelegramClient"); }
public async Task UploadAndSendMedia() { var store = new FileSessionStore(); var client = new TelegramClient(store, "session"); await client.Connect(); Assert.IsTrue(client.IsUserAuthorized()); var res = await client.ImportContactByPhoneNumber(NumberToSendMessage); Assert.IsNotNull(res); const string testFile = "TEST"; var file = File.ReadAllBytes("../../data/cat.jpg"); var mediaFile = await client.UploadFile("test_file.jpg", file); Assert.IsNotNull(mediaFile); var state = await client.SendMediaMessage(res.Value, mediaFile); Assert.IsTrue(state); }