Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UpdateEditChannelMessage gets improperly triggered #221

Closed
heinsenberg82 opened this issue Dec 12, 2023 · 6 comments
Closed

UpdateEditChannelMessage gets improperly triggered #221

heinsenberg82 opened this issue Dec 12, 2023 · 6 comments
Labels
invalid Issue seems invalid, on user side, or unrelated to project

Comments

@heinsenberg82
Copy link

My sample code (based on this documented example: https://github.com/wiz0u/WTelegramClient/blob/master/Examples/Program_ListenUpdates.cs?ts=4#L23):

_client.OnUpdate += Client_OnUpdate;

private async Task Client_OnUpdate(UpdatesBase updates)
    {
        updates.CollectUsersChats(Users, Chats);
        if (updates is UpdateShortMessage usm && !Users.ContainsKey(usm.user_id))
            (await _client.Updates_GetDifference(usm.pts - usm.pts_count, usm.date, 0)).CollectUsersChats(Users, Chats);
        else if (updates is UpdateShortChatMessage uscm &&
                 (!Users.ContainsKey(uscm.from_id) || !Chats.ContainsKey(uscm.chat_id)))
            (await _client.Updates_GetDifference(uscm.pts - uscm.pts_count, uscm.date, 0)).CollectUsersChats(Users, Chats);
        foreach (var update in updates.UpdateList)
            switch (update)
            {
                case UpdateNewChannelMessage unm:
                    Console.WriteLine($"New message in {Chat(unm.message.Peer.ID)}: {((Message)unm.message).message}");
                    await HandleMessage(unm.message);
                    break;
                case UpdateEditChannelMessage uem:
                    Console.WriteLine($"Edit message in {Chat(uem.message.Peer.ID)}: {((Message)uem.message).message}");
                    await HandleMessage(uem.message, true);
                    break;
                default:
                    _logger.LogInformation("{Name}", update.GetType().Name);
                    break; // there are much more update types than the above example cases
            }
    }

Everytime someone posts something new (WITHOUT ANY EDITING) in a supergroup I'm monitoring, my console looks like this:

New message in Channel "MonitoredChannel": somemsg.
Edit message in Channel "MonitoredChannel": somemsg.
@wiz0u
Copy link
Owner

wiz0u commented Dec 12, 2023

You should give more details about your problem.
Please provide:

  • Version of WTelegramClient and version of .NET you're using
  • Library logs from the start of the program up to the problem
    (see here how to redirect WTelegramClient logs to file)

@wiz0u
Copy link
Owner

wiz0u commented Dec 12, 2023

If there is effectively an UpdateEditChannelMessage in the logs, then it's Telegram server behaviour, not the library's.

@heinsenberg82
Copy link
Author

Version of WTelegramClient: 3.6.1

I did exactly what you asked for, using Serilog. Instead of passing the logs to a file, i passed to the console. I used the debug level. Log looks like this:

Loaded previous session
WTelegramClient 3.6.1 running under .NET 7.0.14
[10:00:17 INF] Connecting to xxx.xxx.xxx.xx:443...
[10:00:17 DBG] 1>Sending   InvokeWithLayer`1                        #D82D
[10:00:17 DBG] 1>Receiving MsgContainer                             2023-12-13 13:00:17Z (svc)
[10:00:17 DBG]             → MsgDetailedInfo                        2023-12-13 13:00:17Z (svc) 
[10:00:17 DBG]             → Updates                                2023-12-13 13:00:17Z  
[10:00:17 DBG]             → UpdateShort                            2023-12-13 13:00:17Z  
[10:00:17 DBG]             → MsgsAck                                2023-12-13 13:00:17Z (svc)
[10:00:17 DBG] 1>Receiving RpcResult                                2023-12-13 13:00:17Z
[10:00:17 DBG]              → Config                                #D82D
[10:00:17 INF] Connected to DC 1... default_p2p_contacts, revoke_pm_inbox
[10:00:17 DBG] 1>Sending   MsgContainer                             2023-12-13 13:00:17Z (svc)
[10:00:17 DBG]             → Users_GetUsers                         #D831
[10:00:17 DBG]             → MsgsAck
[10:00:17 DBG] 1>Receiving RpcResult                                2023-12-13 13:00:17Z
[10:00:17 DBG]              → UserBase[]                            #D831
We are logged-in as xxxxx (id xxxxxxxxxx)
[10:00:38 DBG] 1>Receiving UpdateShort                              2023-12-13 13:00:38Z  
[10:00:38 INF] UpdateChannelMessageViews
[10:00:44 DBG] 1>Receiving UpdateShort                              2023-12-13 13:00:44Z  
[10:00:44 INF] UpdateChannelMessageViews
[10:00:45 DBG] 1>Receiving UpdateShort                              2023-12-13 13:00:45Z  
[10:00:45 INF] UpdateUserStatus
[10:00:47 DBG] 1>Receiving Updates                                  2023-12-13 13:00:47Z  
[10:00:47 INF] UpdateReadChannelInbox
[10:01:17 DBG] 1>Sending   MsgContainer                             2023-12-13 13:01:16Z (svc)
[10:01:17 DBG]             → PingDelayDisconnect                    #5CB8
[10:01:17 DBG]             → MsgsAck
[10:01:17 DBG] 1>Receiving Pong                                     2023-12-13 13:01:17Z (svc) 
[10:01:18 DBG] 1>Receiving UpdateShort                              2023-12-13 13:01:18Z  
[10:01:18 INF] UpdateChannelMessageViews
[10:01:20 DBG] 1>Receiving UpdateShort                              2023-12-13 13:01:20Z  
[10:01:20 INF] UpdateChannelMessageViews
[10:01:26 DBG] 1>Receiving UpdateShort                              2023-12-13 13:01:26Z  
[10:01:26 INF] UpdateChannelMessageViews
[10:01:28 DBG] 1>Receiving UpdateShort                              2023-12-13 13:01:28Z  
[10:01:28 INF] UpdateUserStatus
[10:01:37 DBG] 1>Receiving UpdateShort                              2023-12-13 13:01:37Z  
[10:01:37 INF] UpdateChannelMessageViews
[10:01:43 DBG] 1>Receiving UpdateShort                              2023-12-13 13:01:43Z  
[10:01:43 INF] UpdateChannelMessageViews
[10:02:04 DBG] 1>Receiving MsgContainer                             2023-12-13 13:02:04Z (svc)
[10:02:04 DBG]             → UpdateShort                            2023-12-13 13:02:04Z
[10:02:04 DBG]             → Updates                                2023-12-13 13:02:04Z
[10:02:04 INF] UpdateChannelMessageViews
[10:02:04 INF] New message in Channel "MonitoredChannel": 
[10:02:05 DBG] 1>Receiving UpdateShort                              2023-12-13 13:02:05Z  
[10:02:05 INF] UpdateChannelMessageViews
[10:02:07 DBG] 1>Receiving UpdateShort                              2023-12-13 13:02:07Z  
[10:02:07 INF] UpdateChannelMessageViews
[10:02:08 DBG] 1>Receiving UpdateShort                              2023-12-13 13:02:08Z  
[10:02:08 INF] UpdateChannelMessageViews
[10:02:09 DBG] 1>Receiving UpdateShort                              2023-12-13 13:02:09Z  
[10:02:09 INF] UpdateChannelMessageViews
[10:02:13 DBG] 1>Receiving MsgContainer                             2023-12-13 13:02:13Z (svc)
[10:02:13 DBG]             → UpdateShort                            2023-12-13 13:02:13Z
[10:02:13 DBG]             → Updates                                2023-12-13 13:02:13Z
[10:02:13 INF] UpdateChannelMessageViews
[10:02:13 INF] Edit message in Channel "MonitoredChannel":
[10:02:13 DBG] 1>Receiving UpdateShort                              2023-12-13 13:02:13Z  
[10:02:13 INF] UpdateChannelMessageViews
[10:02:14 DBG] 1>Receiving UpdateShort                              2023-12-13 13:02:14Z 
[...]

You should give more details about your problem. Please provide:

  • Version of WTelegramClient and version of .NET you're using
  • Library logs from the start of the program up to the problem
    (see here how to redirect WTelegramClient logs to file)

@wiz0u
Copy link
Owner

wiz0u commented Dec 13, 2023

ah sorry, i meant to log type of each received update..
something like

foreach (var update in updates.UpdateList)
{
	Console.WriteLine(update.GetType().Name);
	...

@heinsenberg82
Copy link
Author

heinsenberg82 commented Dec 13, 2023

Sure. I added this line:

foreach (var update in updates.UpdateList)
        {
            _logger.LogInformation("Update type: {Update}", update.GetType().Name); // <-----
            switch (update)
        /// ...

Now the log looks like this:

[15:32:51 DBG] 1>Receiving MsgContainer                             2023-12-13 18:32:50Z (svc)
[15:32:51 DBG]             → UpdateShort                            2023-12-13 18:32:50Z
[15:32:51 DBG]             → Updates                                2023-12-13 18:32:50Z
[15:32:51 INF] Update type: UpdateChannelMessageViews
[15:32:51 INF] UpdateChannelMessageViews
[15:32:51 INF] Update type: UpdateNewChannelMessage
[15:32:51 INF] New message in Channel "MonitoredChannel": Some message
[15:32:53 DBG] Starting HttpMessageHandler cleanup cycle with 1 items
[15:32:53 DBG] Ending HttpMessageHandler cleanup cycle after 0.0026ms - processed: 0 items - remaining: 1 items
[15:32:55 DBG] 1>Receiving MsgContainer                             2023-12-13 18:32:55Z (svc)
[15:32:55 DBG]             → UpdateShort                            2023-12-13 18:32:55Z
[15:32:55 DBG]             → Updates                                2023-12-13 18:32:55Z
[15:32:55 INF] Update type: UpdateChannelMessageViews
[15:32:55 INF] UpdateChannelMessageViews
[15:32:55 INF] Update type: UpdateEditChannelMessage
[15:32:55 INF] Edit message in Channel "MonitoredChannel": Some message

I can confirm that the message was NOT edited. So, if it's not some kind of bug in the library, I really don't know why Telegram server would send this wrong data.

ah sorry, i meant to log type of each received update.. something like

foreach (var update in updates.UpdateList)
{
	Console.WriteLine(update.GetType().Name);
	...

@wiz0u
Copy link
Owner

wiz0u commented Dec 16, 2023

maybe it's not the message itself that was modified but something around it, like reactions, fwd_from infos, topic info, ...

anyway, it's a Telegram server notification, so... 🤷🏻‍♂️

Reminder: this library is developed independently from Telegram teams.

@wiz0u wiz0u closed this as completed Dec 16, 2023
@wiz0u wiz0u added the invalid Issue seems invalid, on user side, or unrelated to project label Dec 16, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
invalid Issue seems invalid, on user side, or unrelated to project
Projects
None yet
Development

No branches or pull requests

2 participants