use std::time::Duration;
use botkit_core::BotError;
use botkit_core::action::{ChatAction, ChatActionFutureBounds, ChatActionSender};
use crate::client::TelegramClient;
#[derive(Clone)]
pub struct TelegramActionSender {
client: TelegramClient,
chat_id: i64,
thread_id: Option<i64>,
}
impl TelegramActionSender {
pub fn new(client: TelegramClient, chat_id: i64, thread_id: Option<i64>) -> Self {
Self {
client,
chat_id,
thread_id,
}
}
fn action_string(action: ChatAction) -> &'static str {
match action {
ChatAction::Typing => "typing",
ChatAction::UploadPhoto => "upload_photo",
ChatAction::RecordVideo => "record_video",
ChatAction::UploadVideo => "upload_video",
ChatAction::RecordVoice => "record_voice",
ChatAction::UploadVoice => "upload_voice",
ChatAction::UploadDocument => "upload_document",
ChatAction::ChooseSticker => "choose_sticker",
ChatAction::FindLocation => "find_location",
ChatAction::RecordVideoNote => "record_video_note",
ChatAction::UploadVideoNote => "upload_video_note",
}
}
}
impl ChatActionSender for TelegramActionSender {
fn send_action(
&self,
action: ChatAction,
) -> impl ChatActionFutureBounds<Output = Result<(), BotError>> + '_ {
async move {
self.client
.send_chat_action(self.chat_id, Self::action_string(action), self.thread_id)
.await
}
}
fn action_expiry(&self) -> Duration {
Duration::from_secs(5)
}
}