How Use Telegram API in C# With SharpTelegram i use this https://github.com/Everbytes/SharpTL seed message to phone number have telegram in c# i need sample use of this lib tanx
Asked
Active
Viewed 6,618 times
3
-
The SharpTL lib is for serialization/deserialization only. There are SharpMTProto+SharpTelegram libs in frozen undone state. – some_engineer Mar 02 '16 at 14:14
-
@AlexanderLogger that's why the best bet is to understand how Telegram works, write your own library and adapt it as Telegram adds new features. Once you get the basics down... its pretty straight forward – Charles Okwuagwu Mar 02 '16 at 14:57
-
@CharlesO may be, but at least serializer is done, tested and works good. Also there is no need to write a new lib, a lot of work already done with existed libs, though not done, yet. That's how free and open source software should be developed if possible. I'm not interested in developing for .net/mono at the moment, but if someone wants to develop a telegram client lib, one should take a better look at what it is already done and continue developing of it. But if one will say that it is too hard to understand the undone lib, or it has a not good design, then it is OK. – some_engineer Mar 02 '16 at 16:35
-
@AlexanderLogger good points, but the thing is, most libs might be older Telegram layers, maybe just up to 23. The current API is on layer 48... Knowing how to write your own TL parser etc enables you update your lib as required. You may build of course on other OSS work if you must. But just as you pointed out, there are libs out there frozen and incomplete, or out of date – Charles Okwuagwu Mar 02 '16 at 17:01
-
@CharlesO actually layer system is an independent part based upon core protocol which stays the same, hence almost all implemented things are not outdated (at least SharpTL and SharpMTProto), only supported layer of the API, which can easily updated from current layer json with a special tool: SharpTL.Compiler. – some_engineer Mar 02 '16 at 17:38
3 Answers
2
You might want to take a look at this C# telegram Library instead: https://github.com/sochix/TLSharp
Also you might want to get started on learning their API and building your own library from scratch.
Here are some notes to get you started: https://stackoverflow.com/a/32809138/44080
Cheers

Community
- 1
- 1

Charles Okwuagwu
- 10,538
- 16
- 87
- 157
2
There is now WTelegramClient, using the latest Telegram Client API protocol (connecting as a user, not bot).
The library is very complete but also very easy to use. Follow the README on GitHub for an easy introduction.
To send a message to someone can be as simple as:
using TL;
using var client = new WTelegram.Client(); // or Client(Environment.GetEnvironmentVariable)
await client.LoginUserIfNeeded();
var result = await client.Contacts_ImportContacts(new[] { new InputPhoneContact { phone = "+PHONENUMBER" } });
await client.SendMessageAsync(result.users[result.imported[0].user_id], "Hello");
//or by username:
//var result = await client.Contacts_ResolveUsername("USERNAME");
//await await client.SendMessageAsync(result.User, "Hello");

Wizou
- 1,336
- 13
- 24
0
With C# telegram Library at https://github.com/sochix/TLSharp TLSharpTests.cs contains examples:
public async Task ImportContactByPhoneNumberAndSendMessage()
{
// User should be already authenticated!
var store = new FileSessionStore();
var client = new TelegramClient(store, "session");
await client.Connect();
Assert.IsTrue(client.IsUserAuthorized());
var res = await client.ImportContactByPhoneNumber(NumberToSendMessage);
Assert.IsNotNull(res);
await client.SendMessage(res.Value, "Test message from TelegramClient");
}

Tony
- 135
- 9