Class: MediaInfo

Represents media metadata extracted from a V2 file message. Provides convenient getters for type detection, file size formatting, and display.

Source: src/Types/Message.js

Constructor

new MediaInfo(raw)
constructor(raw: object)
Creates a MediaInfo from a raw V2 message with type: "file". Prefer using the static MediaInfo.from(msg) factory method.
raw
object — Raw V2 message object.

Static Methods

MediaInfo.from(msg) static
static from(msg: object): MediaInfo | null
Create a MediaInfo from a raw V2 message, or return null if the message is not a file message. This is the recommended way to create MediaInfo instances.
const { MediaInfo } = require('arattix');

const messages = await bot.fetchMessages(chatId);
for (const msg of messages) {
  const media = MediaInfo.from(msg);
  if (media) {
    console.log(media.toString());
    // "🖼️ photo.jpg (image/jpeg, 190.7KB)"
  }
}

Properties

PropertyTypeDescription
fileIdstring | nullFile ID for download
fileNamestringOriginal file name
mimeTypestringMIME type (e.g. "image/jpeg")
sizenumberFile size in bytes
widthnumberImage/video width in pixels
heightnumberImage/video height in pixels
thumbnailobject | nullThumbnail data (height, width, blur_data)
rawobjectThe original raw V2 message

Getters

isImage getter
get isImage(): boolean
True if MIME type starts with image/.
isAudio getter
get isAudio(): boolean
True if MIME type starts with audio/.
isVideo getter
get isVideo(): boolean
True if MIME type starts with video/.
isDocument getter
get isDocument(): boolean
True if not image, audio, or video.
sizeKB getter
get sizeKB(): string
File size in KB (1 decimal place).
sizeMB getter
get sizeMB(): string
File size in MB (2 decimal places).
typeIcon getter
get typeIcon(): string
Returns an emoji icon: 🖼️ image, 🎵 audio, 🎬 video, 📄 document.

Methods

toString() method
toString(): string
Returns a human-readable string like "🖼️ photo.jpg (image/jpeg, 190.7KB)".

V2 File Message Format

This is the raw structure that MediaInfo parses from the V2 API:

{
  "type": "file",
  "content": {
    "thumbnail": {
      "height": "195",
      "width": "400",
      "blur_data": "/9j/..."
    },
    "file": {
      "name": "photo.jpg",
      "type": "image/jpeg",
      "dimensions": {
        "height": 625,
        "tnheight": 195,
        "size": 195287,
        "tnwidth": 400,
        "width": 1280
      },
      "id": "i5b22..."
    }
  }
}

Complete Example

const { ArattixBot, Bot, MediaInfo } = require('arattix');

async function main() {
  const arattix = new ArattixBot();
  const bot = await arattix.loginWithQr();
  await bot.setupCsrf();

  const messages = await bot.fetchMessages(chatId, { limit: 50 });

  for (const msg of messages) {
    const media = MediaInfo.from(msg);
    if (media) {
      console.log(`${media.typeIcon} ${media.fileName}`);
      console.log(`   MIME: ${media.mimeType}`);
      console.log(`   Size: ${media.sizeKB} KB`);
      console.log(`   Dimensions: ${media.width}x${media.height}`);

      // Download
      const { data } = await bot.downloadMedia(media.fileId, chatId);
      fs.writeFileSync(`./downloads/${media.fileName}`, data);

      // Forward to another chat
      await bot.sender.sendBuffer(data, media.fileName, {
        chatId: otherChatId,
        caption: `Forwarded: ${media.fileName}`
      });
    }
  }
}

main();