botx_api/api/v4/notification/internal/
models.rs

1use serde::{Serialize, Deserialize};
2use uuid::Uuid;
3
4use crate::api::{models::*};
5
6#[derive(Debug, Serialize, Deserialize, Default, Clone, Builder)]
7#[builder(setter(into, prefix = "with", strip_option))]
8pub struct InternalNotificationRequest<TData, TOptions> {
9    /// ID чата
10    pub group_chat_id: Uuid,
11
12    /// Пользовательские данные
13    pub data: TData,
14
15    /// (default: {}) - пользовательские опции
16    pub opts: TOptions,
17    
18    /// (default: Null) - huid получателей события. По умолчанию все участники чата
19    #[builder(default)]
20    pub recipients: Option<Vec<Uuid>>,
21}
22
23#[derive(Debug, Serialize, Deserialize, Clone)]
24pub struct InternalNotificationResponse {
25    pub result: InternalNotificationResult,
26}
27
28#[derive(Debug, Serialize, Deserialize, Clone)]
29pub struct InternalNotificationResult {
30    /// Идентификатор отправляемого сообщения
31    pub sync_id: Uuid,
32}
33
34// #[derive(Debug, Serialize, Deserialize, Clone)]
35// pub struct InternalNotificationExpressError {
36//     pub sync_id: Uuid,
37//     pub reason: String,
38//     pub errors: Vec<String>,
39//     pub error_data: InternalNotificationExpressErrorData
40// }
41
42#[derive(Debug, Serialize, Deserialize, Clone)]
43#[serde(tag = "reason")]
44/// Ошибки при отправке внутренней нотификации
45pub enum InternalNotificationExpressError {
46    /// Превышен лимит интенсивности запросов (429)
47    #[serde(rename(serialize = "too_many_requests", deserialize = "too_many_requests"))]
48    TooManyRequests(TooManyRequests),
49
50    /// Чат не найден
51    #[serde(rename(serialize = "chat_not_found", deserialize = "chat_not_found"))]
52    ChatNotFound(ChatNotFoundWithEventId),
53
54    /// Ошибка от Messaging сервиса
55    #[serde(rename(serialize = "error_from_messaging_service", deserialize = "error_from_messaging_service"))]
56    ErrorFromMessagingService(ErrorFromMessagingServiceWithEventId),
57
58    /// Бот отправитель не является участником чата
59    #[serde(rename(serialize = "bot_is_not_a_chat_member", deserialize = "bot_is_not_a_chat_member"))]
60    BotIsNotAChatMember(BotIsNotAChatMember),
61
62    /// Итоговый список получателей события пуст
63    #[serde(rename(serialize = "event_recipients_list_is_empty", deserialize = "event_recipients_list_is_empty"))]
64    EventRecipientsListIsEmpty(EventRecipientsListIsEmpty),
65
66    // TODO: добавить десериализацию в HashMap<string, string> когда завезут реализацию
67    /// Неопределенная ошибка, смотрите логи
68    #[serde(other)]
69    Other,
70}
71
72#[derive(Debug, Serialize, Deserialize, Clone)]
73/// Превышен лимит интенсивности запросов (429)
74pub struct TooManyRequests {
75    pub errors: Vec<String>,
76    pub error_data: TooManyRequestsData,
77}
78
79#[derive(Debug, Serialize, Deserialize, Clone)]
80/// Чат не найден
81pub struct TooManyRequestsData {
82    pub bot_id: Uuid,
83}
84
85// pub struct ChatNotFound {
86
87// }
88
89// #[derive(Debug, Serialize, Deserialize, Clone)]
90// pub struct InternalNotificationExpressErrorData {
91//     bot_id: Option<Uuid>,
92
93//     group_chat_id: Option<Uuid>,
94
95//     /// Ожидается что будет всегда, но на всякий случай сделан опциональным
96//     error_description: Option<String>,
97
98//     reason: Option<String>,
99
100//     recipients_param: Option<Vec<Uuid>>,
101    
102//     #[serde(flatten)]
103//     other: HashMap<String, String>,
104// }
105