tdlib / td

Cross-platform library for building Telegram clients
https://core.telegram.org/tdlib
Boost Software License 1.0
7.11k stars 1.44k forks source link

[forwardMessages] You cannot see the message that is currently requested to be forwarded, but the message that was requested to be forwarded last time. #2570

Closed DukeAnn closed 1 year ago

DukeAnn commented 1 year ago

When a message is forwarded from one channel to another channel, why the response is normal, but the forwarded message cannot be seen, or is the message ID that I forwarded last time being forwarded? After I use this method again, do I need to call any other method to make the forwarding take effect? At present, I call getChats once after forwarding to see the latest forwarded message. Is this operation as expected?

versions v1.8.0

golang: https://github.com/zelenin/go-tdlib

        _, err = tdClient.GetChats(&client.GetChatsRequest{
        ChatList: &client.ChatListMain{},
        Limit:    10,
    })

    if err != nil {
        log.Fatalf("GetChats error: %s", err)
    }
        var fromMessageId int64
    _, err := tdClient.ClearAllDraftMessages(&client.ClearAllDraftMessagesRequest{})
    if err != nil {
        t.Fatal(err)
    }
    var messageIds MessageIdSort
    for i := 0; i < 10; i++ {
        res, err := tdClient.GetChatHistory(&client.GetChatHistoryRequest{
            ChatId:        -10015*****540,
            Limit:         10,
            FromMessageId: fromMessageId,
            Offset:        0,
            // OnlyLocal:     true,
        })
        if err != nil {
            t.Fatal(err)
        }

        if len(res.Messages) == 0 {
            break
        }
        for _, msg := range res.Messages {
            messageIds = append(messageIds, msg.Id)
        }

        fromMessageId = res.Messages[len(res.Messages)-1].Id
        resByte, _ := json.Marshal(res)
        log.Printf("%v: GetChats GetMessages: %s\n", i, resByte)
    }

    sort.Sort(messageIds)
    fmt.Println(messageIds)
    res1, err := tdClient.ForwardMessages(&client.ForwardMessagesRequest{
        ChatId:        -10017*****997,
        FromChatId:    -10015*****540,
        MessageIds:    messageIds,
        Options:       nil,
        SendCopy:      false,
        RemoveCaption: false,
        OnlyPreview:   false,
    })
    if err != nil {
        t.Fatal(err)
    }
    resByte, _ := json.Marshal(res1)
    log.Printf("GetChats ForwardMessages: %s\n", resByte)

    _, err = tdClient.GetChats(&client.GetChatsRequest{
        ChatList: &client.ChatListMain{},
        Limit:    10,
    })

    if err != nil {
        log.Fatalf("GetChats error: %s", err)
    }
DukeAnn commented 1 year ago

This problem has troubled me for several days. What is the correct way to write it?

levlam commented 1 year ago

forwardMessages returns temporary local messages. You need to handle updates updateMessageSendSucceeded/updateMessageSendFailed/updateDeleteMessages for the messages to wait for sending to be compelted and to actually receive the sent messages.

DukeAnn commented 1 year ago

than you