use serde::{Deserialize, Serialize};
use std::sync::Arc;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum ChannelType {
Http,
WebSocket,
Cli,
Telegram,
Discord,
Slack,
}
impl std::fmt::Display for ChannelType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ChannelType::Http => write!(f, "http"),
ChannelType::WebSocket => write!(f, "websocket"),
ChannelType::Cli => write!(f, "cli"),
ChannelType::Telegram => write!(f, "telegram"),
ChannelType::Discord => write!(f, "discord"),
ChannelType::Slack => write!(f, "slack"),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InboundMessage {
pub text: Arc<str>,
pub session_id: Arc<str>,
pub channel: ChannelType,
pub user_id: Option<Arc<str>>,
pub metadata: Option<serde_json::Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OutboundMessage {
pub text: Arc<str>,
pub status: MessageStatus,
pub error: Option<Arc<str>>,
pub metadata: Option<serde_json::Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum MessageStatus {
Ok,
Error,
Pending,
}
impl OutboundMessage {
pub fn ok(text: impl Into<Arc<str>>) -> Self {
Self {
text: text.into(),
status: MessageStatus::Ok,
error: None,
metadata: None,
}
}
pub fn error(message: impl Into<Arc<str>>) -> Self {
Self {
text: Arc::from(""),
status: MessageStatus::Error,
error: Some(message.into()),
metadata: None,
}
}
}
#[derive(Debug, Clone)]
pub enum ChannelEvent {
Connect { session_id: Arc<str> },
Message { message: InboundMessage },
Close { session_id: Arc<str> },
}
#[derive(Debug, Serialize)]
pub struct HealthResponse {
pub status: Arc<str>,
pub version: Arc<str>,
pub uptime_secs: u64,
}
impl Default for HealthResponse {
fn default() -> Self {
Self {
status: Arc::from("ok"),
version: Arc::from(env!("CARGO_PKG_VERSION")),
uptime_secs: 0,
}
}
}