1defmodule Nadia.Model do
2  @moduledoc """
3  Types used in Telegram Bot API.
4
5  ## Reference
6  https://core.telegram.org/bots/api#available-types
7  """
8
9  defmodule User do
10    defstruct id: nil, first_name: nil, last_name: nil, username: nil
11    @type t :: %User{id: integer, first_name: binary, last_name: binary, username: binary}
12  end
13
14  defmodule ChatPhoto do
15    defstruct small_file_id: nil, big_file_id: nil
16    @type t :: %ChatPhoto{small_file_id: binary, big_file_id: binary}
17  end
18
19  defmodule Chat do
20    defstruct id: nil,
21              type: nil,
22              title: nil,
23              username: nil,
24              first_name: nil,
25              last_name: nil,
26              photo: nil
27
28    @type t :: %Chat{
29            id: integer,
30            type: binary,
31            title: binary,
32            username: binary,
33            first_name: binary,
34            last_name: binary,
35            photo: ChatPhoto.t()
36          }
37  end
38
39  defmodule PhotoSize do
40    defstruct file_id: nil, width: nil, height: nil, file_size: nil
41    @type t :: %PhotoSize{file_id: binary, width: integer, height: integer, file_size: integer}
42  end
43
44  defmodule Audio do
45    defstruct file_id: nil,
46              duration: nil,
47              performer: nil,
48              title: nil,
49              mime_type: nil,
50              file_size: nil
51
52    @type t :: %Audio{
53            file_id: binary,
54            duration: integer,
55            performer: binary,
56            title: binary,
57            mime_type: binary,
58            file_size: integer
59          }
60  end
61
62  defmodule Document do
63    defstruct file_id: nil, thumb: nil, file_name: nil, mime_type: nil, file_size: nil
64
65    @type t :: %Document{
66            file_id: binary,
67            thumb: PhotoSize.t(),
68            file_name: binary,
69            mime_type: binary,
70            file_size: integer
71          }
72  end
73
74  defmodule Sticker do
75    defstruct file_id: nil, width: nil, height: nil, thumb: nil, emoji: nil, file_size: nil
76
77    @type t :: %Sticker{
78            file_id: binary,
79            width: integer,
80            height: integer,
81            thumb: PhotoSize.t(),
82            emoji: binary,
83            file_size: integer
84          }
85  end
86
87  defmodule Video do
88    defstruct file_id: nil,
89              width: nil,
90              height: nil,
91              duration: nil,
92              thumb: nil,
93              mime_type: nil,
94              file_size: nil
95
96    @type t :: %Video{
97            file_id: binary,
98            width: integer,
99            height: integer,
100            duration: integer,
101            thumb: PhotoSize.t(),
102            mime_type: binary,
103            file_size: integer
104          }
105  end
106
107  defmodule Voice do
108    defstruct file_id: nil, duration: nil, mime_type: nil, file_size: nil
109    @type t :: %Voice{file_id: binary, duration: integer, mime_type: binary, file_size: integer}
110  end
111
112  defmodule Contact do
113    defstruct phone_number: nil, first_name: nil, last_name: nil, user_id: nil
114
115    @type t :: %Contact{
116            phone_number: binary,
117            first_name: binary,
118            last_name: binary,
119            user_id: integer
120          }
121  end
122
123  defmodule Location do
124    defstruct latitude: nil, longitude: nil
125    @type t :: %Location{latitude: float, longitude: float}
126  end
127
128  defmodule Venue do
129    defstruct location: nil, title: nil, address: nil, foursquare_id: nil
130
131    @type t :: %Venue{
132            location: Location.t(),
133            title: binary,
134            address: binary,
135            foursquare_id: binary
136          }
137  end
138
139  defmodule Message do
140    defstruct message_id: nil,
141              from: nil,
142              date: nil,
143              chat: nil,
144              forward_from: nil,
145              forward_from_chat: nil,
146              forward_date: nil,
147              reply_to_message: nil,
148              edit_date: nil,
149              text: nil,
150              entities: nil,
151              audio: nil,
152              document: nil,
153              photo: [],
154              sticker: nil,
155              video: nil,
156              voice: nil,
157              caption: nil,
158              contact: nil,
159              location: nil,
160              venue: nil,
161              new_chat_member: nil,
162              left_chat_member: nil,
163              new_chat_title: nil,
164              new_chat_photo: [],
165              delete_chat_photo: nil,
166              group_chat_created: nil,
167              supergroup_chat_created: nil,
168              channel_chat_created: nil,
169              migrate_to_chat_id: nil,
170              migrate_from_chat_id: nil,
171              pinned_message: nil
172
173    @type t :: %Message{
174            message_id: integer,
175            from: User.t(),
176            date: integer,
177            chat: Chat.t(),
178            forward_from: User.t(),
179            forward_from_chat: Chat.t(),
180            forward_date: integer,
181            reply_to_message: Message.t(),
182            edit_date: integer,
183            text: binary,
184            entities: MessageEntity.t(),
185            audio: Audio.t(),
186            document: Document.t(),
187            photo: [PhotoSize.t()],
188            sticker: any,
189            video: any,
190            voice: any,
191            caption: binary,
192            contact: any,
193            location: any,
194            venue: any,
195            new_chat_member: User.t(),
196            left_chat_member: User.t(),
197            new_chat_title: binary,
198            new_chat_photo: [PhotoSize.t()],
199            delete_chat_photo: atom,
200            group_chat_created: atom,
201            supergroup_chat_created: atom,
202            channel_chat_created: atom,
203            migrate_to_chat_id: integer,
204            migrate_from_chat_id: integer,
205            pinned_message: Message.t()
206          }
207  end
208
209  defmodule MessageEntity do
210    defstruct type: nil, offset: nil, length: nil, url: nil, user: nil
211
212    @type t :: %MessageEntity{
213            type: binary,
214            offset: integer,
215            length: integer,
216            url: binary,
217            user: User.t()
218          }
219  end
220
221  defmodule InlineQuery do
222    defstruct id: nil, from: nil, location: nil, query: nil, offset: nil
223
224    @type t :: %InlineQuery{
225            id: binary,
226            from: User.t(),
227            location: Location.t(),
228            query: binary,
229            offset: integer
230          }
231  end
232
233  defmodule ChosenInlineResult do
234    defstruct result_id: nil, from: nil, location: nil, inline_message_id: nil, query: nil
235
236    @type t :: %ChosenInlineResult{
237            result_id: binary,
238            from: User.t(),
239            location: Location.t(),
240            inline_message_id: binary,
241            query: binary
242          }
243  end
244
245  defmodule Update do
246    defstruct update_id: nil,
247              message: nil,
248              edited_message: nil,
249              channel_post: nil,
250              inline_query: nil,
251              chosen_inline_result: nil,
252              callback_query: nil
253
254    @type t :: %Update{
255            update_id: integer,
256            message: Message.t(),
257            edited_message: Message.t(),
258            channel_post: Message.t(),
259            inline_query: InlineQuery.t(),
260            chosen_inline_result: ChosenInlineResult.t(),
261            callback_query: CallbackQuery.t()
262          }
263  end
264
265  defmodule UserProfilePhotos do
266    defstruct total_count: nil, photos: []
267    @type t :: %UserProfilePhotos{total_count: integer, photos: [[PhotoSize.t()]]}
268  end
269
270  defmodule File do
271    defstruct file_id: nil, file_size: nil, file_path: nil
272    @type t :: %File{file_id: binary, file_size: integer, file_path: binary}
273  end
274
275  defmodule ReplyKeyboardMarkup do
276    defstruct keyboard: [], resize_keyboard: false, one_time_keyboard: false, selective: false
277
278    @type t :: %ReplyKeyboardMarkup{
279            keyboard: [[KeyboardButton.t()]],
280            resize_keyboard: atom,
281            one_time_keyboard: atom,
282            selective: atom
283          }
284  end
285
286  defmodule KeyboardButton do
287    defstruct text: nil, request_contact: false, request_location: false
288    @type t :: %KeyboardButton{text: binary, request_contact: atom, request_location: atom}
289  end
290
291  defmodule ReplyKeyboardHide do
292    defstruct hide_keyboard: true, selective: false
293    @type t :: %ReplyKeyboardHide{hide_keyboard: true, selective: atom}
294  end
295
296  defmodule InlineKeyboardMarkup do
297    defstruct inline_keyboard: []
298    @type t :: %InlineKeyboardMarkup{inline_keyboard: [[InlineKeyboardButton.t()]]}
299  end
300
301  defmodule InlineKeyboardButton do
302    defstruct text: nil, url: nil, callback_data: nil, switch_inline_query: nil
303
304    @type t :: %InlineKeyboardButton{
305            text: binary,
306            url: binary,
307            callback_data: binary,
308            switch_inline_query: binary
309          }
310  end
311
312  defmodule CallbackQuery do
313    defstruct id: nil, from: nil, message: nil, inline_message_id: nil, data: nil
314
315    @type t :: %CallbackQuery{
316            id: binary,
317            from: User.t(),
318            message: Message.t(),
319            inline_message_id: binary,
320            data: binary
321          }
322  end
323
324  defmodule ForceReply do
325    defstruct force_reply: true, selective: false
326    @type t :: %ForceReply{force_reply: true, selective: atom}
327  end
328
329  defmodule ChatMember do
330    defstruct user: nil, status: nil
331    @type t :: %ChatMember{user: User.t(), status: binary}
332  end
333
334  defmodule Error do
335    defexception reason: nil
336    @type t :: %Error{reason: any}
337
338    def message(%Error{reason: reason}), do: inspect(reason)
339  end
340end
341