skip to Main Content

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?

2

Answers


  1. Chosen as BEST ANSWER

    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);
                }
    

  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 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 ExamplesProgram_ListenUpdate.cs. It demonstrates how to print most events, including messages posted in groups/channels/private chats

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search