wechat_agent_rs/
models.rs1use async_trait::async_trait;
2use serde::{Deserialize, Serialize};
3
4#[async_trait]
9pub trait Agent: Send + Sync {
10 async fn chat(&self, request: ChatRequest) -> crate::Result<ChatResponse>;
12}
13
14#[derive(Debug, Clone)]
16pub struct ChatRequest {
17 pub conversation_id: String,
19 pub text: String,
21 pub media: Option<IncomingMedia>,
23}
24
25#[derive(Debug, Clone, Default)]
27pub struct ChatResponse {
28 pub text: Option<String>,
30 pub media: Option<OutgoingMedia>,
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36pub struct IncomingMedia {
37 pub media_type: MediaType,
39 pub file_path: String,
41 pub mime_type: String,
43 pub file_name: Option<String>,
45}
46
47#[derive(Debug, Clone, Serialize, Deserialize)]
49pub struct OutgoingMedia {
50 pub media_type: OutgoingMediaType,
52 pub url: String,
55 pub file_name: Option<String>,
57}
58
59#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
61#[serde(rename_all = "snake_case")]
62pub enum MediaType {
63 Image,
65 Audio,
67 Video,
69 File,
71}
72
73#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
75#[serde(rename_all = "snake_case")]
76pub enum OutgoingMediaType {
77 Image,
79 Video,
81 File,
83}
84
85#[derive(Debug, Clone, Default)]
87pub struct LoginOptions {
88 pub base_url: Option<String>,
90}
91
92#[derive(Debug, Clone, Default)]
94pub struct StartOptions {
95 pub account_id: Option<String>,
97}
98
99#[cfg(test)]
100mod tests {
101 use super::*;
102
103 #[test]
104 fn test_chat_response_default() {
105 let resp = ChatResponse::default();
106 assert!(resp.text.is_none());
107 assert!(resp.media.is_none());
108 }
109
110 #[test]
111 fn test_media_type_serde() {
112 for variant in [
113 MediaType::Image,
114 MediaType::Audio,
115 MediaType::Video,
116 MediaType::File,
117 ] {
118 let json = serde_json::to_string(&variant).unwrap();
119 let deserialized: MediaType = serde_json::from_str(&json).unwrap();
120 assert_eq!(deserialized, variant);
121 }
122 }
123
124 #[test]
125 fn test_outgoing_media_type_serde() {
126 for variant in [
127 OutgoingMediaType::Image,
128 OutgoingMediaType::Video,
129 OutgoingMediaType::File,
130 ] {
131 let json = serde_json::to_string(&variant).unwrap();
132 let deserialized: OutgoingMediaType = serde_json::from_str(&json).unwrap();
133 assert_eq!(deserialized, variant);
134 }
135 }
136}