1use std::time::Duration;
2
3use botkit_core::BotError;
4use botkit_core::action::{ChatAction, ChatActionFutureBounds, ChatActionSender};
5use matrix_sdk::Room;
6
7#[derive(Clone)]
11pub struct MatrixActionSender {
12 room: Room,
13}
14
15impl MatrixActionSender {
16 pub fn new(room: Room) -> Self {
18 Self { room }
19 }
20}
21
22impl ChatActionSender for MatrixActionSender {
23 fn send_action(
24 &self,
25 action: ChatAction,
26 ) -> impl ChatActionFutureBounds<Output = Result<(), BotError>> + '_ {
27 async move {
28 if action == ChatAction::Typing {
30 self.room
31 .typing_notice(true)
32 .await
33 .map_err(|e| BotError::Api(e.to_string()))?;
34 }
35 Ok(())
37 }
38 }
39
40 fn action_expiry(&self) -> Duration {
41 Duration::from_secs(4)
44 }
45
46 fn clear_action(&self) -> impl ChatActionFutureBounds<Output = Result<(), BotError>> + '_ {
47 async move {
50 self.room
51 .typing_notice(false)
52 .await
53 .map_err(|e| BotError::Api(e.to_string()))
54 }
55 }
56}