use std::time::Duration;
use botkit_core::BotError;
use botkit_core::action::{ChatAction, ChatActionFuture, ChatActionSender};
use matrix_sdk::Room;
#[derive(Clone)]
pub struct MatrixActionSender {
room: Room,
}
impl MatrixActionSender {
pub fn new(room: Room) -> Self {
Self { room }
}
}
impl ChatActionSender for MatrixActionSender {
fn send_action(&self, action: ChatAction) -> ChatActionFuture<'_> {
Box::pin(async move {
if action == ChatAction::Typing {
self.room
.typing_notice(true)
.await
.map_err(|e| BotError::Api(e.to_string()))?;
}
Ok(())
})
}
fn action_expiry(&self) -> Duration {
Duration::from_secs(4)
}
fn clone_boxed(&self) -> Box<dyn ChatActionSender> {
Box::new(self.clone())
}
}