Can send text message
This commit is contained in:
@@ -6,6 +6,7 @@ use futures_util::{StreamExt, stream};
|
|||||||
use matrix_sdk::Room;
|
use matrix_sdk::Room;
|
||||||
use matrix_sdk::deserialized_responses::{TimelineEvent, TimelineEventKind};
|
use matrix_sdk::deserialized_responses::{TimelineEvent, TimelineEventKind};
|
||||||
use matrix_sdk::room::MessagesOptions;
|
use matrix_sdk::room::MessagesOptions;
|
||||||
|
use matrix_sdk::ruma::events::room::message::RoomMessageEventContent;
|
||||||
use matrix_sdk::ruma::{MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedUserId, RoomId, UInt};
|
use matrix_sdk::ruma::{MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedUserId, RoomId, UInt};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::value::RawValue;
|
use serde_json::value::RawValue;
|
||||||
@@ -89,3 +90,24 @@ pub async fn get_for_room(
|
|||||||
Ok(HttpResponse::Ok()
|
Ok(HttpResponse::Ok()
|
||||||
.json(get_events(&room, query.limit.unwrap_or(500), query.from.as_deref()).await?))
|
.json(get_events(&room, query.limit.unwrap_or(500), query.from.as_deref()).await?))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct SendTextMessageRequest {
|
||||||
|
content: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn send_text_message(
|
||||||
|
client: MatrixClientExtractor,
|
||||||
|
path: web::Path<RoomIdInPath>,
|
||||||
|
) -> HttpResult {
|
||||||
|
let req = client.auth.decode_json_body::<SendTextMessageRequest>()?;
|
||||||
|
|
||||||
|
let Some(room) = client.client.client.get_room(&path.id) else {
|
||||||
|
return Ok(HttpResponse::NotFound().json("Room not found!"));
|
||||||
|
};
|
||||||
|
|
||||||
|
room.send(RoomMessageEventContent::text_plain(req.content))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(HttpResponse::Accepted().finish())
|
||||||
|
}
|
||||||
|
|||||||
@@ -169,6 +169,10 @@ async fn main() -> std::io::Result<()> {
|
|||||||
"/api/matrix/room/{id}/events",
|
"/api/matrix/room/{id}/events",
|
||||||
web::get().to(matrix_event_controller::get_for_room),
|
web::get().to(matrix_event_controller::get_for_room),
|
||||||
)
|
)
|
||||||
|
.route(
|
||||||
|
"/api/matrix/room/{id}/send_text_message",
|
||||||
|
web::post().to(matrix_event_controller::send_text_message),
|
||||||
|
)
|
||||||
// Matrix media controller
|
// Matrix media controller
|
||||||
.route(
|
.route(
|
||||||
"/api/matrix/media/{mxc}",
|
"/api/matrix/media/{mxc}",
|
||||||
|
|||||||
Reference in New Issue
Block a user