Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

this lib is a joke #271

Open
VityaSchel opened this issue Oct 23, 2022 · 6 comments
Open

this lib is a joke #271

VityaSchel opened this issue Oct 23, 2022 · 6 comments

Comments

@VityaSchel
Copy link

image

and file references are expired and broken

@dieptang
Copy link

dieptang commented Nov 19, 2022

{ _: 'message', flags: 50816, post: true, id: 53375, to_id: { _: 'peerChannel', channel_id: 1325499115 }, date: 1668842287, message: '', media: { _: 'messageMediaPhoto', photo: { _: 'photo', flags: 0, id: '6325815975047443198', access_hash: '11021783537486444698', date: 1668842287, sizes: [Array] }, caption: 'Test message' }, entities: [], views: 83, edit_date: 1668842290 }

messageMediaPhoto seems don't have file references anymore. Anyone have any ideas?
How can we download the chat photos?

@VityaSchel
Copy link
Author

Btw if anyone has FILE_REFERENCE_EXPIREd error, you must pass thumb_size even if you don't want to download thumb

This function accepts sizes array as param, tries to find the best version of photo available and outputs string you need to pass as thumb_size:

export function findSizeType(sizes: object[]): string {
  return sizes.find(s => s['_'] === 'photoSizeProgressive')?.['type']
    ?? sizes.filter(s => s['_'] === 'photoSize').sort((a, b) => b['w']*b['h'] - a['w']*a['h'])?.['type']
    ?? sizes[0]['type']
}

@dieptang
Copy link

Btw if anyone has FILE_REFERENCE_EXPIREd error, you must pass thumb_size even if you don't want to download thumb

This function accepts sizes array as param, tries to find the best version of photo available and outputs string you need to pass as thumb_size:

export function findSizeType(sizes: object[]): string {
  return sizes.find(s => s['_'] === 'photoSizeProgressive')?.['type']
    ?? sizes.filter(s => s['_'] === 'photoSize').sort((a, b) => b['w']*b['h'] - a['w']*a['h'])?.['type']
    ?? sizes[0]['type']
}

I don't have the problem with photoSize. Currently I call

let history = await telegram('messages.getHistory', { peer: { _: 'inputPeerChannel', channel_id: chat.id, access_hash: chat.access_hash },, limit: 10 })

And I want to get the photo from media object. Something like this

if (messages[0].media && messages[0].media.caption) {
    if (messages[0].media.photo) {
      const file = await telegram('upload.getFile', {
        location: {
          _: 'inputPhotoFileLocation',
          id: messages[0].media.photo.id,
          dc_id: 5,
          access_hash: messages[0].media.photo.access_hash,
          file_reference: Buffer.from("some_binary_code_here", "hex"),
          //file_reference: buf, //tried
          //Buffer.from(message.media.photo.file_reference.toString('hex'), 'hex'),
          //[...message.media.photo.file_reference] and others
          thumb_size: 'y'
        },
        offset: 0,
        limit: 1024 * 1024
      });
      console.log('file', file);
    }

The error has appeared, due to missing file_reference.

@VityaSchel
Copy link
Author

Btw if anyone has FILE_REFERENCE_EXPIREd error, you must pass thumb_size even if you don't want to download thumb

This function accepts sizes array as param, tries to find the best version of photo available and outputs string you need to pass as thumb_size:

export function findSizeType(sizes: object[]): string {
  return sizes.find(s => s['_'] === 'photoSizeProgressive')?.['type']
    ?? sizes.filter(s => s['_'] === 'photoSize').sort((a, b) => b['w']*b['h'] - a['w']*a['h'])?.['type']
    ?? sizes[0]['type']
}

I don't have the problem with photoSize. Currently I call

let history = await telegram('messages.getHistory', { peer: { _: 'inputPeerChannel', channel_id: chat.id, access_hash: chat.access_hash },, limit: 10 })

And I want to get the photo from media object. Something like this

if (messages[0].media && messages[0].media.caption) {
    if (messages[0].media.photo) {
      const file = await telegram('upload.getFile', {
        location: {
          _: 'inputPhotoFileLocation',
          id: messages[0].media.photo.id,
          dc_id: 5,
          access_hash: messages[0].media.photo.access_hash,
          file_reference: Buffer.from("some_binary_code_here", "hex"),
          //file_reference: buf, //tried
          //Buffer.from(message.media.photo.file_reference.toString('hex'), 'hex'),
          //[...message.media.photo.file_reference] and others
          thumb_size: 'y'
        },
        offset: 0,
        limit: 1024 * 1024
      });
      console.log('file', file);
    }

The error has appeared, due to missing file_reference.

file reference is within that constructor, with id and access hash

@mayeaux
Copy link

mayeaux commented Dec 12, 2022

Fact check: true

@Lucienest
Copy link

bold promises, yet outdated!

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

4 participants