egramtel/tdsharp

GetMessage Content Caption

KomodoCrypto opened this issue · 2 comments

I am properly getting a list of the messages of a chat as,

var chatMessages = await _client.ExecuteAsync(new TdApi.GetChatHistory
            {
                ChatId = chatId,
                Limit = limit,
                FromMessageId = fromMessageId,
            });

I can see the desired message content in intellisense as Message.Content.Caption.Text, however, Caption is not accessible. Message type is messagePhoto.

How to get the text caption of a message??

I already tried to get the message from its Id, but throws an exception.

var message = _client.Execute(new TdApi.GetMessage
            {
                ChatId = chatId,
                MessageId = messageId, 
            });

Try casting the message content to MessagePhoto, for example:

var chatMessages = await _client.ExecuteAsync(new TdApi.GetChatHistory
{
    ChatId = chatId,
    Limit = limit,
    FromMessageId = fromMessageId,
});
var message = chatMessages.Messages_?.FirstOrDefault();
var content = message?.Content as TdApi.MessageContent.MessagePhoto;
var caption = content?.Caption;

Would that work?

yes, it worked!! Thank you for the quick support.