From dfc89dc3ab2ddcb12f77b236b777cb304d3d478d Mon Sep 17 00:00:00 2001 From: Salar Khalilzadeh Date: Mon, 19 Dec 2016 18:30:30 +0330 Subject: [PATCH 01/33] Tests: Use OfType() instead of GetType() == typeof() --- TLSharp.Tests/TLSharpTests.cs | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/TLSharp.Tests/TLSharpTests.cs b/TLSharp.Tests/TLSharpTests.cs index 3b2236a..6166067 100644 --- a/TLSharp.Tests/TLSharpTests.cs +++ b/TLSharp.Tests/TLSharpTests.cs @@ -172,8 +172,7 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .Where(x => x.GetType() == typeof(TLUser)) - .Cast() + .OfType() .FirstOrDefault(x => x.phone == normalizedNumber); if (user == null) @@ -194,8 +193,7 @@ namespace TLSharp.Tests var dialogs = (TLDialogs) await client.GetUserDialogsAsync(); var chat = dialogs.chats.lists - .Where(c => c.GetType() == typeof(TLChannel)) - .Cast() + .OfType() .FirstOrDefault(c => c.title == "TestGroup"); await client.SendMessageAsync(new TLInputPeerChannel() { channel_id = chat.id, access_hash = chat.access_hash.Value }, "TEST MSG"); @@ -210,8 +208,7 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .Where(x => x.GetType() == typeof(TLUser)) - .Cast() + .OfType() .FirstOrDefault(x => x.phone == NumberToSendMessage); var fileResult = (TLInputFile)await client.UploadFile("cat.jpg", new StreamReader("data/cat.jpg")); @@ -227,8 +224,7 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .Where(x => x.GetType() == typeof(TLUser)) - .Cast() + .OfType() .FirstOrDefault(x => x.phone == NumberToSendMessage); var fileResult = (TLInputFileBig)await client.UploadFile("some.zip", new StreamReader("")); @@ -250,21 +246,18 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .Where(x => x.GetType() == typeof(TLUser)) - .Cast() + .OfType() .FirstOrDefault(x => x.phone == NumberToSendMessage); var inputPeer = new TLInputPeerUser() { user_id = user.id }; var res = await client.SendRequestAsync(new TLRequestGetHistory() { peer = inputPeer }); var document = res.messages.lists - .Where(m => m.GetType() == typeof(TLMessage)) - .Cast() - .Where(m => m.media != null && m.media.GetType() == typeof(TLMessageMediaDocument)) + .OfType() + .Where(m => m.media != null) .Select(m => m.media) - .Cast() - .Where(md => md.document.GetType() == typeof(TLDocument)) + .OfType() .Select(md => md.document) - .Cast() + .OfType() .First(); var resFile = await client.GetFile( @@ -288,8 +281,7 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .Where(x => x.GetType() == typeof(TLUser)) - .Cast() + .OfType() .FirstOrDefault(x => x.id == 5880094); var photo = ((TLUserProfilePhoto)user.photo); From 31df61a479b6876eeb5bb626c42e0ae6bc63195a Mon Sep 17 00:00:00 2001 From: Salar Khalilzadeh Date: Mon, 19 Dec 2016 18:30:30 +0330 Subject: [PATCH 02/33] Tests: Use OfType() instead of GetType() == typeof() --- TLSharp.Tests/TLSharpTests.cs | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/TLSharp.Tests/TLSharpTests.cs b/TLSharp.Tests/TLSharpTests.cs index 3b2236a..6166067 100644 --- a/TLSharp.Tests/TLSharpTests.cs +++ b/TLSharp.Tests/TLSharpTests.cs @@ -172,8 +172,7 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .Where(x => x.GetType() == typeof(TLUser)) - .Cast() + .OfType() .FirstOrDefault(x => x.phone == normalizedNumber); if (user == null) @@ -194,8 +193,7 @@ namespace TLSharp.Tests var dialogs = (TLDialogs) await client.GetUserDialogsAsync(); var chat = dialogs.chats.lists - .Where(c => c.GetType() == typeof(TLChannel)) - .Cast() + .OfType() .FirstOrDefault(c => c.title == "TestGroup"); await client.SendMessageAsync(new TLInputPeerChannel() { channel_id = chat.id, access_hash = chat.access_hash.Value }, "TEST MSG"); @@ -210,8 +208,7 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .Where(x => x.GetType() == typeof(TLUser)) - .Cast() + .OfType() .FirstOrDefault(x => x.phone == NumberToSendMessage); var fileResult = (TLInputFile)await client.UploadFile("cat.jpg", new StreamReader("data/cat.jpg")); @@ -227,8 +224,7 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .Where(x => x.GetType() == typeof(TLUser)) - .Cast() + .OfType() .FirstOrDefault(x => x.phone == NumberToSendMessage); var fileResult = (TLInputFileBig)await client.UploadFile("some.zip", new StreamReader("")); @@ -250,21 +246,18 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .Where(x => x.GetType() == typeof(TLUser)) - .Cast() + .OfType() .FirstOrDefault(x => x.phone == NumberToSendMessage); var inputPeer = new TLInputPeerUser() { user_id = user.id }; var res = await client.SendRequestAsync(new TLRequestGetHistory() { peer = inputPeer }); var document = res.messages.lists - .Where(m => m.GetType() == typeof(TLMessage)) - .Cast() - .Where(m => m.media != null && m.media.GetType() == typeof(TLMessageMediaDocument)) + .OfType() + .Where(m => m.media != null) .Select(m => m.media) - .Cast() - .Where(md => md.document.GetType() == typeof(TLDocument)) + .OfType() .Select(md => md.document) - .Cast() + .OfType() .First(); var resFile = await client.GetFile( @@ -288,8 +281,7 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .Where(x => x.GetType() == typeof(TLUser)) - .Cast() + .OfType() .FirstOrDefault(x => x.id == 5880094); var photo = ((TLUserProfilePhoto)user.photo); From 14c0c21bcf4a42df517ba641e63d71cdab6ad816 Mon Sep 17 00:00:00 2001 From: salar2k Date: Wed, 21 Dec 2016 12:18:40 +0330 Subject: [PATCH 03/33] Revert "Tests: Use OfType() instead of GetType() == typeof()" This reverts commit 31df61a479b6876eeb5bb626c42e0ae6bc63195a. --- TLSharp.Tests/TLSharpTests.cs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/TLSharp.Tests/TLSharpTests.cs b/TLSharp.Tests/TLSharpTests.cs index 6166067..3b2236a 100644 --- a/TLSharp.Tests/TLSharpTests.cs +++ b/TLSharp.Tests/TLSharpTests.cs @@ -172,7 +172,8 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .OfType() + .Where(x => x.GetType() == typeof(TLUser)) + .Cast() .FirstOrDefault(x => x.phone == normalizedNumber); if (user == null) @@ -193,7 +194,8 @@ namespace TLSharp.Tests var dialogs = (TLDialogs) await client.GetUserDialogsAsync(); var chat = dialogs.chats.lists - .OfType() + .Where(c => c.GetType() == typeof(TLChannel)) + .Cast() .FirstOrDefault(c => c.title == "TestGroup"); await client.SendMessageAsync(new TLInputPeerChannel() { channel_id = chat.id, access_hash = chat.access_hash.Value }, "TEST MSG"); @@ -208,7 +210,8 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .OfType() + .Where(x => x.GetType() == typeof(TLUser)) + .Cast() .FirstOrDefault(x => x.phone == NumberToSendMessage); var fileResult = (TLInputFile)await client.UploadFile("cat.jpg", new StreamReader("data/cat.jpg")); @@ -224,7 +227,8 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .OfType() + .Where(x => x.GetType() == typeof(TLUser)) + .Cast() .FirstOrDefault(x => x.phone == NumberToSendMessage); var fileResult = (TLInputFileBig)await client.UploadFile("some.zip", new StreamReader("")); @@ -246,18 +250,21 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .OfType() + .Where(x => x.GetType() == typeof(TLUser)) + .Cast() .FirstOrDefault(x => x.phone == NumberToSendMessage); var inputPeer = new TLInputPeerUser() { user_id = user.id }; var res = await client.SendRequestAsync(new TLRequestGetHistory() { peer = inputPeer }); var document = res.messages.lists - .OfType() - .Where(m => m.media != null) + .Where(m => m.GetType() == typeof(TLMessage)) + .Cast() + .Where(m => m.media != null && m.media.GetType() == typeof(TLMessageMediaDocument)) .Select(m => m.media) - .OfType() + .Cast() + .Where(md => md.document.GetType() == typeof(TLDocument)) .Select(md => md.document) - .OfType() + .Cast() .First(); var resFile = await client.GetFile( @@ -281,7 +288,8 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .OfType() + .Where(x => x.GetType() == typeof(TLUser)) + .Cast() .FirstOrDefault(x => x.id == 5880094); var photo = ((TLUserProfilePhoto)user.photo); From 0672086943e14654451163e044e2443cd6a29df0 Mon Sep 17 00:00:00 2001 From: salar2k Date: Wed, 21 Dec 2016 12:18:51 +0330 Subject: [PATCH 04/33] Revert "Revert "Tests: Use OfType() instead of GetType() == typeof()"" This reverts commit 14c0c21bcf4a42df517ba641e63d71cdab6ad816. --- TLSharp.Tests/TLSharpTests.cs | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/TLSharp.Tests/TLSharpTests.cs b/TLSharp.Tests/TLSharpTests.cs index 3b2236a..6166067 100644 --- a/TLSharp.Tests/TLSharpTests.cs +++ b/TLSharp.Tests/TLSharpTests.cs @@ -172,8 +172,7 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .Where(x => x.GetType() == typeof(TLUser)) - .Cast() + .OfType() .FirstOrDefault(x => x.phone == normalizedNumber); if (user == null) @@ -194,8 +193,7 @@ namespace TLSharp.Tests var dialogs = (TLDialogs) await client.GetUserDialogsAsync(); var chat = dialogs.chats.lists - .Where(c => c.GetType() == typeof(TLChannel)) - .Cast() + .OfType() .FirstOrDefault(c => c.title == "TestGroup"); await client.SendMessageAsync(new TLInputPeerChannel() { channel_id = chat.id, access_hash = chat.access_hash.Value }, "TEST MSG"); @@ -210,8 +208,7 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .Where(x => x.GetType() == typeof(TLUser)) - .Cast() + .OfType() .FirstOrDefault(x => x.phone == NumberToSendMessage); var fileResult = (TLInputFile)await client.UploadFile("cat.jpg", new StreamReader("data/cat.jpg")); @@ -227,8 +224,7 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .Where(x => x.GetType() == typeof(TLUser)) - .Cast() + .OfType() .FirstOrDefault(x => x.phone == NumberToSendMessage); var fileResult = (TLInputFileBig)await client.UploadFile("some.zip", new StreamReader("")); @@ -250,21 +246,18 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .Where(x => x.GetType() == typeof(TLUser)) - .Cast() + .OfType() .FirstOrDefault(x => x.phone == NumberToSendMessage); var inputPeer = new TLInputPeerUser() { user_id = user.id }; var res = await client.SendRequestAsync(new TLRequestGetHistory() { peer = inputPeer }); var document = res.messages.lists - .Where(m => m.GetType() == typeof(TLMessage)) - .Cast() - .Where(m => m.media != null && m.media.GetType() == typeof(TLMessageMediaDocument)) + .OfType() + .Where(m => m.media != null) .Select(m => m.media) - .Cast() - .Where(md => md.document.GetType() == typeof(TLDocument)) + .OfType() .Select(md => md.document) - .Cast() + .OfType() .First(); var resFile = await client.GetFile( @@ -288,8 +281,7 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .Where(x => x.GetType() == typeof(TLUser)) - .Cast() + .OfType() .FirstOrDefault(x => x.id == 5880094); var photo = ((TLUserProfilePhoto)user.photo); From 47d1c10c9dc57074dcf3ad2120b1bc5617508230 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Wed, 28 Dec 2016 15:37:34 +0100 Subject: [PATCH 05/33] Search user by username with send message test. (#356) * Search user by username with send message test. --- TLSharp.Core/TelegramClient.cs | 17 +++++++++++++ TLSharp.Tests.NUnit/Test.cs | 6 +++++ TLSharp.Tests.VS/TLSharpTestsVs.cs | 6 +++++ TLSharp.Tests/TLSharpTests.cs | 38 ++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+) diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index 7cf7e5d..732adad 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -337,6 +337,23 @@ namespace TLSharp.Core await _sender.SendPingAsync(); } + /// + /// Serch user or chat. API: contacts.search#11f812d8 q:string limit:int = contacts.Found; + /// + /// User or chat name + /// Max result count + /// + public async Task SearchUserAsync(string q, int limit = 10) + { + var r = new TeleSharp.TL.Contacts.TLRequestSearch + { + q = q, + limit = limit + }; + + return await SendRequestAsync(r); + } + private void OnUserAuthenticated(TLUser TLUser) { _session.TLUser = TLUser; diff --git a/TLSharp.Tests.NUnit/Test.cs b/TLSharp.Tests.NUnit/Test.cs index 7c390db..40e54ac 100644 --- a/TLSharp.Tests.NUnit/Test.cs +++ b/TLSharp.Tests.NUnit/Test.cs @@ -75,5 +75,11 @@ namespace TLSharp.Tests { await base.FloodExceptionShouldNotCauseCannotReadPackageLengthError(); } + + [Test] + public override async Task SendMessageByUserNameTest() + { + await base.SendMessageByUserNameTest(); + } } } diff --git a/TLSharp.Tests.VS/TLSharpTestsVs.cs b/TLSharp.Tests.VS/TLSharpTestsVs.cs index fff25b6..8f6c58d 100644 --- a/TLSharp.Tests.VS/TLSharpTestsVs.cs +++ b/TLSharp.Tests.VS/TLSharpTestsVs.cs @@ -73,5 +73,11 @@ namespace TLSharp.Tests { await base.FloodExceptionShouldNotCauseCannotReadPackageLengthError(); } + + [TestMethod] + public override async Task SendMessageByUserNameTest() + { + await base.SendMessageByUserNameTest(); + } } } diff --git a/TLSharp.Tests/TLSharpTests.cs b/TLSharp.Tests/TLSharpTests.cs index 6166067..487b535 100644 --- a/TLSharp.Tests/TLSharpTests.cs +++ b/TLSharp.Tests/TLSharpTests.cs @@ -323,6 +323,7 @@ namespace TLSharp.Tests var result = await client.IsPhoneRegisteredAsync(NumberToAuthenticate); Assert.IsTrue(result); } + public virtual async Task FloodExceptionShouldNotCauseCannotReadPackageLengthError() { for (int i = 0; i < 50; i++) @@ -338,5 +339,42 @@ namespace TLSharp.Tests } } } + + public virtual async Task SendMessageByUserNameTest() + { + UserNameToSendMessage = ConfigurationManager.AppSettings[nameof(UserNameToSendMessage)]; + if (string.IsNullOrWhiteSpace(UserNameToSendMessage)) + throw new Exception($"Please fill the '{nameof(UserNameToSendMessage)}' setting in app.config file first"); + + var client = NewClient(); + + await client.ConnectAsync(); + + var result = await client.SearchUserAsync(UserNameToSendMessage); + + var user = result.users.lists + .Where(x => x.GetType() == typeof(TLUser)) + .OfType() + .FirstOrDefault(x => x.username == UserNameToSendMessage.TrimStart('@')); + + if (user == null) + { + var contacts = await client.GetContactsAsync(); + + user = contacts.users.lists + .Where(x => x.GetType() == typeof(TLUser)) + .OfType() + .FirstOrDefault(x => x.username == UserNameToSendMessage.TrimStart('@')); + } + + if (user == null) + { + throw new System.Exception("Username was not found: " + UserNameToSendMessage); + } + + await client.SendTypingAsync(new TLInputPeerUser() { user_id = user.id }); + Thread.Sleep(3000); + await client.SendMessageAsync(new TLInputPeerUser() { user_id = user.id }, "TEST"); + } } } From 5e6cf484903764e4d13637c5b9fb2ae26e94c084 Mon Sep 17 00:00:00 2001 From: Starli0n Date: Mon, 9 Jan 2017 18:25:55 +0100 Subject: [PATCH 06/33] Add GetHistoryAsync() to TelegramClient --- README.md | 1 + TLSharp.Core/TelegramClient.cs | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8cdba23..4304ce5 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,7 @@ For your convenience TLSharp have wrappers for several Telegram API methods. You 1. GetFile 1. UploadFile 1. SendPingAsync +1. GetHistoryAsync **What if you can't find needed method at the list?** diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index 732adad..1847f4b 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; -using System.Web; using TeleSharp.TL; using TeleSharp.TL.Account; using TeleSharp.TL.Auth; @@ -15,7 +14,6 @@ using TeleSharp.TL.Upload; using TLSharp.Core.Auth; using TLSharp.Core.MTProto.Crypto; using TLSharp.Core.Network; -using TLSharp.Core.Requests; using TLSharp.Core.Utils; using TLAuthorization = TeleSharp.TL.Auth.TLAuthorization; @@ -335,6 +333,21 @@ namespace TLSharp.Core public async Task SendPingAsync() { await _sender.SendPingAsync(); + } + + public async Task GetHistoryAsync(TLAbsInputPeer peer, int offset, int max_id, int limit) + { + if (!IsUserAuthorized()) + throw new InvalidOperationException("Authorize user first!"); + + var req = new TLRequestGetHistory() + { + peer = peer, + add_offset = offset, + max_id = max_id, + limit = limit + }; + return await SendRequestAsync(req); } /// From a753a1ab136a287559b028ccc7522212882140e0 Mon Sep 17 00:00:00 2001 From: Starli0n Date: Thu, 19 Jan 2017 19:31:27 +0100 Subject: [PATCH 07/33] Add offset parameter to GetFile() method --- TLSharp.Core/TelegramClient.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index 1847f4b..9674ee8 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -290,7 +290,7 @@ namespace TLSharp.Core }); } - public async Task GetFile(TLAbsInputFileLocation location, int filePartSize) + public async Task GetFile(TLAbsInputFileLocation location, int filePartSize, int offset = 0) { TLFile result = null; try @@ -298,7 +298,8 @@ namespace TLSharp.Core result = await SendRequestAsync(new TLRequestGetFile() { location = location, - limit = filePartSize + limit = filePartSize, + offset = offset }); } catch (FileMigrationException ex) From 48077961ae730f84f1624f131dd42eb70db18cb6 Mon Sep 17 00:00:00 2001 From: Starli0n Date: Fri, 27 Jan 2017 10:58:47 +0100 Subject: [PATCH 08/33] Custom TCP hanlder to allow HTTP proxy auth --- TLSharp.Core/Network/TcpTransport.cs | 18 ++++++++++++------ TLSharp.Core/TelegramClient.cs | 9 ++++++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/TLSharp.Core/Network/TcpTransport.cs b/TLSharp.Core/Network/TcpTransport.cs index 9092828..254153e 100644 --- a/TLSharp.Core/Network/TcpTransport.cs +++ b/TLSharp.Core/Network/TcpTransport.cs @@ -1,22 +1,28 @@ using System; -using System.Linq; using System.Net; using System.Net.Sockets; using System.Threading.Tasks; namespace TLSharp.Core.Network { + public delegate TcpClient TcpClientConnectionHandler(string address, int port); + public class TcpTransport : IDisposable { private readonly TcpClient _tcpClient; private int sendCounter = 0; - public TcpTransport(string address, int port) + public TcpTransport(string address, int port, TcpClientConnectionHandler handler = null) { - _tcpClient = new TcpClient(); + if (handler == null) + { + _tcpClient = new TcpClient(); - var ipAddress = IPAddress.Parse(address); - _tcpClient.Connect(ipAddress, port); + var ipAddress = IPAddress.Parse(address); + _tcpClient.Connect(ipAddress, port); + } + else + _tcpClient = handler(address, port); } public async Task Send(byte[] packet) @@ -84,6 +90,6 @@ namespace TLSharp.Core.Network { if (_tcpClient.Connected) _tcpClient.Close(); - } + } } } diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index 9674ee8..d4efdb1 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -28,8 +28,10 @@ namespace TLSharp.Core private int _apiId = 0; private Session _session; private List dcOptions; + private TcpClientConnectionHandler _handler; - public TelegramClient(int apiId, string apiHash, ISessionStore store = null, string sessionUserId = "session") + public TelegramClient(int apiId, string apiHash, + ISessionStore store = null, string sessionUserId = "session", TcpClientConnectionHandler handler = null) { if (apiId == default(int)) throw new MissingApiConfigurationException("API_ID"); @@ -42,9 +44,10 @@ namespace TLSharp.Core TLContext.Init(); _apiHash = apiHash; _apiId = apiId; + _handler = handler; _session = Session.TryLoadOrCreateNew(store, sessionUserId); - _transport = new TcpTransport(_session.ServerAddress, _session.Port); + _transport = new TcpTransport(_session.ServerAddress, _session.Port, _handler); } public async Task ConnectAsync(bool reconnect = false) @@ -85,7 +88,7 @@ namespace TLSharp.Core var dc = dcOptions.First(d => d.id == dcId); - _transport = new TcpTransport(dc.ip_address, dc.port); + _transport = new TcpTransport(dc.ip_address, dc.port, _handler); _session.ServerAddress = dc.ip_address; _session.Port = dc.port; From f6ef04ed01934fae52f58b694ac51efcb4fb9832 Mon Sep 17 00:00:00 2001 From: Ilya Pirozhenko Date: Sun, 29 Jan 2017 17:06:22 +0300 Subject: [PATCH 09/33] Update README.md --- README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4304ce5..5f4cd51 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,21 @@ #TLSharp + [![Join the chat at https://gitter.im/TLSharp/Lobby](https://badges.gitter.im/TLSharp/Lobby.svg)](https://gitter.im/TLSharp/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Build status](https://ci.appveyor.com/api/projects/status/95rl618ch5c4h2fa?svg=true)](https://ci.appveyor.com/project/sochix/tlsharp) [![NuGet version](https://badge.fury.io/nu/TLSharp.svg)](https://badge.fury.io/nu/TLSharp) + _Unofficial_ Telegram (http://telegram.org) client library implemented in C#. Latest TL scheme supported, thanks to Afshin Arani -**Consider donation to speed up development process.** - -Bitcoin wallet: **3K1ocweFgaHnAibJ3n6hX7RNZWFTFcJjUe** - It's a perfect fit for any developer who would like to send data directly to Telegram users or write own custom Telegram client. :star2: If you :heart: library, please star it! :star2: +If you have difficulties with console or writing code, you can try [Telegram Tools](https://github.com/sochix/telegram-tools). It's a GUI for TLSharp. + + + # Table of contents? - [How do I add this to my project?](#how-do-i-add-this-to-my-project) @@ -187,7 +189,7 @@ Latest scheme in JSON format you can find [here](https://gist.github.com/aarani/ # Contributing -Contributing is highly appreciated! +Contributing is highly appreciated! Donations required ## What things can I Implement (Project Roadmap)? @@ -233,7 +235,7 @@ Without information listen above your issue will be closed. # Donations Thanks for donations! It's highly appreciated. -Bitcoin wallet: **3K1ocweFgaHnAibJ3n6hX7RNZWFTFcJjUe** + List of donators: * [mtbitcoin](https://github.com/mtbitcoin) From 26aa35b88aa3ccfc64a108303fa34e078ed15640 Mon Sep 17 00:00:00 2001 From: Barsham Sotoudeh Date: Sat, 18 Feb 2017 02:16:55 +1100 Subject: [PATCH 10/33] Add missing "offset" parameter in catch block of the GetFile method (#402) This offset optional parameter was added in https://github.com/sochix/TLSharp/commit/a753a1ab136a287559b028ccc7522212882140e0 --- TLSharp.Core/TelegramClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index d4efdb1..a4fa06a 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -320,7 +320,7 @@ namespace TLSharp.Core bytes = exportedAuth.bytes, id = exportedAuth.id }); - result = await GetFile(location, filePartSize); + result = await GetFile(location, filePartSize, offset); _session.AuthKey = authKey; _session.TimeOffset = timeOffset; From 1697db9d7fb5cd6d7c41125bde682b56b997ee1e Mon Sep 17 00:00:00 2001 From: Ilya Pirozhenko Date: Tue, 28 Feb 2017 16:45:20 +0300 Subject: [PATCH 11/33] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5f4cd51..54691f8 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,9 @@ It's a perfect fit for any developer who would like to send data directly to Tel :star2: If you :heart: library, please star it! :star2: -If you have difficulties with console or writing code, you can try [Telegram Tools](https://github.com/sochix/telegram-tools). It's a GUI for TLSharp. +If you have difficulties with library usage, I can support you ( 75$/hour ). Contact me at @sochix. - +If you have difficulties with console or writing code, you can try [Telegram Tools](https://github.com/sochix/telegram-tools). It's a GUI for TLSharp. # Table of contents? From 9f14656465facbc82b703790f84e051944ed67f7 Mon Sep 17 00:00:00 2001 From: salar2k Date: Thu, 2 Mar 2017 09:52:12 +0330 Subject: [PATCH 12/33] Implementing IsConnected --- TLSharp.Core/Network/TcpTransport.cs | 13 +++++++++++-- TLSharp.Core/TelegramClient.cs | 11 +++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/TLSharp.Core/Network/TcpTransport.cs b/TLSharp.Core/Network/TcpTransport.cs index 254153e..31bd6b4 100644 --- a/TLSharp.Core/Network/TcpTransport.cs +++ b/TLSharp.Core/Network/TcpTransport.cs @@ -84,8 +84,17 @@ namespace TLSharp.Core.Network } return new TcpMessage(seq, body); - } - + } + + public bool IsConnected + { + get + { + return this._tcpClient.Connected; + } + } + + public void Dispose() { if (_tcpClient.Connected) diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index a4fa06a..228c9b5 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -377,8 +377,15 @@ namespace TLSharp.Core _session.SessionExpires = int.MaxValue; _session.Save(); - } - + } + + public bool IsConnected() + { + if (this._transport == null) + return false; + return this._transport.IsConnected; + } + public void Dispose() { if (_transport != null) From 25e45b52f6a2af6eb8f39391c95b6d73539a6538 Mon Sep 17 00:00:00 2001 From: Salar Khalilzadeh Date: Mon, 19 Dec 2016 18:30:30 +0330 Subject: [PATCH 13/33] Tests: Use OfType() instead of GetType() == typeof() --- TLSharp.Tests/TLSharpTests.cs | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/TLSharp.Tests/TLSharpTests.cs b/TLSharp.Tests/TLSharpTests.cs index 3b2236a..6166067 100644 --- a/TLSharp.Tests/TLSharpTests.cs +++ b/TLSharp.Tests/TLSharpTests.cs @@ -172,8 +172,7 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .Where(x => x.GetType() == typeof(TLUser)) - .Cast() + .OfType() .FirstOrDefault(x => x.phone == normalizedNumber); if (user == null) @@ -194,8 +193,7 @@ namespace TLSharp.Tests var dialogs = (TLDialogs) await client.GetUserDialogsAsync(); var chat = dialogs.chats.lists - .Where(c => c.GetType() == typeof(TLChannel)) - .Cast() + .OfType() .FirstOrDefault(c => c.title == "TestGroup"); await client.SendMessageAsync(new TLInputPeerChannel() { channel_id = chat.id, access_hash = chat.access_hash.Value }, "TEST MSG"); @@ -210,8 +208,7 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .Where(x => x.GetType() == typeof(TLUser)) - .Cast() + .OfType() .FirstOrDefault(x => x.phone == NumberToSendMessage); var fileResult = (TLInputFile)await client.UploadFile("cat.jpg", new StreamReader("data/cat.jpg")); @@ -227,8 +224,7 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .Where(x => x.GetType() == typeof(TLUser)) - .Cast() + .OfType() .FirstOrDefault(x => x.phone == NumberToSendMessage); var fileResult = (TLInputFileBig)await client.UploadFile("some.zip", new StreamReader("")); @@ -250,21 +246,18 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .Where(x => x.GetType() == typeof(TLUser)) - .Cast() + .OfType() .FirstOrDefault(x => x.phone == NumberToSendMessage); var inputPeer = new TLInputPeerUser() { user_id = user.id }; var res = await client.SendRequestAsync(new TLRequestGetHistory() { peer = inputPeer }); var document = res.messages.lists - .Where(m => m.GetType() == typeof(TLMessage)) - .Cast() - .Where(m => m.media != null && m.media.GetType() == typeof(TLMessageMediaDocument)) + .OfType() + .Where(m => m.media != null) .Select(m => m.media) - .Cast() - .Where(md => md.document.GetType() == typeof(TLDocument)) + .OfType() .Select(md => md.document) - .Cast() + .OfType() .First(); var resFile = await client.GetFile( @@ -288,8 +281,7 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .Where(x => x.GetType() == typeof(TLUser)) - .Cast() + .OfType() .FirstOrDefault(x => x.id == 5880094); var photo = ((TLUserProfilePhoto)user.photo); From a53351d65ed0288a58e99d83219cef6ff347587c Mon Sep 17 00:00:00 2001 From: salar2k Date: Wed, 21 Dec 2016 12:18:40 +0330 Subject: [PATCH 14/33] Revert "Tests: Use OfType() instead of GetType() == typeof()" This reverts commit 31df61a479b6876eeb5bb626c42e0ae6bc63195a. --- TLSharp.Tests/TLSharpTests.cs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/TLSharp.Tests/TLSharpTests.cs b/TLSharp.Tests/TLSharpTests.cs index 6166067..3b2236a 100644 --- a/TLSharp.Tests/TLSharpTests.cs +++ b/TLSharp.Tests/TLSharpTests.cs @@ -172,7 +172,8 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .OfType() + .Where(x => x.GetType() == typeof(TLUser)) + .Cast() .FirstOrDefault(x => x.phone == normalizedNumber); if (user == null) @@ -193,7 +194,8 @@ namespace TLSharp.Tests var dialogs = (TLDialogs) await client.GetUserDialogsAsync(); var chat = dialogs.chats.lists - .OfType() + .Where(c => c.GetType() == typeof(TLChannel)) + .Cast() .FirstOrDefault(c => c.title == "TestGroup"); await client.SendMessageAsync(new TLInputPeerChannel() { channel_id = chat.id, access_hash = chat.access_hash.Value }, "TEST MSG"); @@ -208,7 +210,8 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .OfType() + .Where(x => x.GetType() == typeof(TLUser)) + .Cast() .FirstOrDefault(x => x.phone == NumberToSendMessage); var fileResult = (TLInputFile)await client.UploadFile("cat.jpg", new StreamReader("data/cat.jpg")); @@ -224,7 +227,8 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .OfType() + .Where(x => x.GetType() == typeof(TLUser)) + .Cast() .FirstOrDefault(x => x.phone == NumberToSendMessage); var fileResult = (TLInputFileBig)await client.UploadFile("some.zip", new StreamReader("")); @@ -246,18 +250,21 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .OfType() + .Where(x => x.GetType() == typeof(TLUser)) + .Cast() .FirstOrDefault(x => x.phone == NumberToSendMessage); var inputPeer = new TLInputPeerUser() { user_id = user.id }; var res = await client.SendRequestAsync(new TLRequestGetHistory() { peer = inputPeer }); var document = res.messages.lists - .OfType() - .Where(m => m.media != null) + .Where(m => m.GetType() == typeof(TLMessage)) + .Cast() + .Where(m => m.media != null && m.media.GetType() == typeof(TLMessageMediaDocument)) .Select(m => m.media) - .OfType() + .Cast() + .Where(md => md.document.GetType() == typeof(TLDocument)) .Select(md => md.document) - .OfType() + .Cast() .First(); var resFile = await client.GetFile( @@ -281,7 +288,8 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .OfType() + .Where(x => x.GetType() == typeof(TLUser)) + .Cast() .FirstOrDefault(x => x.id == 5880094); var photo = ((TLUserProfilePhoto)user.photo); From a792e4dc067a43d15edebffb3ae18737173424fa Mon Sep 17 00:00:00 2001 From: salar2k Date: Wed, 21 Dec 2016 12:18:51 +0330 Subject: [PATCH 15/33] Revert "Revert "Tests: Use OfType() instead of GetType() == typeof()"" This reverts commit 14c0c21bcf4a42df517ba641e63d71cdab6ad816. --- TLSharp.Tests/TLSharpTests.cs | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/TLSharp.Tests/TLSharpTests.cs b/TLSharp.Tests/TLSharpTests.cs index 3b2236a..6166067 100644 --- a/TLSharp.Tests/TLSharpTests.cs +++ b/TLSharp.Tests/TLSharpTests.cs @@ -172,8 +172,7 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .Where(x => x.GetType() == typeof(TLUser)) - .Cast() + .OfType() .FirstOrDefault(x => x.phone == normalizedNumber); if (user == null) @@ -194,8 +193,7 @@ namespace TLSharp.Tests var dialogs = (TLDialogs) await client.GetUserDialogsAsync(); var chat = dialogs.chats.lists - .Where(c => c.GetType() == typeof(TLChannel)) - .Cast() + .OfType() .FirstOrDefault(c => c.title == "TestGroup"); await client.SendMessageAsync(new TLInputPeerChannel() { channel_id = chat.id, access_hash = chat.access_hash.Value }, "TEST MSG"); @@ -210,8 +208,7 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .Where(x => x.GetType() == typeof(TLUser)) - .Cast() + .OfType() .FirstOrDefault(x => x.phone == NumberToSendMessage); var fileResult = (TLInputFile)await client.UploadFile("cat.jpg", new StreamReader("data/cat.jpg")); @@ -227,8 +224,7 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .Where(x => x.GetType() == typeof(TLUser)) - .Cast() + .OfType() .FirstOrDefault(x => x.phone == NumberToSendMessage); var fileResult = (TLInputFileBig)await client.UploadFile("some.zip", new StreamReader("")); @@ -250,21 +246,18 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .Where(x => x.GetType() == typeof(TLUser)) - .Cast() + .OfType() .FirstOrDefault(x => x.phone == NumberToSendMessage); var inputPeer = new TLInputPeerUser() { user_id = user.id }; var res = await client.SendRequestAsync(new TLRequestGetHistory() { peer = inputPeer }); var document = res.messages.lists - .Where(m => m.GetType() == typeof(TLMessage)) - .Cast() - .Where(m => m.media != null && m.media.GetType() == typeof(TLMessageMediaDocument)) + .OfType() + .Where(m => m.media != null) .Select(m => m.media) - .Cast() - .Where(md => md.document.GetType() == typeof(TLDocument)) + .OfType() .Select(md => md.document) - .Cast() + .OfType() .First(); var resFile = await client.GetFile( @@ -288,8 +281,7 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .Where(x => x.GetType() == typeof(TLUser)) - .Cast() + .OfType() .FirstOrDefault(x => x.id == 5880094); var photo = ((TLUserProfilePhoto)user.photo); From 703e0a235835fd8a87a9b232650557a836a46ff0 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Wed, 28 Dec 2016 15:37:34 +0100 Subject: [PATCH 16/33] Search user by username with send message test. (#356) * Search user by username with send message test. --- TLSharp.Core/TelegramClient.cs | 17 +++++++++++++ TLSharp.Tests.NUnit/Test.cs | 6 +++++ TLSharp.Tests.VS/TLSharpTestsVs.cs | 6 +++++ TLSharp.Tests/TLSharpTests.cs | 38 ++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+) diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index 7cf7e5d..732adad 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -337,6 +337,23 @@ namespace TLSharp.Core await _sender.SendPingAsync(); } + /// + /// Serch user or chat. API: contacts.search#11f812d8 q:string limit:int = contacts.Found; + /// + /// User or chat name + /// Max result count + /// + public async Task SearchUserAsync(string q, int limit = 10) + { + var r = new TeleSharp.TL.Contacts.TLRequestSearch + { + q = q, + limit = limit + }; + + return await SendRequestAsync(r); + } + private void OnUserAuthenticated(TLUser TLUser) { _session.TLUser = TLUser; diff --git a/TLSharp.Tests.NUnit/Test.cs b/TLSharp.Tests.NUnit/Test.cs index 7c390db..40e54ac 100644 --- a/TLSharp.Tests.NUnit/Test.cs +++ b/TLSharp.Tests.NUnit/Test.cs @@ -75,5 +75,11 @@ namespace TLSharp.Tests { await base.FloodExceptionShouldNotCauseCannotReadPackageLengthError(); } + + [Test] + public override async Task SendMessageByUserNameTest() + { + await base.SendMessageByUserNameTest(); + } } } diff --git a/TLSharp.Tests.VS/TLSharpTestsVs.cs b/TLSharp.Tests.VS/TLSharpTestsVs.cs index fff25b6..8f6c58d 100644 --- a/TLSharp.Tests.VS/TLSharpTestsVs.cs +++ b/TLSharp.Tests.VS/TLSharpTestsVs.cs @@ -73,5 +73,11 @@ namespace TLSharp.Tests { await base.FloodExceptionShouldNotCauseCannotReadPackageLengthError(); } + + [TestMethod] + public override async Task SendMessageByUserNameTest() + { + await base.SendMessageByUserNameTest(); + } } } diff --git a/TLSharp.Tests/TLSharpTests.cs b/TLSharp.Tests/TLSharpTests.cs index 6166067..487b535 100644 --- a/TLSharp.Tests/TLSharpTests.cs +++ b/TLSharp.Tests/TLSharpTests.cs @@ -323,6 +323,7 @@ namespace TLSharp.Tests var result = await client.IsPhoneRegisteredAsync(NumberToAuthenticate); Assert.IsTrue(result); } + public virtual async Task FloodExceptionShouldNotCauseCannotReadPackageLengthError() { for (int i = 0; i < 50; i++) @@ -338,5 +339,42 @@ namespace TLSharp.Tests } } } + + public virtual async Task SendMessageByUserNameTest() + { + UserNameToSendMessage = ConfigurationManager.AppSettings[nameof(UserNameToSendMessage)]; + if (string.IsNullOrWhiteSpace(UserNameToSendMessage)) + throw new Exception($"Please fill the '{nameof(UserNameToSendMessage)}' setting in app.config file first"); + + var client = NewClient(); + + await client.ConnectAsync(); + + var result = await client.SearchUserAsync(UserNameToSendMessage); + + var user = result.users.lists + .Where(x => x.GetType() == typeof(TLUser)) + .OfType() + .FirstOrDefault(x => x.username == UserNameToSendMessage.TrimStart('@')); + + if (user == null) + { + var contacts = await client.GetContactsAsync(); + + user = contacts.users.lists + .Where(x => x.GetType() == typeof(TLUser)) + .OfType() + .FirstOrDefault(x => x.username == UserNameToSendMessage.TrimStart('@')); + } + + if (user == null) + { + throw new System.Exception("Username was not found: " + UserNameToSendMessage); + } + + await client.SendTypingAsync(new TLInputPeerUser() { user_id = user.id }); + Thread.Sleep(3000); + await client.SendMessageAsync(new TLInputPeerUser() { user_id = user.id }, "TEST"); + } } } From fe4486e8eeb1ca83ba9636d6fe6968345c42a4ab Mon Sep 17 00:00:00 2001 From: Starli0n Date: Mon, 9 Jan 2017 18:25:55 +0100 Subject: [PATCH 17/33] Add GetHistoryAsync() to TelegramClient --- README.md | 1 + TLSharp.Core/TelegramClient.cs | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8cdba23..4304ce5 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,7 @@ For your convenience TLSharp have wrappers for several Telegram API methods. You 1. GetFile 1. UploadFile 1. SendPingAsync +1. GetHistoryAsync **What if you can't find needed method at the list?** diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index 732adad..1847f4b 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; -using System.Web; using TeleSharp.TL; using TeleSharp.TL.Account; using TeleSharp.TL.Auth; @@ -15,7 +14,6 @@ using TeleSharp.TL.Upload; using TLSharp.Core.Auth; using TLSharp.Core.MTProto.Crypto; using TLSharp.Core.Network; -using TLSharp.Core.Requests; using TLSharp.Core.Utils; using TLAuthorization = TeleSharp.TL.Auth.TLAuthorization; @@ -335,6 +333,21 @@ namespace TLSharp.Core public async Task SendPingAsync() { await _sender.SendPingAsync(); + } + + public async Task GetHistoryAsync(TLAbsInputPeer peer, int offset, int max_id, int limit) + { + if (!IsUserAuthorized()) + throw new InvalidOperationException("Authorize user first!"); + + var req = new TLRequestGetHistory() + { + peer = peer, + add_offset = offset, + max_id = max_id, + limit = limit + }; + return await SendRequestAsync(req); } /// From 78ae7928e089d0eaed6b64b60b9c42acdb28eb52 Mon Sep 17 00:00:00 2001 From: Starli0n Date: Thu, 19 Jan 2017 19:31:27 +0100 Subject: [PATCH 18/33] Add offset parameter to GetFile() method --- TLSharp.Core/TelegramClient.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index 1847f4b..9674ee8 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -290,7 +290,7 @@ namespace TLSharp.Core }); } - public async Task GetFile(TLAbsInputFileLocation location, int filePartSize) + public async Task GetFile(TLAbsInputFileLocation location, int filePartSize, int offset = 0) { TLFile result = null; try @@ -298,7 +298,8 @@ namespace TLSharp.Core result = await SendRequestAsync(new TLRequestGetFile() { location = location, - limit = filePartSize + limit = filePartSize, + offset = offset }); } catch (FileMigrationException ex) From ac6ec0cb8e3a3777a277d67379e765956031e19d Mon Sep 17 00:00:00 2001 From: Starli0n Date: Fri, 27 Jan 2017 10:58:47 +0100 Subject: [PATCH 19/33] Custom TCP hanlder to allow HTTP proxy auth --- TLSharp.Core/Network/TcpTransport.cs | 18 ++++++++++++------ TLSharp.Core/TelegramClient.cs | 9 ++++++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/TLSharp.Core/Network/TcpTransport.cs b/TLSharp.Core/Network/TcpTransport.cs index 9092828..254153e 100644 --- a/TLSharp.Core/Network/TcpTransport.cs +++ b/TLSharp.Core/Network/TcpTransport.cs @@ -1,22 +1,28 @@ using System; -using System.Linq; using System.Net; using System.Net.Sockets; using System.Threading.Tasks; namespace TLSharp.Core.Network { + public delegate TcpClient TcpClientConnectionHandler(string address, int port); + public class TcpTransport : IDisposable { private readonly TcpClient _tcpClient; private int sendCounter = 0; - public TcpTransport(string address, int port) + public TcpTransport(string address, int port, TcpClientConnectionHandler handler = null) { - _tcpClient = new TcpClient(); + if (handler == null) + { + _tcpClient = new TcpClient(); - var ipAddress = IPAddress.Parse(address); - _tcpClient.Connect(ipAddress, port); + var ipAddress = IPAddress.Parse(address); + _tcpClient.Connect(ipAddress, port); + } + else + _tcpClient = handler(address, port); } public async Task Send(byte[] packet) @@ -84,6 +90,6 @@ namespace TLSharp.Core.Network { if (_tcpClient.Connected) _tcpClient.Close(); - } + } } } diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index 9674ee8..d4efdb1 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -28,8 +28,10 @@ namespace TLSharp.Core private int _apiId = 0; private Session _session; private List dcOptions; + private TcpClientConnectionHandler _handler; - public TelegramClient(int apiId, string apiHash, ISessionStore store = null, string sessionUserId = "session") + public TelegramClient(int apiId, string apiHash, + ISessionStore store = null, string sessionUserId = "session", TcpClientConnectionHandler handler = null) { if (apiId == default(int)) throw new MissingApiConfigurationException("API_ID"); @@ -42,9 +44,10 @@ namespace TLSharp.Core TLContext.Init(); _apiHash = apiHash; _apiId = apiId; + _handler = handler; _session = Session.TryLoadOrCreateNew(store, sessionUserId); - _transport = new TcpTransport(_session.ServerAddress, _session.Port); + _transport = new TcpTransport(_session.ServerAddress, _session.Port, _handler); } public async Task ConnectAsync(bool reconnect = false) @@ -85,7 +88,7 @@ namespace TLSharp.Core var dc = dcOptions.First(d => d.id == dcId); - _transport = new TcpTransport(dc.ip_address, dc.port); + _transport = new TcpTransport(dc.ip_address, dc.port, _handler); _session.ServerAddress = dc.ip_address; _session.Port = dc.port; From f26ab3afa7667fbe7fa22b764f24e5e4d1a3c778 Mon Sep 17 00:00:00 2001 From: Ilya Pirozhenko Date: Sun, 29 Jan 2017 17:06:22 +0300 Subject: [PATCH 20/33] Update README.md --- README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4304ce5..5f4cd51 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,21 @@ #TLSharp + [![Join the chat at https://gitter.im/TLSharp/Lobby](https://badges.gitter.im/TLSharp/Lobby.svg)](https://gitter.im/TLSharp/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Build status](https://ci.appveyor.com/api/projects/status/95rl618ch5c4h2fa?svg=true)](https://ci.appveyor.com/project/sochix/tlsharp) [![NuGet version](https://badge.fury.io/nu/TLSharp.svg)](https://badge.fury.io/nu/TLSharp) + _Unofficial_ Telegram (http://telegram.org) client library implemented in C#. Latest TL scheme supported, thanks to Afshin Arani -**Consider donation to speed up development process.** - -Bitcoin wallet: **3K1ocweFgaHnAibJ3n6hX7RNZWFTFcJjUe** - It's a perfect fit for any developer who would like to send data directly to Telegram users or write own custom Telegram client. :star2: If you :heart: library, please star it! :star2: +If you have difficulties with console or writing code, you can try [Telegram Tools](https://github.com/sochix/telegram-tools). It's a GUI for TLSharp. + + + # Table of contents? - [How do I add this to my project?](#how-do-i-add-this-to-my-project) @@ -187,7 +189,7 @@ Latest scheme in JSON format you can find [here](https://gist.github.com/aarani/ # Contributing -Contributing is highly appreciated! +Contributing is highly appreciated! Donations required ## What things can I Implement (Project Roadmap)? @@ -233,7 +235,7 @@ Without information listen above your issue will be closed. # Donations Thanks for donations! It's highly appreciated. -Bitcoin wallet: **3K1ocweFgaHnAibJ3n6hX7RNZWFTFcJjUe** + List of donators: * [mtbitcoin](https://github.com/mtbitcoin) From 4c1a0b8be00ad56db072be5560214d96ee9f3cb2 Mon Sep 17 00:00:00 2001 From: Barsham Sotoudeh Date: Sat, 18 Feb 2017 02:16:55 +1100 Subject: [PATCH 21/33] Add missing "offset" parameter in catch block of the GetFile method (#402) This offset optional parameter was added in https://github.com/sochix/TLSharp/commit/a753a1ab136a287559b028ccc7522212882140e0 --- TLSharp.Core/TelegramClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index d4efdb1..a4fa06a 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -320,7 +320,7 @@ namespace TLSharp.Core bytes = exportedAuth.bytes, id = exportedAuth.id }); - result = await GetFile(location, filePartSize); + result = await GetFile(location, filePartSize, offset); _session.AuthKey = authKey; _session.TimeOffset = timeOffset; From bea1363641dc6d6fef0be9754d7822daf1cfb64d Mon Sep 17 00:00:00 2001 From: Ilya Pirozhenko Date: Tue, 28 Feb 2017 16:45:20 +0300 Subject: [PATCH 22/33] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5f4cd51..54691f8 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,9 @@ It's a perfect fit for any developer who would like to send data directly to Tel :star2: If you :heart: library, please star it! :star2: -If you have difficulties with console or writing code, you can try [Telegram Tools](https://github.com/sochix/telegram-tools). It's a GUI for TLSharp. +If you have difficulties with library usage, I can support you ( 75$/hour ). Contact me at @sochix. - +If you have difficulties with console or writing code, you can try [Telegram Tools](https://github.com/sochix/telegram-tools). It's a GUI for TLSharp. # Table of contents? From ade02105f6b4bbfaa7e4651c3457b7aed0a29a82 Mon Sep 17 00:00:00 2001 From: salar2k Date: Thu, 2 Mar 2017 09:52:12 +0330 Subject: [PATCH 23/33] Implementing IsConnected --- TLSharp.Core/Network/TcpTransport.cs | 13 +++++++++++-- TLSharp.Core/TelegramClient.cs | 11 +++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/TLSharp.Core/Network/TcpTransport.cs b/TLSharp.Core/Network/TcpTransport.cs index 254153e..31bd6b4 100644 --- a/TLSharp.Core/Network/TcpTransport.cs +++ b/TLSharp.Core/Network/TcpTransport.cs @@ -84,8 +84,17 @@ namespace TLSharp.Core.Network } return new TcpMessage(seq, body); - } - + } + + public bool IsConnected + { + get + { + return this._tcpClient.Connected; + } + } + + public void Dispose() { if (_tcpClient.Connected) diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index a4fa06a..228c9b5 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -377,8 +377,15 @@ namespace TLSharp.Core _session.SessionExpires = int.MaxValue; _session.Save(); - } - + } + + public bool IsConnected() + { + if (this._transport == null) + return false; + return this._transport.IsConnected; + } + public void Dispose() { if (_transport != null) From e99aaa02f52cd2bef48bb1262fbce60516cfac57 Mon Sep 17 00:00:00 2001 From: salar2k Date: Wed, 21 Dec 2016 12:18:40 +0330 Subject: [PATCH 24/33] Revert "Tests: Use OfType() instead of GetType() == typeof()" This reverts commit 31df61a479b6876eeb5bb626c42e0ae6bc63195a. --- TLSharp.Tests/TLSharpTests.cs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/TLSharp.Tests/TLSharpTests.cs b/TLSharp.Tests/TLSharpTests.cs index 487b535..0d8852e 100644 --- a/TLSharp.Tests/TLSharpTests.cs +++ b/TLSharp.Tests/TLSharpTests.cs @@ -172,7 +172,8 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .OfType() + .Where(x => x.GetType() == typeof(TLUser)) + .Cast() .FirstOrDefault(x => x.phone == normalizedNumber); if (user == null) @@ -193,7 +194,8 @@ namespace TLSharp.Tests var dialogs = (TLDialogs) await client.GetUserDialogsAsync(); var chat = dialogs.chats.lists - .OfType() + .Where(c => c.GetType() == typeof(TLChannel)) + .Cast() .FirstOrDefault(c => c.title == "TestGroup"); await client.SendMessageAsync(new TLInputPeerChannel() { channel_id = chat.id, access_hash = chat.access_hash.Value }, "TEST MSG"); @@ -208,7 +210,8 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .OfType() + .Where(x => x.GetType() == typeof(TLUser)) + .Cast() .FirstOrDefault(x => x.phone == NumberToSendMessage); var fileResult = (TLInputFile)await client.UploadFile("cat.jpg", new StreamReader("data/cat.jpg")); @@ -224,7 +227,8 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .OfType() + .Where(x => x.GetType() == typeof(TLUser)) + .Cast() .FirstOrDefault(x => x.phone == NumberToSendMessage); var fileResult = (TLInputFileBig)await client.UploadFile("some.zip", new StreamReader("")); @@ -246,18 +250,21 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .OfType() + .Where(x => x.GetType() == typeof(TLUser)) + .Cast() .FirstOrDefault(x => x.phone == NumberToSendMessage); var inputPeer = new TLInputPeerUser() { user_id = user.id }; var res = await client.SendRequestAsync(new TLRequestGetHistory() { peer = inputPeer }); var document = res.messages.lists - .OfType() - .Where(m => m.media != null) + .Where(m => m.GetType() == typeof(TLMessage)) + .Cast() + .Where(m => m.media != null && m.media.GetType() == typeof(TLMessageMediaDocument)) .Select(m => m.media) - .OfType() + .Cast() + .Where(md => md.document.GetType() == typeof(TLDocument)) .Select(md => md.document) - .OfType() + .Cast() .First(); var resFile = await client.GetFile( @@ -281,7 +288,8 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .OfType() + .Where(x => x.GetType() == typeof(TLUser)) + .Cast() .FirstOrDefault(x => x.id == 5880094); var photo = ((TLUserProfilePhoto)user.photo); From 91b423c921239a32ca2faff7acdbf6d3f708f675 Mon Sep 17 00:00:00 2001 From: salar2k Date: Wed, 21 Dec 2016 12:18:51 +0330 Subject: [PATCH 25/33] Revert "Revert "Tests: Use OfType() instead of GetType() == typeof()"" This reverts commit 14c0c21bcf4a42df517ba641e63d71cdab6ad816. --- TLSharp.Tests/TLSharpTests.cs | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/TLSharp.Tests/TLSharpTests.cs b/TLSharp.Tests/TLSharpTests.cs index 0d8852e..487b535 100644 --- a/TLSharp.Tests/TLSharpTests.cs +++ b/TLSharp.Tests/TLSharpTests.cs @@ -172,8 +172,7 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .Where(x => x.GetType() == typeof(TLUser)) - .Cast() + .OfType() .FirstOrDefault(x => x.phone == normalizedNumber); if (user == null) @@ -194,8 +193,7 @@ namespace TLSharp.Tests var dialogs = (TLDialogs) await client.GetUserDialogsAsync(); var chat = dialogs.chats.lists - .Where(c => c.GetType() == typeof(TLChannel)) - .Cast() + .OfType() .FirstOrDefault(c => c.title == "TestGroup"); await client.SendMessageAsync(new TLInputPeerChannel() { channel_id = chat.id, access_hash = chat.access_hash.Value }, "TEST MSG"); @@ -210,8 +208,7 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .Where(x => x.GetType() == typeof(TLUser)) - .Cast() + .OfType() .FirstOrDefault(x => x.phone == NumberToSendMessage); var fileResult = (TLInputFile)await client.UploadFile("cat.jpg", new StreamReader("data/cat.jpg")); @@ -227,8 +224,7 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .Where(x => x.GetType() == typeof(TLUser)) - .Cast() + .OfType() .FirstOrDefault(x => x.phone == NumberToSendMessage); var fileResult = (TLInputFileBig)await client.UploadFile("some.zip", new StreamReader("")); @@ -250,21 +246,18 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .Where(x => x.GetType() == typeof(TLUser)) - .Cast() + .OfType() .FirstOrDefault(x => x.phone == NumberToSendMessage); var inputPeer = new TLInputPeerUser() { user_id = user.id }; var res = await client.SendRequestAsync(new TLRequestGetHistory() { peer = inputPeer }); var document = res.messages.lists - .Where(m => m.GetType() == typeof(TLMessage)) - .Cast() - .Where(m => m.media != null && m.media.GetType() == typeof(TLMessageMediaDocument)) + .OfType() + .Where(m => m.media != null) .Select(m => m.media) - .Cast() - .Where(md => md.document.GetType() == typeof(TLDocument)) + .OfType() .Select(md => md.document) - .Cast() + .OfType() .First(); var resFile = await client.GetFile( @@ -288,8 +281,7 @@ namespace TLSharp.Tests var result = await client.GetContactsAsync(); var user = result.users.lists - .Where(x => x.GetType() == typeof(TLUser)) - .Cast() + .OfType() .FirstOrDefault(x => x.id == 5880094); var photo = ((TLUserProfilePhoto)user.photo); From 653b01ecc01c5e7c2be649fa12e4a9483a656464 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Wed, 28 Dec 2016 15:37:34 +0100 Subject: [PATCH 26/33] Search user by username with send message test. (#356) * Search user by username with send message test. --- TLSharp.Core/TelegramClient.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index 228c9b5..47fbf8d 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -371,6 +371,23 @@ namespace TLSharp.Core return await SendRequestAsync(r); } + /// + /// Serch user or chat. API: contacts.search#11f812d8 q:string limit:int = contacts.Found; + /// + /// User or chat name + /// Max result count + /// + public async Task SearchUserAsync(string q, int limit = 10) + { + var r = new TeleSharp.TL.Contacts.TLRequestSearch + { + q = q, + limit = limit + }; + + return await SendRequestAsync(r); + } + private void OnUserAuthenticated(TLUser TLUser) { _session.TLUser = TLUser; From 756fed882735b806a0d8c6c1681a467361cdc214 Mon Sep 17 00:00:00 2001 From: Starli0n Date: Mon, 9 Jan 2017 18:25:55 +0100 Subject: [PATCH 27/33] Add GetHistoryAsync() to TelegramClient --- TLSharp.Core/TelegramClient.cs | 44 +++++++--------------------------- 1 file changed, 8 insertions(+), 36 deletions(-) diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index 47fbf8d..1847f4b 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -28,10 +28,8 @@ namespace TLSharp.Core private int _apiId = 0; private Session _session; private List dcOptions; - private TcpClientConnectionHandler _handler; - public TelegramClient(int apiId, string apiHash, - ISessionStore store = null, string sessionUserId = "session", TcpClientConnectionHandler handler = null) + public TelegramClient(int apiId, string apiHash, ISessionStore store = null, string sessionUserId = "session") { if (apiId == default(int)) throw new MissingApiConfigurationException("API_ID"); @@ -44,10 +42,9 @@ namespace TLSharp.Core TLContext.Init(); _apiHash = apiHash; _apiId = apiId; - _handler = handler; _session = Session.TryLoadOrCreateNew(store, sessionUserId); - _transport = new TcpTransport(_session.ServerAddress, _session.Port, _handler); + _transport = new TcpTransport(_session.ServerAddress, _session.Port); } public async Task ConnectAsync(bool reconnect = false) @@ -88,7 +85,7 @@ namespace TLSharp.Core var dc = dcOptions.First(d => d.id == dcId); - _transport = new TcpTransport(dc.ip_address, dc.port, _handler); + _transport = new TcpTransport(dc.ip_address, dc.port); _session.ServerAddress = dc.ip_address; _session.Port = dc.port; @@ -293,7 +290,7 @@ namespace TLSharp.Core }); } - public async Task GetFile(TLAbsInputFileLocation location, int filePartSize, int offset = 0) + public async Task GetFile(TLAbsInputFileLocation location, int filePartSize) { TLFile result = null; try @@ -301,8 +298,7 @@ namespace TLSharp.Core result = await SendRequestAsync(new TLRequestGetFile() { location = location, - limit = filePartSize, - offset = offset + limit = filePartSize }); } catch (FileMigrationException ex) @@ -320,7 +316,7 @@ namespace TLSharp.Core bytes = exportedAuth.bytes, id = exportedAuth.id }); - result = await GetFile(location, filePartSize, offset); + result = await GetFile(location, filePartSize); _session.AuthKey = authKey; _session.TimeOffset = timeOffset; @@ -371,38 +367,14 @@ namespace TLSharp.Core return await SendRequestAsync(r); } - /// - /// Serch user or chat. API: contacts.search#11f812d8 q:string limit:int = contacts.Found; - /// - /// User or chat name - /// Max result count - /// - public async Task SearchUserAsync(string q, int limit = 10) - { - var r = new TeleSharp.TL.Contacts.TLRequestSearch - { - q = q, - limit = limit - }; - - return await SendRequestAsync(r); - } - private void OnUserAuthenticated(TLUser TLUser) { _session.TLUser = TLUser; _session.SessionExpires = int.MaxValue; _session.Save(); - } - - public bool IsConnected() - { - if (this._transport == null) - return false; - return this._transport.IsConnected; - } - + } + public void Dispose() { if (_transport != null) From ed24638315fee1ca19688112626a736a63648156 Mon Sep 17 00:00:00 2001 From: Starli0n Date: Thu, 19 Jan 2017 19:31:27 +0100 Subject: [PATCH 28/33] Add offset parameter to GetFile() method --- TLSharp.Core/TelegramClient.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index 1847f4b..9674ee8 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -290,7 +290,7 @@ namespace TLSharp.Core }); } - public async Task GetFile(TLAbsInputFileLocation location, int filePartSize) + public async Task GetFile(TLAbsInputFileLocation location, int filePartSize, int offset = 0) { TLFile result = null; try @@ -298,7 +298,8 @@ namespace TLSharp.Core result = await SendRequestAsync(new TLRequestGetFile() { location = location, - limit = filePartSize + limit = filePartSize, + offset = offset }); } catch (FileMigrationException ex) From 0c6838740c852f6e5d1a437b1dba798337dc1ee3 Mon Sep 17 00:00:00 2001 From: Starli0n Date: Fri, 27 Jan 2017 10:58:47 +0100 Subject: [PATCH 29/33] Custom TCP hanlder to allow HTTP proxy auth --- TLSharp.Core/TelegramClient.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index 9674ee8..d4efdb1 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -28,8 +28,10 @@ namespace TLSharp.Core private int _apiId = 0; private Session _session; private List dcOptions; + private TcpClientConnectionHandler _handler; - public TelegramClient(int apiId, string apiHash, ISessionStore store = null, string sessionUserId = "session") + public TelegramClient(int apiId, string apiHash, + ISessionStore store = null, string sessionUserId = "session", TcpClientConnectionHandler handler = null) { if (apiId == default(int)) throw new MissingApiConfigurationException("API_ID"); @@ -42,9 +44,10 @@ namespace TLSharp.Core TLContext.Init(); _apiHash = apiHash; _apiId = apiId; + _handler = handler; _session = Session.TryLoadOrCreateNew(store, sessionUserId); - _transport = new TcpTransport(_session.ServerAddress, _session.Port); + _transport = new TcpTransport(_session.ServerAddress, _session.Port, _handler); } public async Task ConnectAsync(bool reconnect = false) @@ -85,7 +88,7 @@ namespace TLSharp.Core var dc = dcOptions.First(d => d.id == dcId); - _transport = new TcpTransport(dc.ip_address, dc.port); + _transport = new TcpTransport(dc.ip_address, dc.port, _handler); _session.ServerAddress = dc.ip_address; _session.Port = dc.port; From 04ad7a67e9c6b52c4115ab7ba08b411a87377cdd Mon Sep 17 00:00:00 2001 From: Ilya Pirozhenko Date: Sun, 29 Jan 2017 17:06:22 +0300 Subject: [PATCH 30/33] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 54691f8..5f4cd51 100644 --- a/README.md +++ b/README.md @@ -12,10 +12,10 @@ It's a perfect fit for any developer who would like to send data directly to Tel :star2: If you :heart: library, please star it! :star2: -If you have difficulties with library usage, I can support you ( 75$/hour ). Contact me at @sochix. - If you have difficulties with console or writing code, you can try [Telegram Tools](https://github.com/sochix/telegram-tools). It's a GUI for TLSharp. + + # Table of contents? - [How do I add this to my project?](#how-do-i-add-this-to-my-project) From dba1f0fd2adb2745d1b933877f471bbdd3fbaaf9 Mon Sep 17 00:00:00 2001 From: Barsham Sotoudeh Date: Sat, 18 Feb 2017 02:16:55 +1100 Subject: [PATCH 31/33] Add missing "offset" parameter in catch block of the GetFile method (#402) This offset optional parameter was added in https://github.com/sochix/TLSharp/commit/a753a1ab136a287559b028ccc7522212882140e0 --- TLSharp.Core/TelegramClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index d4efdb1..a4fa06a 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -320,7 +320,7 @@ namespace TLSharp.Core bytes = exportedAuth.bytes, id = exportedAuth.id }); - result = await GetFile(location, filePartSize); + result = await GetFile(location, filePartSize, offset); _session.AuthKey = authKey; _session.TimeOffset = timeOffset; From 8f02d52e65320d240079a9d42f89f79b9b883bef Mon Sep 17 00:00:00 2001 From: Ilya Pirozhenko Date: Tue, 28 Feb 2017 16:45:20 +0300 Subject: [PATCH 32/33] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5f4cd51..54691f8 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,9 @@ It's a perfect fit for any developer who would like to send data directly to Tel :star2: If you :heart: library, please star it! :star2: -If you have difficulties with console or writing code, you can try [Telegram Tools](https://github.com/sochix/telegram-tools). It's a GUI for TLSharp. +If you have difficulties with library usage, I can support you ( 75$/hour ). Contact me at @sochix. - +If you have difficulties with console or writing code, you can try [Telegram Tools](https://github.com/sochix/telegram-tools). It's a GUI for TLSharp. # Table of contents? From f11475badd4ecf53a67660045fccaa1698c08222 Mon Sep 17 00:00:00 2001 From: salar2k Date: Thu, 2 Mar 2017 09:52:12 +0330 Subject: [PATCH 33/33] Implementing IsConnected --- TLSharp.Core/TelegramClient.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index a4fa06a..228c9b5 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -377,8 +377,15 @@ namespace TLSharp.Core _session.SessionExpires = int.MaxValue; _session.Save(); - } - + } + + public bool IsConnected() + { + if (this._transport == null) + return false; + return this._transport.IsConnected; + } + public void Dispose() { if (_transport != null)