Expand description
§telegram-rich
Toolkit for Telegram Bot API rich messages (sendRichMessage, Bot API 10.2+,
types up to date with 10.4).
html(featurehtml, on by default): turns arbitrary, messy web HTML (RSS items, articles, newsletters) into the HTML subset that Telegram rich messages accept, resolving relative URLs, lifting images out of paragraphs, dropping scripts and tracking pixels, and detecting layout tables.Document: an intermediate representation that you can also build by hand, measure against the officialLimits(32 768 characters, 500 blocks, 16 nesting levels, 50 media, 20 table columns), truncate at block boundaries withDocument::fit, and render withDocument::to_html.types: serde types forInputRichMessage, everyInputRichBlock,RichTextentity andRichMessageButton, for callers who prefer the explicitblocksrepresentation.
The crate performs no network I/O and does not depend on any Telegram client;
serialize types::InputRichMessage into the rich_message parameter with
the HTTP client of your choice.
use telegram_rich::{Block, FitOptions};
use telegram_rich::html::{normalize, ParseOptions};
let fit = FitOptions {
tail: vec![Block::link_button("Read original", "https://example.com/post/1")],
truncation_notice: vec![Block::paragraph("The article was truncated.")],
..FitOptions::default()
};
let msg = normalize("<p>Hello <b>world</b></p>", &ParseOptions::default(), &fit)
.into_input_rich_message();
let json = serde_json::to_string(&msg).unwrap();
assert!(json.starts_with(r#"{"html":"<p>Hello <b>world</b></p><tg-button-row>"#));Re-exports§
pub use document::Align;pub use document::Block;pub use document::ButtonStyle;pub use document::Document;pub use document::FitOptions;pub use document::Inline;pub use document::ListItem;pub use document::Media;pub use document::MediaKind;pub use document::Table;pub use document::TableCell;pub use document::UrlButton;pub use document::VAlign;
Modules§
- document
- Intermediate representation of a Telegram rich message document.
- html
html - Normalizing arbitrary web HTML into Telegram Rich HTML.
- types
- Serde types for outgoing Telegram rich messages (Bot API 10.4).