From 103e41fb2bd9fc6db6fce3239f93fea193f4ce29 Mon Sep 17 00:00:00 2001 From: Ilya Pirozhneko Date: Sun, 7 Feb 2016 13:28:41 +0300 Subject: [PATCH] Updates --- README.md | 72 +++++++++++++++++-- ...dChatUserRequest => AddChatUserRequest.cs} | 0 ...CreateChatRequest => CreateChatRequest.cs} | 0 ...atUserRequest => DeleteChatUserRequest.cs} | 0 TLSharp.Core/Requests/ImportContactRequest | 66 ----------------- TLSharp.Core/TLSharp.Core.csproj | 3 + TLSharp.Core/TelegramClient.cs | 18 ++++- TLSharp.Tests/TLSharpTests.cs | 12 ++-- 8 files changed, 91 insertions(+), 80 deletions(-) rename TLSharp.Core/Requests/{AddChatUserRequest => AddChatUserRequest.cs} (100%) rename TLSharp.Core/Requests/{CreateChatRequest => CreateChatRequest.cs} (100%) rename TLSharp.Core/Requests/{DeleteChatUserRequest => DeleteChatUserRequest.cs} (100%) delete mode 100644 TLSharp.Core/Requests/ImportContactRequest diff --git a/README.md b/README.md index 2286342..418f129 100644 --- a/README.md +++ b/README.md @@ -110,12 +110,12 @@ Get user id by phone number. _Example_: ``` -var res = await client.ImportContact(phoneNumber); +var res = await client.ImportContactByPhoneNumber("791812312323"); ``` * phoneNumber - **string**, phone number in international format (eg. 791812312323) -**Returns**: **int?**, User Id with phoneNumber +**Returns**: **int?**, User Id or null if no such user. ####Get Contact By Username Get user id by userName. @@ -128,7 +128,7 @@ var res = await client.ImportByUserName(userName); * userName - **string**, user name (eg. telegram_bot) -**Returns**: **int?**, User Id with phoneNumber +**Returns**: **int?**, User Id or null if no such user. ####Send Message To Contact Send text message to specified user @@ -179,10 +179,59 @@ var hist = await client.GetMessagesHistoryForContact(userId, offset, limit); Contributing is highly appreciated! ###How to add new functions -It's really simple to add new functionality to TLSharp. -###What things can I Implement? -TODO: +Adding new functions is easy. + +* Just create a new Request class in Requests folder. +* Derive it from MTProtoRequest. + +Requests specification you can find in [Telegram API](link) reference. + +_Example_: + +``` +public class ExampleRequest : MTProtoRequest +{ + private int _someParameter; + + // pass needed parameters through constructor, and save it to private vars + public InitConnectionRequest(int someParameter) + { + _someParameter = someParameter; + } + + // send all needed params to Telegram + public override void OnSend(BinaryWriter writer) + { + writer.Write(_someParameter); + } + + // read a received data from Telegram + public override void OnResponse(BinaryReader reader) + { + _someParameter = reader.ReadUInt32(); + } + + public override void OnException(Exception exception) + { + throw new NotImplementedException(); + } + + public override bool Responded { get; } + + public override bool Confirmed => true; +} +``` + +More advanced examples you can find in [Requests folder](link). + +###What things can I Implement (Project Roadmap)? + +* Factor out current TL language implementation, and use [this one](link) +* Add possibility to get current user Chats and Users +* Fix Chat requests (Create, AddUser) +* Add Updates handling +* Add possibility to work with Channels # FAQ @@ -201,6 +250,17 @@ It's Telegram restrictions. See [this](https://core.telegram.org/api/errors#420- Now TLSharp is basic realization of Telegram protocol, you can be a contributor or a sponsor to speed-up developemnt of any feature. +#### Nothing helps +Create an issue in project bug tracker. + +**Attach this information**: + +* Full problem description and exception message +* Stack-trace +* Your code that runs in to this exception + +Without information listen above your issue will be closed. + # License **Please, provide link to an author when you using library** diff --git a/TLSharp.Core/Requests/AddChatUserRequest b/TLSharp.Core/Requests/AddChatUserRequest.cs similarity index 100% rename from TLSharp.Core/Requests/AddChatUserRequest rename to TLSharp.Core/Requests/AddChatUserRequest.cs diff --git a/TLSharp.Core/Requests/CreateChatRequest b/TLSharp.Core/Requests/CreateChatRequest.cs similarity index 100% rename from TLSharp.Core/Requests/CreateChatRequest rename to TLSharp.Core/Requests/CreateChatRequest.cs diff --git a/TLSharp.Core/Requests/DeleteChatUserRequest b/TLSharp.Core/Requests/DeleteChatUserRequest.cs similarity index 100% rename from TLSharp.Core/Requests/DeleteChatUserRequest rename to TLSharp.Core/Requests/DeleteChatUserRequest.cs diff --git a/TLSharp.Core/Requests/ImportContactRequest b/TLSharp.Core/Requests/ImportContactRequest deleted file mode 100644 index 7fe658a..0000000 --- a/TLSharp.Core/Requests/ImportContactRequest +++ /dev/null @@ -1,66 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using TLSharp.Core.MTProto; - -namespace TLSharp.Core.Requests -{ - public class ImportContactRequest : MTProtoRequest - { - private List Contact { get; set; } - private bool Replace { get; set; } - - public List imported; - public List users; - - public ImportContactRequest(List contact, bool shouldReplace = true) - { - Contact = contact; - Replace = shouldReplace; - } - - public override void OnSend(BinaryWriter writer) - { - writer.Write(0xda30b32d); - writer.Write(0x1cb5c415); - writer.Write(Contact.Count); - foreach (var item in Contact) - { - item.Write(writer); - } - - writer.Write(Replace ? 0x997275b5 : 0xbc799737); - } - - public override void OnResponse(BinaryReader reader) - { - var code = reader.ReadUInt32(); - var result = reader.ReadInt32(); // vector code - int imported_len = reader.ReadInt32(); - this.imported = new List(imported_len); - for (int imported_index = 0; imported_index < imported_len; imported_index++) - { - ImportedContact imported_element; - imported_element = TL.Parse(reader); - this.imported.Add(imported_element); - } - reader.ReadInt32(); // vector code - int users_len = reader.ReadInt32(); - this.users = new List(users_len); - for (int users_index = 0; users_index < users_len; users_index++) - { - User users_element; - users_element = TL.Parse(reader); - this.users.Add(users_element); - } - } - - public override void OnException(Exception exception) - { - throw new NotImplementedException(); - } - public override bool Confirmed { get { return true; } } - private readonly bool responded; - public override bool Responded { get { return responded; } } - } -} diff --git a/TLSharp.Core/TLSharp.Core.csproj b/TLSharp.Core/TLSharp.Core.csproj index 2541b51..6b3c220 100644 --- a/TLSharp.Core/TLSharp.Core.csproj +++ b/TLSharp.Core/TLSharp.Core.csproj @@ -85,6 +85,9 @@ + + +