mirror of
https://github.com/FliegendeWurst/telegram_notes_bot.git
synced 2024-11-25 04:04:56 +00:00
Send json data about events to Trilium
This commit is contained in:
parent
ec00812887
commit
4c2d78c6bb
@ -14,6 +14,8 @@ pub struct Event {
|
|||||||
pub uid: String,
|
pub uid: String,
|
||||||
pub summary: String,
|
pub summary: String,
|
||||||
pub description: String,
|
pub description: String,
|
||||||
|
/// X-ALT-DESC;FMTTYPE=text/html
|
||||||
|
pub description_html: Option<String>,
|
||||||
pub start: NaiveDateTime,
|
pub start: NaiveDateTime,
|
||||||
pub end: NaiveDateTime,
|
pub end: NaiveDateTime,
|
||||||
pub duration: Option<Duration>,
|
pub duration: Option<Duration>,
|
||||||
@ -43,6 +45,7 @@ fn process_event(event: IcalEvent) -> Result<Event, Error> {
|
|||||||
let mut uid = None;
|
let mut uid = None;
|
||||||
let mut summary = None;
|
let mut summary = None;
|
||||||
let mut description = None;
|
let mut description = None;
|
||||||
|
let mut description_html = None;
|
||||||
let mut start = None;
|
let mut start = None;
|
||||||
let mut end = None;
|
let mut end = None;
|
||||||
let mut duration = None;
|
let mut duration = None;
|
||||||
@ -59,6 +62,14 @@ fn process_event(event: IcalEvent) -> Result<Event, Error> {
|
|||||||
"DTEND" => end = Some(process_dt(&value)?),
|
"DTEND" => end = Some(process_dt(&value)?),
|
||||||
"DURATION" => duration = Some(process_duration(&value)?),
|
"DURATION" => duration = Some(process_duration(&value)?),
|
||||||
"RRULE" => { /* TODO: periodic */ },
|
"RRULE" => { /* TODO: periodic */ },
|
||||||
|
"X-ALT-DESC" => {
|
||||||
|
if prop.params.as_ref()
|
||||||
|
.map(|x| x.iter()
|
||||||
|
.any(|(key, values)| key == "FMTTYPE" && values.first().map(|x| &**x) == Some("text/html"))
|
||||||
|
).unwrap_or(false) {
|
||||||
|
description_html = Some(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -69,6 +80,7 @@ fn process_event(event: IcalEvent) -> Result<Event, Error> {
|
|||||||
uid: uid.unwrap_or_default(),
|
uid: uid.unwrap_or_default(),
|
||||||
summary: summary.unwrap_or_default(),
|
summary: summary.unwrap_or_default(),
|
||||||
description: description.unwrap_or_default(),
|
description: description.unwrap_or_default(),
|
||||||
|
description_html,
|
||||||
start: start,
|
start: start,
|
||||||
end: end,
|
end: end,
|
||||||
duration,
|
duration,
|
||||||
|
27
src/main.rs
27
src/main.rs
@ -130,7 +130,6 @@ async fn process_one(update: Update, reminder_msg: &mut MessageId, reminder_text
|
|||||||
}
|
}
|
||||||
} else if let MessageKind::Document { ref data, ref caption, .. } = message.kind {
|
} else if let MessageKind::Document { ref data, ref caption, .. } = message.kind {
|
||||||
let document = data;
|
let document = data;
|
||||||
send_message(format!("Document {:?} {:?} {:?} {:?}", caption, document.file_id, document.file_name, document.mime_type)).await?;
|
|
||||||
let get_file = GetFile::new(&document);
|
let get_file = GetFile::new(&document);
|
||||||
let file = API.send(get_file).await?;
|
let file = API.send(get_file).await?;
|
||||||
let url = file.get_url(&TELEGRAM_BOT_TOKEN).ok_or_else(|| error("url is none"))?;
|
let url = file.get_url(&TELEGRAM_BOT_TOKEN).ok_or_else(|| error("url is none"))?;
|
||||||
@ -140,11 +139,29 @@ async fn process_one(update: Update, reminder_msg: &mut MessageId, reminder_text
|
|||||||
(mime::TEXT, x) if x == "calendar" => {
|
(mime::TEXT, x) if x == "calendar" => {
|
||||||
let text = String::from_utf8_lossy(&data);
|
let text = String::from_utf8_lossy(&data);
|
||||||
let text = text.replace("\n<", "<"); // newlines in HTML values
|
let text = text.replace("\n<", "<"); // newlines in HTML values
|
||||||
send_message(&text).await?;
|
//send_message(&text).await?;
|
||||||
let calendar = ical_parsing::parse_calendar(&text)?;
|
let calendar = ical_parsing::parse_calendar(&text)?;
|
||||||
send_message(format!("{:?}", calendar)).await?;
|
//send_message(format!("{:?}", calendar)).await?;
|
||||||
|
if calendar.events.len() != 1 {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
if CLIENT.get("http://localhost:9001/custom/new_event").form(&json!({
|
||||||
|
"name": calendar.events[0].summary,
|
||||||
|
"summary": calendar.events[0].description_html.as_deref().unwrap_or(&calendar.events[0].description),
|
||||||
|
"fileName": document.file_name,
|
||||||
|
"fileData": text,
|
||||||
|
"location": calendar.events[0].location,
|
||||||
|
"startTime": calendar.events[0].start.format("%Y-%m-%dT%H:%M:%S").to_string(),
|
||||||
|
"endTime": calendar.events[0].end.format("%Y-%m-%dT%H:%M:%S").to_string(),
|
||||||
|
})).send().await?.status().is_success() {
|
||||||
|
send_message("Event saved :-)").await?;
|
||||||
|
} else {
|
||||||
|
send_message("error saving event").await?;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
_ => {}
|
_ => {
|
||||||
|
send_message(format!("Document {:?} {:?} {:?} {:?}", caption, document.file_id, document.file_name, document.mime_type)).await?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if let UpdateKind::CallbackQuery(cb) = update.kind {
|
} else if let UpdateKind::CallbackQuery(cb) = update.kind {
|
||||||
@ -178,7 +195,7 @@ async fn process_one(update: Update, reminder_msg: &mut MessageId, reminder_text
|
|||||||
CLIENT.get("http://localhost:9001/custom/new_reminder").form(&json!({
|
CLIENT.get("http://localhost:9001/custom/new_reminder").form(&json!({
|
||||||
"time": remind_time.to_rfc3339(),
|
"time": remind_time.to_rfc3339(),
|
||||||
"task": *reminder_text
|
"task": *reminder_text
|
||||||
})).send().await?.text().await?;
|
})).send().await?;
|
||||||
API.send(SendMessage::new(*OWNER, "Reminder saved :-)")).await?;
|
API.send(SendMessage::new(*OWNER, "Reminder saved :-)")).await?;
|
||||||
*reminder_text = String::new();
|
*reminder_text = String::new();
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user