Search code examples
c#telegramtelegram-apiwtelegramclient

how to send a large video and photo in telegram using the Telegram api


the problem is this, I'm trying to send videos and photos with one media group, but on the desktop and web versions it looks almost normal, and on the mobile version it sends two messages all the time, but if the video weighs less than 10 MB then everything is sent in one message, I used the TDLib(NuGet) and WTelegram libraries

here are examples of codes from different libraries

TDLib

private static async Task SendMediaGroup(long chatId, string photoPath, string videoPath)
{
    var inputMessages = new TdApi.InputMessageContent[]
    {
        new TdApi.InputMessageContent.InputMessagePhoto
        {
            Photo = new TdApi.InputFile.InputFileLocal { Path = photoPath },
        },
        new TdApi.InputMessageContent.InputMessageVideo
        {
            Video = new TdApi.InputFile.InputFileLocal { Path = videoPath },
        }
    };

    var result = await _client.ExecuteAsync(new TdApi.SendMessageAlbum
    {
        ChatId = chatId,
        InputMessageContents = inputMessages,
    });

}

WTelegram

  var inputMediaVideo = new InputMediaUploadedDocument
            {
                file = uploadedVideo,
                mime_type = "video/mp4",
                attributes = new[]
                {
                    new DocumentAttributeVideo
                    {
                        duration = 0,
                        w = 1280, 
                        h = 720  
                    }
                }
            };

            var inputMediaPhoto = new InputMediaUploadedPhoto
            {
                file = uploadedPhoto
            };
            
            var mMediaPhoto = client.Messages_UploadFile(inputPeet,inputMediaPhoto);
            var mMediaVideo = client.Messages_UploadFile(inputPeet,inputMediaVideo);

            var inputMediaList = new InputSingleMedia[]
            {
                new InputSingleMedia
                {
                    media = mMediaPhoto.ToInputMedia(),
                    message = caption,
                    random_id = Helpers.RandomLong()
                },
                new InputSingleMedia
                {
                    media = mMediaVideo.ToInputMedia(),
                    random_id = Helpers.RandomLong()
                }
            };

            var updates = await client.Messages_SendMultiMedia(inputPeer, inputMediaList);

Solution

  • I think photo & large videos can only be mixed in the same album if you provide a thumbnail photo for the video.

    The difference you witness with official clients is that they are able to construct (on send, or on receive of small videos after automatic download) the thumbnail for the video.