alik0211 / mtproto-core

Telegram API JS (MTProto) client library for Node.js and browser
https://mtproto-core.js.org
GNU General Public License v3.0
625 stars 111 forks source link

this lib is a joke #271

Open VityaSchel opened 1 year ago

VityaSchel commented 1 year ago

image

and file references are expired and broken

dieptang commented 1 year ago

{ _: '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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

Fact check: true

Lucienest commented 1 year ago

bold promises, yet outdated!