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 endpoints::EndpointBuilder,
13 http::Transport,
14 req_option::RequestOption,
15 SDKResult,
16 },
17 service::im::v2::models::{ButtonInfo, UserIdType},
18};
19
20pub struct GroupsBotsService {
22 pub config: Config,
23}
24
25#[derive(Debug, Serialize, Deserialize)]
27pub struct BotTimeSentiveRequest {
28 pub receive_id: String,
30 pub content: Value,
32 pub msg_type: String,
34}
35
36#[derive(Debug, Clone, Serialize, Deserialize)]
38pub struct BotTimeSentiveResponse {
39 pub message_id: String,
41 pub send_time: String,
43}
44
45impl ApiResponseTrait for BotTimeSentiveResponse {
46 fn data_format() -> ResponseFormat {
47 ResponseFormat::Data
48 }
49}
50
51#[derive(Debug, Serialize, Deserialize)]
53pub struct UpdateFeedCardButtonRequest {
54 pub buttons: Vec<ButtonInfo>,
56 #[serde(skip_serializing_if = "Option::is_none")]
58 pub reason: Option<String>,
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize)]
63pub struct UpdateFeedCardButtonResponse {
64 pub message_id: String,
66 pub update_time: String,
68 pub updated_button_count: i32,
70}
71
72impl ApiResponseTrait for UpdateFeedCardButtonResponse {
73 fn data_format() -> ResponseFormat {
74 ResponseFormat::Data
75 }
76}
77
78#[derive(Debug, Serialize, Deserialize)]
80pub struct TimelyReminderRequest {
81 pub content: Value,
83 pub target_users: Vec<String>,
85 #[serde(skip_serializing_if = "Option::is_none")]
87 pub reminder_type: Option<String>,
88}
89
90#[derive(Debug, Clone, Serialize, Deserialize)]
92pub struct TimelyReminderResponse {
93 pub reminder_id: String,
95 pub send_time: String,
97 pub success_count: i32,
99 pub failed_users: Vec<String>,
101}
102
103impl ApiResponseTrait for TimelyReminderResponse {
104 fn data_format() -> ResponseFormat {
105 ResponseFormat::Data
106 }
107}
108
109impl GroupsBotsService {
110 pub fn new(config: Config) -> Self {
111 Self { config }
112 }
113
114 pub async fn bot_time_sentive(
116 &self,
117 receive_id_type: UserIdType,
118 request: BotTimeSentiveRequest,
119 option: Option<RequestOption>,
120 ) -> SDKResult<BaseResponse<BotTimeSentiveResponse>> {
121 let api_req = ApiRequest {
122 http_method: Method::POST,
123 api_path: crate::core::endpoints::im::IM_V2_GROUPS_BOTS_TIME_SENSITIVE.to_string(),
124 supported_access_token_types: vec![AccessTokenType::Tenant, AccessTokenType::User],
125 query_params: HashMap::from([(
126 "receive_id_type",
127 receive_id_type.as_str().to_string(),
128 )]),
129 body: serde_json::to_vec(&request)?,
130 ..Default::default()
131 };
132
133 Transport::request(api_req, &self.config, option).await
134 }
135
136 pub async fn update(
138 &self,
139 message_id: &str,
140 request: UpdateFeedCardButtonRequest,
141 option: Option<RequestOption>,
142 ) -> SDKResult<BaseResponse<UpdateFeedCardButtonResponse>> {
143 let api_req = ApiRequest {
144 http_method: Method::PUT,
145 api_path: EndpointBuilder::replace_param(
146 crate::core::endpoints::im::IM_V2_GROUPS_BOTS_UPDATE,
147 "message_id",
148 message_id,
149 ),
150 supported_access_token_types: vec![AccessTokenType::Tenant, AccessTokenType::User],
151 body: serde_json::to_vec(&request)?,
152 ..Default::default()
153 };
154
155 Transport::request(api_req, &self.config, option).await
156 }
157
158 pub async fn patch(
160 &self,
161 receive_id_type: UserIdType,
162 request: TimelyReminderRequest,
163 option: Option<RequestOption>,
164 ) -> SDKResult<BaseResponse<TimelyReminderResponse>> {
165 let api_req = ApiRequest {
166 http_method: Method::PATCH,
167 api_path: crate::core::endpoints::im::IM_V2_GROUPS_BOTS_PATCH.to_string(),
168 supported_access_token_types: vec![AccessTokenType::Tenant, AccessTokenType::User],
169 query_params: HashMap::from([(
170 "receive_id_type",
171 receive_id_type.as_str().to_string(),
172 )]),
173 body: serde_json::to_vec(&request)?,
174 ..Default::default()
175 };
176
177 Transport::request(api_req, &self.config, option).await
178 }
179}