open_lark/service/im/v2/groups_bots/
mod.rs1use reqwest::Method;
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4use std::collections::HashMap;
5
6use crate::{
7 core::{
8 api_req::ApiRequest,
9 api_resp::{ApiResponseTrait, BaseResponse, ResponseFormat},
10 config::Config,
11 constants::AccessTokenType,
12 http::Transport,
13 req_option::RequestOption,
14 SDKResult,
15 },
16 service::im::v2::models::{ButtonInfo, UserIdType},
17};
18
19pub struct GroupsBotsService {
21 pub config: Config,
22}
23
24#[derive(Debug, Serialize, Deserialize)]
26pub struct BotTimeSentiveRequest {
27 pub receive_id: String,
29 pub content: Value,
31 pub msg_type: String,
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
37pub struct BotTimeSentiveResponse {
38 pub message_id: String,
40 pub send_time: String,
42}
43
44impl ApiResponseTrait for BotTimeSentiveResponse {
45 fn data_format() -> ResponseFormat {
46 ResponseFormat::Data
47 }
48}
49
50#[derive(Debug, Serialize, Deserialize)]
52pub struct UpdateFeedCardButtonRequest {
53 pub buttons: Vec<ButtonInfo>,
55 #[serde(skip_serializing_if = "Option::is_none")]
57 pub reason: Option<String>,
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
62pub struct UpdateFeedCardButtonResponse {
63 pub message_id: String,
65 pub update_time: String,
67 pub updated_button_count: i32,
69}
70
71impl ApiResponseTrait for UpdateFeedCardButtonResponse {
72 fn data_format() -> ResponseFormat {
73 ResponseFormat::Data
74 }
75}
76
77#[derive(Debug, Serialize, Deserialize)]
79pub struct TimelyReminderRequest {
80 pub content: Value,
82 pub target_users: Vec<String>,
84 #[serde(skip_serializing_if = "Option::is_none")]
86 pub reminder_type: Option<String>,
87}
88
89#[derive(Debug, Clone, Serialize, Deserialize)]
91pub struct TimelyReminderResponse {
92 pub reminder_id: String,
94 pub send_time: String,
96 pub success_count: i32,
98 pub failed_users: Vec<String>,
100}
101
102impl ApiResponseTrait for TimelyReminderResponse {
103 fn data_format() -> ResponseFormat {
104 ResponseFormat::Data
105 }
106}
107
108impl GroupsBotsService {
109 pub fn new(config: Config) -> Self {
110 Self { config }
111 }
112
113 pub async fn bot_time_sentive(
115 &self,
116 receive_id_type: UserIdType,
117 request: BotTimeSentiveRequest,
118 option: Option<RequestOption>,
119 ) -> SDKResult<BaseResponse<BotTimeSentiveResponse>> {
120 let api_req = ApiRequest {
121 http_method: Method::POST,
122 api_path: "/open-apis/im/v2/groups-bots/bot_time_sentive".to_string(),
123 supported_access_token_types: vec![AccessTokenType::Tenant, AccessTokenType::User],
124 query_params: HashMap::from([(
125 "receive_id_type".to_string(),
126 receive_id_type.as_str().to_string(),
127 )]),
128 body: serde_json::to_vec(&request)?,
129 ..Default::default()
130 };
131
132 Transport::request(api_req, &self.config, option).await
133 }
134
135 pub async fn update(
137 &self,
138 message_id: &str,
139 request: UpdateFeedCardButtonRequest,
140 option: Option<RequestOption>,
141 ) -> SDKResult<BaseResponse<UpdateFeedCardButtonResponse>> {
142 let api_req = ApiRequest {
143 http_method: Method::PUT,
144 api_path: format!("/open-apis/im/v2/groups-bots/{message_id}/update"),
145 supported_access_token_types: vec![AccessTokenType::Tenant, AccessTokenType::User],
146 body: serde_json::to_vec(&request)?,
147 ..Default::default()
148 };
149
150 Transport::request(api_req, &self.config, option).await
151 }
152
153 pub async fn patch(
155 &self,
156 receive_id_type: UserIdType,
157 request: TimelyReminderRequest,
158 option: Option<RequestOption>,
159 ) -> SDKResult<BaseResponse<TimelyReminderResponse>> {
160 let api_req = ApiRequest {
161 http_method: Method::PATCH,
162 api_path: "/open-apis/im/v2/groups-bots/patch".to_string(),
163 supported_access_token_types: vec![AccessTokenType::Tenant, AccessTokenType::User],
164 query_params: HashMap::from([(
165 "receive_id_type".to_string(),
166 receive_id_type.as_str().to_string(),
167 )]),
168 body: serde_json::to_vec(&request)?,
169 ..Default::default()
170 };
171
172 Transport::request(api_req, &self.config, option).await
173 }
174}