I found many examples using the bot api, however I need a simple client that implements an event when a message from a contact or group is received, as a user and not a bot (so the Telegram api, and not Bot api). TLSharp library doesn't implement this method. What is the best way to achieve it?
Asked
Active
Viewed 5,534 times
3
-
1how about checking this https://github.com/sochix/TLSharp/issues/580 – InYeopTTi Aug 23 '21 at 06:30
-
1good starting point... I am going to implement the suggestions from this issue workaround and provide the result – Jaume Aug 23 '21 at 08:21
2 Answers
4
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 simple to use. Follow the README on GitHub for an easy introduction.
To monitor Update events that are pushed to the client whenever a message is posted somewhere (or other events), take a look at the Examples\Program_ListenUpdate.cs. It demonstrates how to print most events, including messages posted in groups/channels/private chats

Wizou
- 1,336
- 13
- 24
0
The provided link is old but it was a good starting point. Here is the updated working code:
while (true)
{
var state = await _client.SendRequestAsync<TLState>(new TLRequestGetState());
TrackingState = state.Pts.ToString();
var req = new TLRequestGetDifference() { Date = state.Date, Pts = state.Pts-10, Qts = state.Qts };
var diff = await _client.SendRequestAsync<TLAbsDifference>(req);
var msgs = diff as TLDifference;
if (msgs!=null && msgs.NewMessages.Count>0)
{
var mss = msgs.NewMessages.Where(x => x.GetType() == typeof(TLMessage))
.Cast<TLMessage>().ToList().Where(x => x.Date > _lastMessageStamp && x.Out == false)
.OrderBy(dt => dt.Date);
foreach (TLMessage upd in mss)
{
Console.WriteLine("New message ({0}): {1}", upd.Date, upd.Message);
}
_lastMessageStamp = mss.Any() ? mss.Max(x => x.Date) : _lastMessageStamp;
}
await Task.Delay(2500);
}

Jaume
- 3,672
- 19
- 60
- 119