use serde::{Deserialize, Serialize};
use crate::file::{Animation, Audio, PhotoSize, Video, Voice};
use crate::user::User;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RichText {
Plain(String),
Array(Vec<RichText>),
Bold(Box<RichTextBold>),
Italic(Box<RichTextItalic>),
Underline(Box<RichTextUnderline>),
Strikethrough(Box<RichTextStrikethrough>),
Spoiler(Box<RichTextSpoiler>),
DateTime(Box<RichTextDateTime>),
TextMention(Box<RichTextTextMention>),
Subscript(Box<RichTextSubscript>),
Superscript(Box<RichTextSuperscript>),
Marked(Box<RichTextMarked>),
Code(Box<RichTextCode>),
CustomEmoji(Box<RichTextCustomEmoji>),
MathematicalExpression(Box<RichTextMathematicalExpression>),
Url(Box<RichTextUrl>),
EmailAddress(Box<RichTextEmailAddress>),
PhoneNumber(Box<RichTextPhoneNumber>),
BankCardNumber(Box<RichTextBankCardNumber>),
Mention(Box<RichTextMention>),
Hashtag(Box<RichTextHashtag>),
Cashtag(Box<RichTextCashtag>),
BotCommand(Box<RichTextBotCommand>),
Anchor(Box<RichTextAnchor>),
AnchorLink(Box<RichTextAnchorLink>),
Footnote(Box<RichTextFootnote>),
Reference(Box<RichTextReference>),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichTextBold {
#[serde(rename = "type")]
pub kind: String,
pub text: RichText,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichTextItalic {
#[serde(rename = "type")]
pub kind: String,
pub text: RichText,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichTextUnderline {
#[serde(rename = "type")]
pub kind: String,
pub text: RichText,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichTextStrikethrough {
#[serde(rename = "type")]
pub kind: String,
pub text: RichText,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichTextSpoiler {
#[serde(rename = "type")]
pub kind: String,
pub text: RichText,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichTextDateTime {
#[serde(rename = "type")]
pub kind: String,
pub text: RichText,
pub unix_time: i64,
pub date_time_format: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichTextTextMention {
#[serde(rename = "type")]
pub kind: String,
pub text: RichText,
pub user: User,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichTextSubscript {
#[serde(rename = "type")]
pub kind: String,
pub text: RichText,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichTextSuperscript {
#[serde(rename = "type")]
pub kind: String,
pub text: RichText,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichTextMarked {
#[serde(rename = "type")]
pub kind: String,
pub text: RichText,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichTextCode {
#[serde(rename = "type")]
pub kind: String,
pub text: RichText,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichTextCustomEmoji {
#[serde(rename = "type")]
pub kind: String,
pub custom_emoji_id: String,
pub alternative_text: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichTextMathematicalExpression {
#[serde(rename = "type")]
pub kind: String,
pub expression: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichTextUrl {
#[serde(rename = "type")]
pub kind: String,
pub text: RichText,
pub url: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichTextEmailAddress {
#[serde(rename = "type")]
pub kind: String,
pub text: RichText,
pub email_address: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichTextPhoneNumber {
#[serde(rename = "type")]
pub kind: String,
pub text: RichText,
pub phone_number: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichTextBankCardNumber {
#[serde(rename = "type")]
pub kind: String,
pub text: RichText,
pub bank_card_number: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichTextMention {
#[serde(rename = "type")]
pub kind: String,
pub text: RichText,
pub username: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichTextHashtag {
#[serde(rename = "type")]
pub kind: String,
pub text: RichText,
pub hashtag: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichTextCashtag {
#[serde(rename = "type")]
pub kind: String,
pub text: RichText,
pub cashtag: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichTextBotCommand {
#[serde(rename = "type")]
pub kind: String,
pub text: RichText,
pub bot_command: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichTextAnchor {
#[serde(rename = "type")]
pub kind: String,
pub name: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichTextAnchorLink {
#[serde(rename = "type")]
pub kind: String,
pub text: RichText,
pub anchor_name: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichTextFootnote {
#[serde(rename = "type")]
pub kind: String,
pub text: RichText,
pub name: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichTextReference {
#[serde(rename = "type")]
pub kind: String,
pub text: RichText,
pub footnote_name: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichBlockCaption {
pub text: RichText,
#[serde(skip_serializing_if = "Option::is_none")]
pub credit: Option<RichText>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichBlockTableCell {
#[serde(skip_serializing_if = "Option::is_none")]
pub text: Option<RichText>,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_header: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub colspan: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub rowspan: Option<u32>,
pub align: String,
pub valign: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichBlockListItem {
pub label: String,
pub blocks: Vec<RichBlock>,
#[serde(skip_serializing_if = "Option::is_none")]
pub has_checkbox: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_checked: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub value: Option<i64>,
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
pub kind: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum RichBlock {
Paragraph(RichBlockParagraph),
#[serde(rename = "heading")]
SectionHeading(RichBlockSectionHeading),
Pre(RichBlockPreformatted),
Footer(RichBlockFooter),
Divider(RichBlockDivider),
MathematicalExpression(RichBlockMathematicalExpression),
Anchor(RichBlockAnchor),
List(RichBlockList),
Blockquote(RichBlockBlockQuotation),
Pullquote(RichBlockPullQuotation),
Collage(RichBlockCollage),
Slideshow(RichBlockSlideshow),
Table(RichBlockTable),
Details(RichBlockDetails),
Map(RichBlockMap),
Animation(RichBlockAnimation),
Audio(RichBlockAudio),
Photo(RichBlockPhoto),
Video(RichBlockVideo),
VoiceNote(RichBlockVoiceNote),
Thinking(RichBlockThinking),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichBlockParagraph {
pub text: RichText,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichBlockSectionHeading {
pub text: RichText,
pub size: u8,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichBlockPreformatted {
pub text: RichText,
#[serde(skip_serializing_if = "Option::is_none")]
pub language: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichBlockFooter {
pub text: RichText,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichBlockDivider {}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichBlockMathematicalExpression {
pub expression: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichBlockAnchor {
pub name: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichBlockList {
pub items: Vec<RichBlockListItem>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichBlockBlockQuotation {
pub blocks: Vec<RichBlock>,
#[serde(skip_serializing_if = "Option::is_none")]
pub credit: Option<RichText>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichBlockPullQuotation {
pub text: RichText,
#[serde(skip_serializing_if = "Option::is_none")]
pub credit: Option<RichText>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichBlockCollage {
pub blocks: Vec<RichBlock>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caption: Option<RichBlockCaption>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichBlockSlideshow {
pub blocks: Vec<RichBlock>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caption: Option<RichBlockCaption>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichBlockTable {
pub cells: Vec<Vec<RichBlockTableCell>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_bordered: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_striped: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caption: Option<RichText>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichBlockDetails {
pub summary: RichText,
pub blocks: Vec<RichBlock>,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_open: Option<bool>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichBlockMap {
pub latitude: f64,
pub longitude: f64,
pub zoom: u8,
pub width: u32,
pub height: u32,
#[serde(skip_serializing_if = "Option::is_none")]
pub caption: Option<RichBlockCaption>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichBlockAnimation {
pub animation: Animation,
#[serde(skip_serializing_if = "Option::is_none")]
pub need_autoplay: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub has_spoiler: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caption: Option<RichBlockCaption>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichBlockAudio {
pub audio: Audio,
#[serde(skip_serializing_if = "Option::is_none")]
pub caption: Option<RichBlockCaption>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichBlockPhoto {
pub photo: Vec<PhotoSize>,
#[serde(skip_serializing_if = "Option::is_none")]
pub has_spoiler: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caption: Option<RichBlockCaption>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichBlockVideo {
pub video: Video,
#[serde(skip_serializing_if = "Option::is_none")]
pub need_autoplay: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_looped: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub has_spoiler: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caption: Option<RichBlockCaption>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichBlockVoiceNote {
pub voice_note: Voice,
#[serde(skip_serializing_if = "Option::is_none")]
pub caption: Option<RichBlockCaption>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichBlockThinking {
pub text: RichText,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RichMessage {
pub blocks: Vec<RichBlock>,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_rtl: Option<bool>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InputRichMessage {
#[serde(skip_serializing_if = "Option::is_none")]
pub html: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub markdown: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_rtl: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub skip_entity_detection: Option<bool>,
}
impl InputRichMessage {
pub fn from_html(html: impl Into<String>) -> Self {
Self {
html: Some(html.into()),
markdown: None,
is_rtl: None,
skip_entity_detection: None,
}
}
pub fn from_markdown(markdown: impl Into<String>) -> Self {
Self {
html: None,
markdown: Some(markdown.into()),
is_rtl: None,
skip_entity_detection: None,
}
}
#[must_use]
pub fn rtl(mut self, v: bool) -> Self {
self.is_rtl = Some(v);
self
}
#[must_use]
pub fn skip_entity_detection(mut self, v: bool) -> Self {
self.skip_entity_detection = Some(v);
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InputRichMessageContent {
pub rich_message: InputRichMessage,
}