Attachments
VK-IO provides specialized attachment classes for all VK media types. All attachment classes extend the baseAttachment class.
Base Attachment Class
The base class for all attachments.Properties
The attachment type (e.g., ‘photo’, ‘video’, ‘audio’, ‘doc’)
The attachment ID
The owner ID (user or community)
Access key for private attachments
Whether the attachment has full data loaded
Whether the attachment can be attached via string representation
Methods
fromString(attachment, api)
Parses an attachment from a string.Attachment string (e.g., “photo123_456” or “photo123_456_abc”)
API instance
Attachment
equals(attachment)
Checks if this attachment is equivalent to another.Attachment to compare with
boolean
toString()
Returns the string representation for VK API.string
toJSON()
Returns JSON representation of the attachment. Returns:object
PhotoAttachment
Represents a photo attachment.Properties
ID of the user who uploaded the photo
Album ID containing the photo
Photo caption
Upload timestamp (Unix time)
Photo width in pixels
Photo height in pixels
URL of small photo (130 or 75px)
URL of medium photo (807, 604px or less)
URL of large photo (2560, 1280px or less)
Array of all available photo sizes
Methods
loadAttachmentPayload()
Loads full photo data from VK API if not already loaded.Promise<void>
getSizes(sizeTypes)
Returns photo sizes of specified types.Array of size type identifiers (e.g., [‘w’, ‘z’, ‘y’])
IPhotoSize[]
IPhotoSize
Usage Example
VideoAttachment
Represents a video attachment.Properties
Video title
Video description
Video duration in seconds
Upload timestamp
Added to user’s videos timestamp
Number of views
Number of comments
URL to the video player page
Platform name for external videos
Whether the video is repeatable
Whether user can add the video
Whether user can edit the video
Whether the video is being processed
Whether the video is a live broadcast
Whether the video is an upcoming broadcast
Whether the video is bookmarked
Methods
loadAttachmentPayload()
Loads full video data from VK API. Returns:Promise<void>
AudioAttachment
Represents an audio attachment.Properties
Track title
Artist name
Track duration in seconds
Audio file URL
Lyrics identifier
Album identifier
Genre identifier
Upload timestamp
Whether the audio is high quality
Methods
loadAttachmentPayload()
Loads full audio data from VK API. Returns:Promise<void>
DocumentAttachment
Represents a document attachment.Properties
Document title
File size in bytes
File extension
Download URL
Upload timestamp
Document type: 1=text, 2=archive, 3=gif, 4=image, 5=audio, 6=video, 7=e-book, 8=unknown
Preview data (for images, graffiti, voice messages)
Whether the document is a text file
Whether the document is an archive
Whether the document is a GIF
Whether the document is an image
Whether the document is a graffiti
Whether the document is an audio file
Whether the document is a voice message
Whether the document is a video file
Whether the document is an e-book
Methods
loadAttachmentPayload()
Loads full document data from VK API. Returns:Promise<void>
hasPreviewProperty(name)
Checks if the document has a specific preview property.Preview property name
boolean
WallAttachment
Represents a wall post attachment.Properties
Post text
Author ID
Post creation timestamp
Post type
Number of views
Number of likes
Number of reposts
Number of comments
Attachments in the post
Repost history
ID of the user who signed the post
Whether the post is pinned
Whether the post is bookmarked
Whether the post has comments
Whether the post contains ads
Whether the current user liked the post
Whether the user can edit the post
Whether the user can delete the post
Methods
loadAttachmentPayload()
Loads full post data from VK API. Returns:Promise<void>
PollAttachment
Represents a poll attachment.Properties
Poll question
Poll creator ID
Poll creation timestamp
Poll end timestamp (0 if unlimited)
Total number of votes
IDs of answers selected by current user
Array of poll answers
IDs of up to 3 friends who voted
Poll background configuration
Poll photo
Whether the poll is anonymous
Whether multiple answers are allowed
Whether the poll is closed
Whether the poll is attached to a discussion
Whether the user can edit the poll
Whether the user can vote
Methods
loadAttachmentPayload()
Loads full poll data from VK API. Returns:Promise<void>
StickerAttachment
Represents a sticker attachment.Properties
Sticker ID
Sticker pack ID
Array of sticker images
Array of sticker images with backgrounds
IStickerImage
Other Attachment Types
VK-IO also provides these attachment classes:- AudioMessageAttachment - Voice messages
- GiftAttachment - Gifts
- GraffitiAttachment - Graffiti images
- LinkAttachment - Shared links
- MarketAttachment - Market items
- MarketAlbumAttachment - Market collections
- StoryAttachment - Stories
- WallReplyAttachment - Wall comment replies
Helper Functions
transformAttachments(attachments, api)
Transforms raw VK API attachment data into typed attachment instances.Raw attachment data from VK API
API instance
(Attachment | ExternalAttachment)[]