Osmium supports rich URL embeds with preview metadata for links shared in messages.
The MediaEmbed type represents a URL embed with optional preview data:
message MediaEmbed {
string url = 1 ;
optional string title = 2 ;
optional string description = 3 ;
// TODO: spoiler, etc
}
Page title or embed title
Page description or summary
To reference an embed when creating media, use MediaRefEmbed:
message MediaRefEmbed {
string url = 1 ;
}
Using Embeds in Messages
Embeds can be attached to messages through the MessageMedia type:
message MessageMedia {
oneof media {
MediaFile file = 1 ;
MediaEmbed embed = 2 ;
}
}
Example: Simple Embed
Send Message with Embed
Send Message with Embed
const message = await client . call ( 'messages.sendMessage' , {
chat_id: chatId ,
content: {
text: 'Check out this article!' ,
media: [
{
embed: {
url: 'https://example.com/article'
}
}
]
}
});
Get Embed Preview
While not currently in the proto file, the protocol will support fetching embed previews. The embed preview would populate the title and description fields:
Expected Usage
Future: Get Preview
Future: Get Preview
// This method is referenced in comments but not yet implemented
const preview = await client . call ( 'media.getEmbedPreview' , {
url: 'https://example.com/article'
});
// preview would contain:
// {
// url: 'https://example.com/article',
// title: 'Article Title',
// description: 'Article summary...',
// thumbnail: fileRef // optional
// }
Embed previews are typically generated from:
< meta property = "og:title" content = "Page Title" />
< meta property = "og:description" content = "Page description" />
< meta property = "og:image" content = "https://example.com/image.jpg" />
< meta name = "twitter:title" content = "Page Title" />
< meta name = "twitter:description" content = "Page description" />
< meta name = "twitter:image" content = "https://example.com/image.jpg" />
Standard HTML
< title > Page Title </ title >
< meta name = "description" content = "Page description" />
The MediaRef type supports both uploaded files and embeds:
message MediaRef {
oneof ref {
MediaRefUploadedFile uploaded = 1 ;
MediaRefEmbed embed = 2 ;
}
}
This allows you to attach either files or URL embeds to messages:
File vs Embed
File vs Embed
// File attachment
const fileMedia = {
uploaded: {
file: uploadedFileRef ,
filename: 'image.jpg' ,
mimetype: 'image/jpeg' ,
metadata: { image: { width: 800 , height: 600 } }
}
};
// URL embed
const embedMedia = {
embed: {
url: 'https://example.com/page'
}
};
Future Features
The proto comments indicate planned features:
Spoiler support : Mark embeds as spoilers requiring click to reveal
Thumbnail images : Embed preview images
Rich metadata : Additional fields for video embeds, article metadata, etc.
Embed customization : Control how embeds are displayed
Use Cases
Link Sharing
Share URLs with automatic preview generation:
// User pastes link, client detects and creates embed
const url = detectUrlInMessage ( text );
if ( url ) {
const preview = await getEmbedPreview ( url );
attachEmbed ( preview );
}
Rich Articles
Display article previews with title and description:
const embed = {
url: 'https://blog.example.com/post' ,
title: 'How to Build Chat Apps' ,
description: 'A comprehensive guide to building modern chat applications...'
};
Video Links
Embed video URLs with metadata:
const embed = {
url: 'https://youtube.com/watch?v=...' ,
title: 'Video Title' ,
description: 'Video description'
};