1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#![warn(missing_docs)]
//! handle simple text message
use std::str;

use async_trait::async_trait;

use super::backend::MessageEndpoint;
use super::BackendMessage;
use crate::error::Error;
use crate::error::Result;
use crate::prelude::*;

/// SimpleTextEndpoint
#[derive(Clone, Debug, Default)]
pub struct TextEndpoint;

#[async_trait]
impl MessageEndpoint for TextEndpoint {
    async fn handle_message(
        &self,
        ctx: &MessagePayload<Message>,
        data: &BackendMessage,
    ) -> Result<Vec<MessageHandlerEvent>> {
        let text = str::from_utf8(&data.data).map_err(|_| Error::InvalidMessage)?;
        tracing::info!(
            "SimpleText, From: {}, Text: {}",
            ctx.relay.origin_sender(),
            text
        );
        Ok(vec![])
    }
}