Skip to content
This repository has been archived by the owner on Dec 5, 2021. It is now read-only.

How to get Photo message in tlsharp? #1014

Open
theSadra opened this issue Feb 3, 2021 · 2 comments
Open

How to get Photo message in tlsharp? #1014

theSadra opened this issue Feb 3, 2021 · 2 comments

Comments

@theSadra
Copy link

theSadra commented Feb 3, 2021

Hi everyone,
I'm using Tl sharp to create a channel message receiver.
and I have a problem about receiving and saving Photo Files.
I checked out official tlsharp code sample to get document files bud I want to save photo files using client.get(); method.

this is the code sample for ducument files:

How can I use this code for getting and saving Photo files?

 
          var client = NewClient();

            await client.ConnectAsync();

            var result = await client.GetContactsAsync();

            var user = result.Users
                .OfType<TLUser>()
                .FirstOrDefault(x => x.Phone == NumberToSendMessage);

            var inputPeer = new TLInputPeerUser() { UserId = user.Id };
            var res = await client.SendRequestAsync<TLMessagesSlice>(new TLRequestGetHistory() { Peer = inputPeer });
            var document = res.Messages
                .OfType<TLMessage>()
                .Where(m => m.Media != null)
                .Select(m => m.Media)
                .OfType<TLMessageMediaDocument>()
                .Select(md => md.Document)
                .OfType<TLDocument>()
                .First();

            var resFile = await client.GetFile(
                new TLInputDocumentFileLocation()
                {
                    AccessHash = document.AccessHash,
                    Id = document.Id,
                    Version = document.Version
                },
                 document.Size);
@rocket-builder
Copy link

i find such code example, but it throw Flood Prevention exception
var mediaPhoto = message.Media as TLMessageMediaPhoto;

                    var photo = mediaPhoto.Photo as TLPhoto;

                    TLPhotoSize photoSize = photo.Sizes.ToList().OfType<TLPhotoSize>().Last();
                    TLFileLocation location = (TLFileLocation)photoSize.Location;

                    TLAbsInputFileLocation inputLocation = new TLInputFileLocation()
                    {
                        LocalId = location.LocalId,
                        Secret = location.Secret,
                        VolumeId = location.VolumeId
                    };
                    TLInputFileLocation inputFileLocation = inputLocation as TLInputFileLocation;

                    var photoFile = await _client.GetFile(inputFileLocation, 1024 * 512);
                    
                    does anyone know how to avoid this error?

@SmaGMan
Copy link

SmaGMan commented Nov 2, 2021

Check this thread #1019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants