steavy29 / Telegram.Net

Telegram (http://telegram.org) client library implemented in C#.
17 stars 6 forks source link

How can i receive a message #25

Closed wasimjee closed 7 years ago

wasimjee commented 7 years ago

How can i receive a message from users

steavy29 commented 7 years ago

You should create an instance of TelegramClient, subscribe to appropriate Update event and then invoke Start method. Afterwards all messages will be propagated through Update event.

wasimjee commented 7 years ago

Any Sample code for creating update events please.

steavy29 commented 7 years ago

I'll be able to get you sample of code in the evening. But the main idea is that you subscribe to UpdateMessage event and then if\else on type of Updates object. To know what could be there see descendants of Updates class. Generally it should reflect these types from the documentation https://core.telegram.org/type/Updates

wasimjee commented 7 years ago

@steavy29 Thank you very much , i will be waiting for a sample.

steavy29 commented 7 years ago

Subscribe to event
client.UpdateMessage += UpdateMessage;

Handle update event

        private void UpdateMessage(object sender, Updates update)
        {
            switch (update.Constructor)
            {
                case Constructor.updatesTooLong:
                {
                    // need to download updates manually
                    break;
                }
                case Constructor.updateShortMessage:
                {
                    var upd = update as UpdateShortMessageConstructor;
                    // upd.message
                    break;
                }
                case Constructor.updates:
                {
                    var upd = update as UpdatesConstructor;
                    foreach (var updatePiece in upd.updates)
                    {
                        // handle update
                    }
                    break;
                }
            }
            // ...
        }