sochix / tlsharp Goto Github PK
View Code? Open in Web Editor NEWTelegram client library implemented in C#
Telegram client library implemented in C#
When I run the program, I have received a code from telegram, but the program does not reach the breakpoint and performances continues! Please help
Hi in app.config file we have:
What is the meaning of each?
Thank you!
Can you put real example. I want to send message to special number which I do not know the telegram's ID! I write this code but it does not work:
static void Main(string[] args)
{
try
{
Console.WriteLine("Start:");
Task.Run(() => Send("Hi"));
Task.Run(() => SendMessage());
Console.WriteLine("End");
Console.ReadLine();
}
catch (Exception ex)
{
}
}
public static async Task AuthUser()
{
var store = new FileSessionStore();
var client = new TLSharp.Core.TelegramClient(store, "session");
await client.Connect();
var hash = await client.SendCodeRequest("+phone");
var code = "59149"; // you can change code in debugger
var user = await client.MakeAuth("+phone", hash, code);
Assert.IsNotNull(user);
}
public static async Task CheckPhones()
{
var store = new FileSessionStore();
var client = new TLSharp.Core.TelegramClient(store, "session");
await client.Connect();
var phoneList = new string[]
{
"+phone",
"+phone"
};
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 static async Task ImportContact()
{
// User should be already authenticated!
var store = new FileSessionStore();
var client = new TLSharp.Core.TelegramClient(store, "session");
await client.Connect();
Assert.IsTrue(client.IsUserAuthorized());
var res = await client.ImportContact("@IrisTed");
Assert.IsNotNull(res);
}
public static async Task SendMessage()
{
// User should be already authenticated!
var store = new FileSessionStore();
var client = new TLSharp.Core.TelegramClient(store, "session");
await client.Connect();
Assert.IsTrue(client.IsUserAuthorized());
var res = await client.ImportContact("+phone");
Assert.IsNotNull(res);
await client.SendMessage(res.Value, "Test message from TelegramClient");
}
public static async Task TestConnection()
{
var store = new FakeSessionStore();
var client = new TLSharp.Core.TelegramClient(store, "");
Assert.IsTrue(await client.Connect());
}
public static async Task AuthenticationWorks()
{
using (var transport = new TcpTransport())
{
var authKey = await Authenticator.DoAuthentication(transport);
Assert.IsNotNull(authKey.AuthKey.Data);
}
}
public static async Task Send(string message)
{
var store = new FileSessionStore();
var client = new TLSharp.Core.TelegramClient(store, "session");
var connected = await client.Connect();
if (!client.IsUserAuthorized())
{
var hash = await client.SendCodeRequest("+phone");
var code = "35828"; // you can change code in debugger
var user = await client.MakeAuth("+phone", hash, code);
}
var res = await client.ImportContact("@IrisTed");
await client.SendMessage(res.Value, message);
}
Hi Again.
I'm developing a windows application which serves a WCF Service, which other apps could invoke it for telegram messaging (instead of sms notifications to my users).
After a while since application is idle, it seems that tcp connection get closed and I get errors when calling sendmessage method.
Do have any advice for this problem?
i passed TestConnection and AuthUser successfully,
but in SendMessage Test i got this error:
Test Name: SendMessage
Test FullName: TLSharp.Tests.NotificatioClientTests.SendMessage
Test Source: F:\Telegram\003 - TLSharp-master\TLSharp-master\TLSharp.Tests\NotificatioClientTests.cs : line 101
Test Outcome: Failed
Test Duration: 0:00:02.85505
Result StackTrace:
at TLSharp.Tests.NotificatioClientTests.d__16.MoveNext() in F:\Telegram\003 - TLSharp-master\TLSharp-master\TLSharp.Tests\NotificatioClientTests.cs:line 108
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Result Message: Assert.IsTrue failed.
any idea?
it connect ok, but when a trying to make AuthUser it gave this error "Your phone number registered to 1 dc. Please update settings. See https://github.com/sochix/TLSharp#i-get-an-error-migrate_x for details.". I use all these, but still doesn't work
i checked these server:
Server 1: 149.154.175.50:443
Server 2: 149.154.167.51:443
Server 3: 149.154.175.100:443
Server 4: 149.154.167.91:443
Server 5: 91.108.56.165:443
server 6:149.154.167.40:443
server 7:149.154.167.50:443
and set phone numbers in app.configs but doesn't work,
how can i create Session.dat file?
hi.
in TLSharp.Core.Requests.AckRequest you in line 36 you wrote :
public override bool Confirmed => false;
i have VS 2013, why my VS doesn't recognize this?
please help, i can't build the project. :-(
Hi
This wrapper work fine on win app.
Can i use this wrapper on web application or web service?
I tested, but can't work. stop on client.Connect() method!
Thanks
Hi
can i ask u about these three phone numbers?
what about numberToAuthenticate, registeredNumber and unregisteredNumber?
i set them like this:
MyPhoneNumber means that number i registered it in Telegram Site for giving API Code.
is that alright?
what about unregisteredNumber?
thanks
hi.
in following method : OnResponse in class : AuthSendCodeRequest
in following lines :
var sendCodeTimeout = reader.ReadInt32();
var isPassword = reader.ReadUInt32() == boolTrue;
it return an exception with following content :
unable to read beyond the end of stream.
in register form in telegram api, i get Public keys, should i put it some where?
and also im getting PHONE_NUMBER_UNOCCUPIED , but im registered in telegram
please help. im realy stucked on this
after many struggling i am in this section now.
http://s3.picofile.com/file/8214980850/1.PNG
and Authuser test is running for more than 5 minute. what i must do. or what is wrong with my action?
Thanks.
I always receive error PHONE_CODE_EXPIRED.
i receive two message with only one code from Telegram but this code not work :(
any idea for this bug? and why telegram send 2 message for one code?
Hi
Could you kindly add functions for working with chats?
Or if have'nt enough time, if you guide me I could help to develop and improve your library.
I'm a senior developer with 22 year of software development experience.
If you like my offer, we could talk here or in telegram. I will give you my phone number for telegram chat.
please can I use your TLSHARP to send file now I can send text message can I send photo or any file if I can please give me any sample
thanks
hi
How do I implement channels.createChannel?
Layer 41 is implemented. But I do not know flags: # will not implement any
hello
works sent message but sometimes in line
if (!constructors.ContainsKey(dataCode))
{
throw new Exception(String.Format("invalid constructor code {0}", dataCode));
}
Exception thrown: 'System.Exception' in TLSharp.Core.dll ("invalid constructor code 1444835612")
why?
I understand that this is not realized , but how do I implement the event to receive messages ?
hi
tanks for great library
I have a problem with sendmessage after release layer version 42
I can send message before but now i can't
I saw sendmessage schema in layer 42 . some parameters added to method
I try to add this parameters but it doesn't work
please help me
tanks
after I used AuthUser with defaultConnectionAddress = "91.108.56.165"
I get this error
" An exception of type 'System.InvalidOperationException' occurred in mscorlib.dll but was not handled in user code
Additional information: Your phone number registered to 1 dc. Please update settings. See https://github.com/sochix/TLSharp#i-get-an-error-migrate_x for details."
I go to link https://github.com/sochix/TLSharp#i-get-an-error-migrate_x and read I must chage server address I change it to defaultConnectionAddress = "149.154.167.51" then try again I get this error
" An exception of type 'System.IO.EndOfStreamException' occurred in mscorlib.dll but was not handled in user code
Additional information: Unable to read beyond the end of the stream. "
please any help and I hope give me complete work example
thanks
hi: i get this error after invoke sendMessage method in test mode :
unable to cast object of type 'TLSharp.Core.MTProto.UserContactCostructor' to type TLSharp.Core.MTProto.UserSelfCostructor
please help me.
hi
very thanks for this app .i`m used it but when compile show error tlcore.dll not found
please help me
when I call SendMessage method, get error : Unable to read beyond the end of the stream.
!?
Hi.
I successfully passed AuthUser Test. Problem was the server ip which is solved by setting server address to 149.154.167.91 .
Now when debugging ImportContact test i get following exception:
Test method TLSharp.Tests.NotificatioClientTests.ImportContact threw exception:
System.InvalidCastException: Unable to cast object of type 'TLSharp.Core.MTProto.UserSelfConstructor' to type 'TLSharp.Core.MTProto.UserContactConstructor'.
hi.
im getting the following error in makeauth method:
PHONE_NUMBER_UNOCCUPIED
i receive code from telegram and send in parameter but i get error.
please help.
thanks
I am receiving two types of errors when calling AuthUser test.
For a few IPs (e.g. 149.154.175.100) I receive the SMS but code faces with an exception:
EndOfStreamException: Unable to read beyond the end of the stream
which prevents code from normal execution and 'hash' variable being filled appropriately and ultimately test being failed.
When using other IPs (e.g. 149.154.175.50, 149.154.167.91, &...), I receive:
Your phone number registered to 3 dc. Please update settings.
I have no way of calling help.getConfig or getting updated list of DCs and I put break-point on any possible line to find the place DC IP might be returned, but found no clues.
Please guide me by resolving EndOfStreamException or updating me with a DC address which accepts requests from a phone number registered in DC 3.
Thanks
Hi. When i run unit tests i get this error:
TLSharp.Tests.NotificatioClientTests.AuthUser threw 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.
hi, before i point out the my problem, i appreciating developers for this nice and clean api code!
what i have to set for offset and limit? i don't know photo size! to use it in offset!!!
i know i can use that for chunked download , part by part, but if i wont like to download chunked file
can i set 0, 0 for both?
i did that and i got this respone:
type =>> {(storage_fileJpeg)}
mtime =>> 1446716047
bytes =>> {byte[9484]}
how i can see the photo from {byte[9484]}?
i used this code:
using (var ms = new MemoryStream(byteArrayIn))
{
return new Bitmap(ms);
}
and set that return for a PictureBox.Image
but it return exception with: Invalid Parameter!
(it says that the byte format is not correct for Bitmap).
hint:
because i have not offset and limit, i changed some part of code in GetFileRequest:
public override void OnResponse(BinaryReader reader)
{
var code = reader.ReadUInt32(); // upload.file#96a18d5
type = TL.Parse<storage_FileType>(reader);
mtime = reader.ReadInt32();
bytes = reader.ReadBytes(int.Parse((reader.BaseStream.Length - reader.BaseStream.Position).ToString()));
}
thanks in advance!
Hi boys,
i'm trying to use TLSharp on Xamarin studio, but code crash calling client.Connect()... on step 2 of DoAuthentication Task.
System return this error code on step 2 of DoAuthentication task:
System.IO.EndOfStreamException: Failed to read past end of stream.
Have an ideas?
Thank you so much!!
hi.
please can you help me to define InputMedia
I need to send photo then I need to define message content as inputmedia can you help me in this
thanks
Hi
1- Every time I run make project I have to run AuthUser test and get a code from telegram, otherwise none of methods work and they wait for unlimited time.
Is there any workaround for this?
2- I tested these servers:
Server 1: 149.154.175.50:443
Server 2: 149.154.167.51:443
Server 3: 149.154.175.100:443
Server 4: 149.154.167.91:443
Server 5: 91.108.56.165:443
and only server with address 149.154.167.91 works, other servers return exceptions when calling their methods.
The exception is:
Test method TLSharp.Tests.NotificatioClientTests.AuthUser threw exception:
System.IO.EndOfStreamException: Unable to read beyond the end of the stream.
More strange part is that they send code to me using sms, and then return above exception.
Is there any reason for this?
3- When i send someone a message, his contact name changes to "My Test Name" for me. What to do with this?
Hi, Ilya. Thank you for the great work.
AuthUser test has failed because SendCodeRequest method thrown a exception in mscorlib.dll and i can't receive SMS code to my phone number. I try 0,1 and 5 value in sms_type parameter.
TestConnection and AutheficationWorks works fine.
Visual Studio 2015 Community, Win7 32-bit
Regards, Egor
Hi. I want to be able to retrieve my conversation in a chat with another person. can i do this using TLSharp?
Thanks.
Hi,what's create class to send sms to unregistered number because to register number with TLSharp.core.
TLSharp.core has auth.encoDe.
The issue is being reported among comments here:
#17 (comment)
and exists. I'm sure the DC address is correct and the exception is due to a change from Telegram side which makes the operation not being completed.
I am using the following Code
private async void btrequestcode_Click(object sender, EventArgs e)
{
var store = new FileSessionStore();
var client = new TelegramClient(store, "session");
await client.Connect();
var hash = await client.SendCodeRequest(tbmobile.Text);
MessageBox.Show(hash);
}
but i am unable to get the hash variable.
I am using 149.154.167.50 and also used other IPs : 91.108.56.165 , 149.154.167.90, 149.154.167.91
Please guide me , where i am wrong.
hi
when I create account telegram using phone number I get it from textplus program
the account blocked from sending message
any help
thanks
error in AuthUser:
I get an exception: System.IO.EndOfStreamException: Unable to read beyond the end of the stream
how can i config session?
it's written in code with the default of "session" creating session.dat file.
please help me.
thanx
hello
How can I use the library
And send me the telegram
please advice
Thank you
Hi. and thank you for this project. In step 4 of https://github.com/sochix/TLSharp#quick-configuration you sayed Run test testConnection(). How can i do this? and another question that i have is that is this a project to import in visual studio or it is a library for adding to another project? Thank you.
Hi
i have problem with AuthUser when my number is new Telegram Number and not registered on tegegram yet. in this cases i recive sms on my phone but error on MakeAuth func.
for telegram numbers i can recive code via sms and on actived telegram and no problem.
thank's
Hi. 2 of tests(Test Connection and AuthenticationWorks) passed. but when i run authuser test First: I do not receive message from telegram and Second: Where the Session.dat file located? Thanks for your help.
This image is for more info:
http://s6.picofile.com/file/8215040434/from10.PNG
Thanks for you helping.
I Got MIGRATE_X error for some numbers
i have tested all 5 servers and there was no luck !
where i can find suitable server address
do i have to test all servers ?
Hi. This is the code i'm using.
public static void Send(string message)
var store = new FileSessionStore();
var client = new TelegramClient(store, "session");
var connected = await client.Connect();
if (!client.IsUserAuthorized())
{
var hash = await client.SendCodeRequest("+myponenumber");
var code = "33219"; // you can change code in debugger
var user = await client.MakeAuth("+myponenumber", hash, "33219");
}
var res = await client.ImportContact("@mychannel");
await client.SendMessage(res.Value, message);
}
When I run this function, I get this error:
[InvalidOperationException: API_ID_INVALID]
TLSharp.Core.Network.MtProtoSender.HandleRpcResult(UInt64 messageId, Int32 sequence, BinaryReader messageReader, MTProtoRequest request) +983
TLSharp.Core.Network.MtProtoSender.processMessage(UInt64 messageId, Int32 sequence, BinaryReader messageReader, MTProtoRequest request) +945
TLSharp.Core.Network.d__8.MoveNext() +627
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
System.Runtime.CompilerServices.TaskAwaiter1.GetResult() +28 TLSharp.Core.<SendCodeRequest>d__14.MoveNext() +538 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58 System.Runtime.CompilerServices.TaskAwaiter
1.GetResult() +28
M***************TelegramSender.cs:61
I have set the _apiId and _apiHash values in telegram client with the values I have in https://my.telegram.org/apps
The number I'm using in SendCodeRequest is my number (app owner).
A weird thing is: when I run this function for the first time, the response returned on client.Connect() is good. But for the second time, I get the same API_ID_INVALID exception. But it's catched in MtProtoSender.HandleContainer
Please help
hi
i execute tutorial step by step, when i run testConnection test function
but doesn't create session.dat
actually i set breakpoint step by step, when reach Receieve function in tcpTransport.cs file suddenly exit and close program,
when run AuthUser function and set breakpoint on "var code = "123"" never reach this line and exit from program
why?
tnx
Hi. i am doing a registeration check for my list of phone numbers. but after doing 9 or 10 of checks an rpc error for FLOOD_WAIT occur and in debug write that you must wait(for example 270 sec.) why this error occur? and how to pass from this error. please explain about it. Thanks.
the library works fine for me, i could make it work with layer40, except at TcpMessage.cs line 63, sometimes the packetLength
is negative or more than packet size.
thanks for your great work
I studied issues but still have problems in using the TLSharp.
Please give the following code:
One Button(btnSend) and two TextBox(txtMessage,txtNumber) on a form, each time the button is clicked text in 'txtMessage' is send to the 'txtNumber'
thanks
please all can any one help me I want run telegram instance from multiple numbers
I use one of registered number . But is there any way to switch to another number ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.