From 58143ad978d6a46326ed2e8de0fade040a04e643 Mon Sep 17 00:00:00 2001 From: Afshin Arani Date: Sat, 1 Oct 2016 15:38:21 +0330 Subject: [PATCH 1/6] Update README.md --- README.md | 227 ------------------------------------------------------ 1 file changed, 227 deletions(-) diff --git a/README.md b/README.md index 3b431d1..8ffd069 100644 --- a/README.md +++ b/README.md @@ -74,18 +74,6 @@ Currently supported methods: - [IsPhoneRegistered - Check if phone is registered in Telegram](#isphoneregistered) - [Authenticate user](#authenticate-user) - [SignUp user](#signup-user) - - [Get Contact by Phone number](#get-contact-by-phone-number) - - [Get Contact by Username](#get-contact-by-username) - - [Send Message to Contact](#send-message-to-contact) - - [Send Media to Contact](#send-media-to-contact) - - [Get Messages History for Contact](#get-messages-history-for-contact) - - [Get UserFull](#get-userfull) - - [Create Chat](#create-chat) - - [Add Chat user](#add-chat-user) - - [Delete Chat user](#delete-chat-user) - - [Leave Chat](#leave-chat) - - [Get Updates State](#get-updates-state) - - [Get Updates Difference](#get-updates-difference) ####IsPhoneRegistered Check if phone number registered to Telegram. @@ -135,228 +123,13 @@ _Example_: **Returns:** **User**, authenticated User. -####Get Contact By Phone number -Get user id by phone number. - -_Example_: - -``` -var res = await client.ImportContactByPhoneNumber("791812312323"); -``` - -* phoneNumber - **string**, phone number in international format (eg. 791812312323) - -**Returns**: **int?**, User Id or null if no such user. - -####Get Contact By Username -Get user id by userName. - -_Example_: - -``` -var res = await client.ImportByUserName(userName); -``` - -* userName - **string**, user name (eg. telegram_bot) - -**Returns**: **int?**, User Id or null if no such user. - -####Send Message To Contact -Send text message to specified user - -_Example_: - -``` -await client.SendMessage(userId, message); -``` -* userId - **int**, user id -* message - **string**, message - -####Send Media To Contact -Send media file to specified contact. - -_Example_: - -``` -var mediaFile = await client.UploadFile(file_name, file); - -var res = await client.SendMediaMessage(userId, mediaFile); -``` - -* file_name - **string**, file name with extension (eg. "file.jpg") -* file - **byte[]**, file content -* userId - **int**, user id -* mediaFile - **InputFile**, reference to uploaded file - -**Returns**: **bool**, file sent or not - -####Get Messages History for Contact -Returns messages history for specified userId. - -_Example_: - -``` -var hist = await client.GetMessagesHistoryForContact(userId, offset, limit); -``` - -* userId - **int**, user id -* offset - **int**, from what index start load history -* limit - **int**, how much items return - -**Returns**: **List\**, message history - -####Get UserFull -Returns user's full information for specified userId. - -_Example_: - -``` -var userFull = await client.GetUserFull(userId); -``` - -* userId - **int**, user id - -**Returns**: **UserFull**, User's information - -####Create Chat -Creates a new chat. - -_Example_: - -``` -var statedMessage = await client.CreateChat(title, new List { userId1, userId2 }); -``` - -* title - **string**, chat name -* userIdsToInvite - **List**, list of userIds to invite to chat. Current user will be automatically added to this chat. - -**Returns**: **Messages_statedMessageConstructor**, Message that contains information about created chat. - -####Add Chat user -Adds a user to a chat and sends a service message on it. - -_Example_: - -``` -var statedMessage = await client.AddChatUser(chatId, userId); -``` - -* chatId - **int**, Chat ID -* userId - **int**, User ID to be added - -**Returns**: **Messages_statedMessageConstructor**, Message that contains information about modified chat. - -####Delete Chat user -Deletes a user from a chat and sends a service message on it. - -_Example_: - -``` -var statedMessage = await client.DeleteChatUser(chatId, userId); -``` - -* chatId - **int**, Chat ID -* userId - **int**, User ID to be deleted - -**Returns**: **Messages_statedMessageConstructor**, Message that contains information about modified chat. - -####Leave Chat -Leaves the chat by deleting currently authenticated user from it. - -_Example_: - -``` -var statedMessage = await client.LeaveChat(chatId); -``` - -* chatId - **int**, Chat ID - -**Returns**: **Messages_statedMessageConstructor**, Message that contains information about modified chat. - -####Get Updates State -Returns a current state of updates. - -_Example_: - -``` -var userFull = await client.GetUpdatesState(); -``` - -**Returns**: **UpdatesState**, Object contains info on state for further updates. - -####Get Updates Difference -Returns diffetence between the current state of updates and transmitted. - -_Example_: - -``` -var userFull = await client.GetUpdatesDifference(currentState.pts, currentState.date, currentState.qts); -``` - -* lastPts - **int**, The most relevant value of parameter pts of (updates.state) -* lastDate - **int**, The most relevant value of parameter date of (updates.state) -* lastQts - **int**, The most relevant value of parameter qts of (updates.state) - -**Returns**: **UpdatesDifference**, Occurred changes. - ## Contributing Contributing is highly appreciated! -###How to add new functions - -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](https://core.telegram.org/#api-methods) 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](https://github.com/sochix/TLSharp/tree/master/TLSharp.Core/Requests). - ###What things can I Implement (Project Roadmap)? -* Factor out current TL language implementation, and use [this one](https://github.com/everbytes/SharpTL) -* Add possibility to get current user Chats and Users -* Fix Chat requests (Create, AddUser) * Add Updates handling -* Add possibility to work with Channels # FAQ From 8093c8a1f15ed8f78842f5f7ff5f2badd1a82566 Mon Sep 17 00:00:00 2001 From: Afshin Arani Date: Sun, 2 Oct 2016 17:58:39 +0330 Subject: [PATCH 2/6] Update README.md --- README.md | 79 +------------------------------------------------------ 1 file changed, 1 insertion(+), 78 deletions(-) diff --git a/README.md b/README.md index 8ffd069..2e67b7e 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,7 @@ It's a perfect fit for any developer who would like to send data directly to Tel :exclamation: **Please, don't use it for SPAM!** -[How-To: Send messages to Telegram from C#](http://www.sochix.ru/how-to-send-messages-to-telegram-from-c/) - -:ru: Russian description you can find [here](https://habrahabr.ru/post/277079/) +# The Docuemention Moved to [TLSharp.aarani.ir](tlsharp.aarani.ir) #Table of contents? @@ -20,7 +18,6 @@ It's a perfect fit for any developer who would like to send data directly to Tel - [Dependencies](#dependencies) - [Starter Guide](#starter-guide) - [Quick configuration](#quick-configuration) - - [Using TLSharp](#using-tlsharp) - [Contributing](#contributing) - [FAQ](#faq) - [Donations](#donations) @@ -49,80 +46,6 @@ Telegram API isn't that easy to start. You need to do some configuration first. 1. Create a [developer account](https://my.telegram.org/) in Telegram. 1. Goto [API development tools](https://my.telegram.org/apps) and copy **API_ID** and **API_HASH** from your account. You'll need it later. -## Using TLSharp - -###Initializing client - -To initialize client you need to create a store in which TLSharp will save Session info. - -``` -var store = new FileSessionStore(); -``` - -Next, create client instance and connect to Telegram server. You need your **API_ID** and **API_HASH** for this step. - -``` -var client = new TelegramClient(store, "session", API_ID, "API_HASH"); -await client.Connect(); -``` -Now, you can call methods. - -All methods except [IsPhoneRegistered](#IsPhoneRegistered) requires to authenticated user. Example usage of all methods you can find in [Tests]. - -###Supported methods -Currently supported methods: - - [IsPhoneRegistered - Check if phone is registered in Telegram](#isphoneregistered) - - [Authenticate user](#authenticate-user) - - [SignUp user](#signup-user) - -####IsPhoneRegistered -Check if phone number registered to Telegram. - -_Example_: - -``` -var result = await client.IsPhoneRegistered(phoneNumber) -``` - -* phoneNumber - **string**, phone number in international format (eg. 791812312323) - -**Returns:** **bool**, is phone registerd in Telegram or not. - - -####Authenticate user -Authenticate user by phone number and secret code. - -_Example_: - -``` - var hash = await client.SendCodeRequest(phoneNumber); - - var code = "1234"; //code that you receive from Telegram - - var user = await client.MakeAuth(phoneNumber, hash, code); -``` -* phoneNumber - **string**, phone number in international format (eg. 791812312323) - -**Returns:** **User**, authenticated User. - -####SignUp user -Register new user by phone number, secret code and first/last name. - -_Example_: - -``` - var hash = await client.SendCodeRequest(phoneNumber); - - var code = "1234"; //code that you receive from Telegram - - var user = await client.SignUp(phoneNumber, hash, code, "TLSharp", "User"); -``` -* phoneNumber - **string**, phone number in international format (eg. 791812312323) that is not yet registered in Telegram. -* firstName - **string**, new user first name -* lastName - **string**, new user last name - -**Returns:** **User**, authenticated User. - ## Contributing Contributing is highly appreciated! From 82d65f5a34a327ab91e723aedaec3e585c9af2c3 Mon Sep 17 00:00:00 2001 From: Afshin Arani Date: Sun, 2 Oct 2016 18:00:41 +0330 Subject: [PATCH 3/6] Add My Copyright --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2e67b7e..611e882 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ List of donators: The MIT License -Copyright (c) 2015 Ilya Pirozhenko http://www.sochix.ru/ +Copyright (c) 2015 Ilya Pirozhenko http://www.sochix.ru/ & Afshin Arani http://aarani.ir Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: From 85a29f505a9b0dbce038941d7758a304762f1b87 Mon Sep 17 00:00:00 2001 From: Afshin Arani Date: Sun, 2 Oct 2016 18:01:37 +0330 Subject: [PATCH 4/6] Update Link --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 611e882..67190dc 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ It's a perfect fit for any developer who would like to send data directly to Tel :exclamation: **Please, don't use it for SPAM!** -# The Docuemention Moved to [TLSharp.aarani.ir](tlsharp.aarani.ir) +# The Docuemention Moved to [TLSharp.aarani.ir](http://tlsharp.aarani.ir) #Table of contents? @@ -60,7 +60,7 @@ Contributing is highly appreciated! TLSharp library should automatically handle this errors. If you see such errors, pls create a new issue. -#### I get an exception: System.IO.EndOfStreamException: Unable to read beyond the end of the stream. All test methos except that AuthenticationWorks and TestConnection return same error. I did every thing including setting api id and hash, and setting server address. +#### I get an exception: System.IO.EndOfStreamException: Unable to read beyond the end of the stream. All test methos except that AuthenticationWorks and TestConnection return same error. I did every thing including setting api id and hash, and setting server address.- You should create a Telegram session. See [configuration guide](#sending-messages-set-up) From cd48986200ae696d0409b9c5d4aacffb74e9e6a7 Mon Sep 17 00:00:00 2001 From: The Gitter Badger Date: Sun, 2 Oct 2016 11:13:02 -0500 Subject: [PATCH 5/6] Add Gitter badge --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 67190dc..95b44f9 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ #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) Telegram (http://telegram.org) client library implemented in C#. Only basic functionality is currently implemented. **Consider donation to speed up development process.** Bitcoin wallet: **3K1ocweFgaHnAibJ3n6hX7RNZWFTFcJjUe** From e626e76a66cfc698218f812ab1a94e0ec2b54eb2 Mon Sep 17 00:00:00 2001 From: Afshin Arani Date: Thu, 6 Oct 2016 14:21:21 +0330 Subject: [PATCH 6/6] Temporary Update for TLVector Deserialization Bug --- TeleSharp.TL/TLVector.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/TeleSharp.TL/TLVector.cs b/TeleSharp.TL/TLVector.cs index 9c67768..4c2b539 100644 --- a/TeleSharp.TL/TLVector.cs +++ b/TeleSharp.TL/TLVector.cs @@ -43,9 +43,10 @@ namespace TeleSharp.TL else if (typeof(T).BaseType == typeof(TLObject)) { int constructor = br.ReadInt32(); - object obj = Activator.CreateInstance(typeof(T)); - typeof(T).GetMethod("DeserializeBody").Invoke(obj, new object[] { br }); - lists.Add((T)Convert.ChangeType(obj,typeof(T))); + Type type = TLContext.getType(constructor); + object obj = Activator.CreateInstance(type); + type.GetMethod("DeserializeBody").Invoke(obj, new object[] { br }); + lists.Add((T)Convert.ChangeType(obj, type)); } } }