Files
baibot-withmcp/src/controller/reaction/mod.rs

51 lines
1.3 KiB
Rust
Raw Normal View History

2024-09-12 13:44:06 +03:00
use std::ops::Deref;
use mxlink::MatrixLink;
use crate::{
2025-02-27 07:46:16 +02:00
Bot,
2024-09-12 13:44:06 +03:00
agent::AgentPurpose,
entity::{MessageContext, MessagePayload},
};
mod text_to_speech;
pub async fn handle(
bot: &Bot,
matrix_link: MatrixLink,
message_context: &MessageContext,
) -> anyhow::Result<()> {
match &message_context.payload() {
MessagePayload::Reaction {
key,
reacted_to_event_payload,
reacted_to_event_id,
reacted_to_event_sender_id,
} => {
if key == AgentPurpose::TextToSpeech.emoji() {
if let MessagePayload::Text(text_content) = reacted_to_event_payload.deref() {
return text_to_speech::handle(
bot,
matrix_link,
message_context,
reacted_to_event_id,
reacted_to_event_sender_id,
text_content,
)
.await;
}
tracing::debug!("Ignoring text-to-speech reaction to non-text message");
return Ok(());
}
tracing::debug!("Ignoring unknown reaction");
Ok(())
}
_ => Err(anyhow::anyhow!(
"Reaction controller called with a non-reaction message"
)),
}
}