wtelegramclient

Which session triggered the event?


I'm trying to use 2 sessions.

If I understood the FAQ correctly, I should do it like this.

    static async Task Main(string[] _)
    {
        Helpers.Log = (l, s) => Debug.WriteLine(s);
        Clients.Add(new Client(what => Config(what, "session1")));
        Clients.Add(new Client(what => Config(what, "session2")));

        for (int i = 0; i < Clients.Count; i++)
        {
            Clients[i].OnUpdate += Client_OnUpdate;
            MyUsers.Add(new User());
            MyUsers[i] = await Clients[i].LoginUserIfNeeded();
            var dialogs = await Clients[i].Messages_GetAllDialogs();
            dialogs.CollectUsersChats(Users, Chats);
        }

        Console.ReadKey();
    }

But I can't figure out which session I'm getting the message from. How can I understand this ?

In IObject arg I could not find this information, because I do not have enough knowledge(

Client_OnUpdate(IObject arg)

Update

Something is not working as I expected(

I did everything as you said.

    static async Task Main(string[] _)
    {
        Helpers.Log = (l, s) => Debug.WriteLine(s);
        Clients.Add(new Client(what => Config(what, "session1")));
        Clients.Add(new Client(what => Config(what, "session2")));

        for (int i = 0; i < Clients.Count; i++)
        {
            Clients[i].OnUpdate += updates => Client_OnUpdate(updates, i);
            MyUsers.Add(new User());
            MyUsers[i] = await Clients[i].LoginUserIfNeeded();
            var dialogs = await Clients[i].Messages_GetAllDialogs();
            dialogs.CollectUsersChats(Users, Chats);
        }

        Console.ReadKey();
    }

    private static async Task Client_OnUpdate(IObject arg, int i)
    {
        Debug.WriteLine($"i = {i}");
    }

Log:

2>Receiving Updates                                  2023-05-09 18:55:00Z  
    i = 2
    2>Receiving Updates                                  2023-05-09 18:55:01Z  
    i = 2
    2>Receiving UpdateShort                              2023-05-09 18:55:02Z  
    i = 2
    2>Receiving UpdateShort                              2023-05-09 18:55:02Z  
    i = 2
    4>Receiving Updates                                  2023-05-09 18:55:03Z  
    i = 2
    4>Receiving Updates                                  2023-05-09 18:55:03Z  
    i = 2
    2>Receiving UpdateShort                              2023-05-09 18:55:04Z  
    i = 2
    2>Receiving MsgContainer                             2023-05-09 18:55:05Z (svc)
                → UpdateShort                            2023-05-09 18:55:05Z  
                → Updates                                2023-05-09 18:55:05Z  
    i = 2
    i = 2
    2>Receiving Updates                                  2023-05-09 18:55:05Z  
    i = 2
    4>Receiving Updates                                  2023-05-09 18:55:05Z  
    i = 2
    2>Receiving UpdateShort                              2023-05-09 18:55:06Z  
    i = 2
    4>Receiving Updates                                  2023-05-09 18:55:06Z  
    i = 2
    4>Receiving Updates                                  2023-05-09 18:55:07Z  
    i = 2
    4>Receiving Updates                                  2023-05-09 18:55:07Z  
    i = 2
    2>Receiving Updates                                  2023-05-09 18:55:08Z  
    i = 2
    2>Receiving Updates                                  2023-05-09 18:55:08Z  
    i = 2
    2>Receiving Updates                                  2023-05-09 18:55:09Z  
    i = 2
    4>Receiving Updates                                  2023-05-09 18:55:10Z  
    i = 2

Solution

  • modify your Client_OnUpdate to take an extra i argument, and register it like that:

    Clients[i].OnUpdate += updates => Client_OnUpdate(updates, i)
    

    You might want to learn more about lambda expressions...