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

Getting the message that i have just sent. #2377

Closed YarnikeyZ closed 1 year ago

YarnikeyZ commented 1 year ago

Getting the message that i have just sent.

I have only a little bit of experience in c# so this is might be obvious but i am struggling with it.

I have a function that sends a message, it's pretty much an un-edited ctrl+c + ctrl+v from the example

private static void sendMessage(string text, long chatId, TdApi.Message message = null)
{
    if (message != null) { chatId = message.ChatId; }
    TdApi.InputMessageContent content = new TdApi.InputMessageText(new TdApi.FormattedText(text, null), false, true);
    _client.Send(new TdApi.SendMessage(chatId, 0, 0, null, null, content), _defaultHandler);
}

But _client.Send() redirects function output (message that i need) to only Td.ClientResultHandler and from it i obviosly can't get it back since it returns only void.
I have tried to send message in sync but it's can't be done.
So, how do i get back (to sendMessage function) the message that i just sent?

levlam commented 1 year ago

You need to specify an appropriate response handler instead of _defaultHandler. TdApi.SendMessage returns a temporary local message. You need to wait and handle updateMessageSendSucceeded/updateMessageSendFailed/updateDeleteMessages for the message to actually receive the sent message.