added propper formating
This commit is contained in:
parent
5acefb9a86
commit
6a68b8c311
27
src/lib.rs
27
src/lib.rs
|
@ -62,9 +62,21 @@ async fn message_handler(message: String) -> Result<()> {
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
let message = format!("New mail from {message_sender} with subject {}:\n```\n{}\n```", message_subject.trim(), message_body.trim());
|
||||
|
||||
send_message(&message).await?;
|
||||
let message = format!(
|
||||
"New mail from {message_sender} with subject {}:\n```\n{}\n```",
|
||||
message_subject.trim(),
|
||||
message_body.trim()
|
||||
);
|
||||
|
||||
let message_html = format!(
|
||||
"New mail from {message_sender} with subject {}:\n<code>\n{}\n</code>",
|
||||
message_subject.trim(),
|
||||
message_body.trim()
|
||||
);
|
||||
|
||||
let message_formatted = RoomMessageEventContent::text_html(message, message_html);
|
||||
|
||||
send_message(message_formatted).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -123,13 +135,11 @@ fn get_room_id() -> OwnedRoomId {
|
|||
room_id.as_ref().unwrap().clone()
|
||||
}
|
||||
|
||||
async fn send_message(message: &str) -> Result<()> {
|
||||
async fn send_message(content: RoomMessageEventContent) -> Result<()> {
|
||||
let client = get_client();
|
||||
let room_id = get_room_id();
|
||||
|
||||
let transaction_id = TransactionId::new();
|
||||
let text_content = TextMessageEventContent::plain(message);
|
||||
let content = RoomMessageEventContent::new(MessageType::Text(text_content));
|
||||
let message =
|
||||
send_message_event::v3::Request::new(room_id, transaction_id.to_owned(), &content)?;
|
||||
client.send_request(message).await?;
|
||||
|
@ -142,7 +152,10 @@ async fn on_start() -> Result<()> {
|
|||
create_client().await?;
|
||||
create_room_id().await?;
|
||||
|
||||
send_message("Started Mailing-List Matrix bridge").await?;
|
||||
send_message(RoomMessageEventContent::new(MessageType::Text(
|
||||
TextMessageEventContent::plain("Started Mailing-List Matrix bridge"),
|
||||
)))
|
||||
.await?;
|
||||
|
||||
println!("Started Matrix Plugin");
|
||||
|
||||
|
|
Loading…
Reference in a new issue