Add models of Telegram API JSON responses.
This commit is contained in:
parent
76381e004a
commit
d0a044f3c7
1
src/telepathy/model.cr
Normal file
1
src/telepathy/model.cr
Normal file
@ -0,0 +1 @@
|
||||
require "./model/*"
|
14
src/telepathy/model/audio.cr
Normal file
14
src/telepathy/model/audio.cr
Normal file
@ -0,0 +1,14 @@
|
||||
require "json"
|
||||
|
||||
module Telepathy
|
||||
class Audio
|
||||
JSON.mapping(
|
||||
file_id: String,
|
||||
duration: Int64,
|
||||
performer: String?,
|
||||
title: String?,
|
||||
mime_type: String?,
|
||||
file_size: Int64?
|
||||
)
|
||||
end
|
||||
end
|
22
src/telepathy/model/chat.cr
Normal file
22
src/telepathy/model/chat.cr
Normal file
@ -0,0 +1,22 @@
|
||||
require "json"
|
||||
require "./message.cr"
|
||||
|
||||
module Telepathy
|
||||
class Chat
|
||||
JSON.mapping(
|
||||
id: Int64,
|
||||
type: String,
|
||||
title: String?,
|
||||
username: String?,
|
||||
first_name: String?,
|
||||
last_name: String?,
|
||||
all_members_are_administrators: Bool?,
|
||||
# TODO photo
|
||||
description: String?,
|
||||
invite_link: String?,
|
||||
pinned_message: Message?,
|
||||
sticker_set_name: String?,
|
||||
can_set_sticker_set: Bool?
|
||||
)
|
||||
end
|
||||
end
|
12
src/telepathy/model/contact.cr
Normal file
12
src/telepathy/model/contact.cr
Normal file
@ -0,0 +1,12 @@
|
||||
require "json"
|
||||
|
||||
module Telepathy
|
||||
class Contact
|
||||
JSON.mapping(
|
||||
phone_number: String,
|
||||
first_name: String,
|
||||
last_name: String?,
|
||||
user_id: Int64?
|
||||
)
|
||||
end
|
||||
end
|
14
src/telepathy/model/document.cr
Normal file
14
src/telepathy/model/document.cr
Normal file
@ -0,0 +1,14 @@
|
||||
require "json"
|
||||
require "./photo_size.cr"
|
||||
|
||||
module Telepathy
|
||||
class Document
|
||||
JSON.mapping(
|
||||
file_id: String,
|
||||
thumb: PhotoSize?,
|
||||
file_name: String?,
|
||||
mime_type: String?,
|
||||
file_size: Int64?
|
||||
)
|
||||
end
|
||||
end
|
10
src/telepathy/model/location.cr
Normal file
10
src/telepathy/model/location.cr
Normal file
@ -0,0 +1,10 @@
|
||||
require "json"
|
||||
|
||||
module Telepathy
|
||||
class Location
|
||||
JSON.mapping(
|
||||
longitude: Float32,
|
||||
latitude: Float32
|
||||
)
|
||||
end
|
||||
end
|
61
src/telepathy/model/message.cr
Normal file
61
src/telepathy/model/message.cr
Normal file
@ -0,0 +1,61 @@
|
||||
require "json"
|
||||
require "./user.cr"
|
||||
require "./char.cr"
|
||||
require "./message_entity.cr"
|
||||
require "./audio.cr"
|
||||
require "./document.cr"
|
||||
require "./photo_size.cr"
|
||||
require "./video.cr"
|
||||
require "./voice.cr"
|
||||
require "./video_note.cr"
|
||||
require "./contact.cr"
|
||||
require "./location.cr"
|
||||
require "./venue.cr"
|
||||
|
||||
module Telepathy
|
||||
class Message
|
||||
JSON.mapping(
|
||||
message_id: Int64,
|
||||
from: User?,
|
||||
date: Int64,
|
||||
chat: Chat,
|
||||
forward_from: User?,
|
||||
forward_from_chat: Chat?,
|
||||
forward_from_message_id: Int64?,
|
||||
forward_signature: String?,
|
||||
forward_date: Int64?,
|
||||
reply_to_message: Message?,
|
||||
edit_date: Int64?,
|
||||
media_group_id: String?,
|
||||
author_signature: String?,
|
||||
text: String?,
|
||||
entities: Array(MessageEntity)?,
|
||||
caption_entities: Array(MessageEntity)?,
|
||||
audio: Audio?,
|
||||
document: Document?,
|
||||
photo: Array(PhotoSize)?,
|
||||
video: Video?,
|
||||
voice: Voice?,
|
||||
video_note: VideoNote?,
|
||||
# TODO game
|
||||
# TODO sticker
|
||||
caption: String?,
|
||||
contact: Contact?,
|
||||
location: Location?,
|
||||
venue: Venue?,
|
||||
new_chat_members: Array(User)?,
|
||||
left_chat_member: User?,
|
||||
new_chat_title: String?,
|
||||
# new_chat_photo
|
||||
delete_chat_photo: Bool?,
|
||||
group_chat_created: Bool?,
|
||||
supergroup_chat_created: Bool?,
|
||||
channel_chat_created: Bool?,
|
||||
migrate_to_chat_id: Int64?,
|
||||
migrate_from_chat_id: Int64?,
|
||||
pinned_message: Message?
|
||||
# invoice
|
||||
# successful_payment
|
||||
)
|
||||
end
|
||||
end
|
14
src/telepathy/model/message_entity.cr
Normal file
14
src/telepathy/model/message_entity.cr
Normal file
@ -0,0 +1,14 @@
|
||||
require "json"
|
||||
require "./user.cr"
|
||||
|
||||
module Telepathy
|
||||
class MessageEntity
|
||||
JSON.mapping(
|
||||
type: String,
|
||||
offset: Int64,
|
||||
length: Int64,
|
||||
url: String?,
|
||||
user: User?
|
||||
)
|
||||
end
|
||||
end
|
12
src/telepathy/model/photo_size.cr
Normal file
12
src/telepathy/model/photo_size.cr
Normal file
@ -0,0 +1,12 @@
|
||||
require "json"
|
||||
|
||||
module Telepathy
|
||||
class PhotoSize
|
||||
JSON.mapping(
|
||||
file_id: String?,
|
||||
width: Int64,
|
||||
height: Int64,
|
||||
file_size: Int64?
|
||||
)
|
||||
end
|
||||
end
|
14
src/telepathy/model/user.cr
Normal file
14
src/telepathy/model/user.cr
Normal file
@ -0,0 +1,14 @@
|
||||
require "json"
|
||||
|
||||
module Telepathy
|
||||
class User
|
||||
JSON.mapping(
|
||||
id: Int64,
|
||||
is_bot: Bool,
|
||||
first_name: String,
|
||||
last_name: String?,
|
||||
username: String?,
|
||||
language_code: String?
|
||||
)
|
||||
end
|
||||
end
|
13
src/telepathy/model/venue.cr
Normal file
13
src/telepathy/model/venue.cr
Normal file
@ -0,0 +1,13 @@
|
||||
require "json"
|
||||
require "./location.cr"
|
||||
|
||||
module Telepathy
|
||||
class Venue
|
||||
JSON.mapping(
|
||||
location: Location,
|
||||
title: String,
|
||||
address: String,
|
||||
foursquare_id: String?
|
||||
)
|
||||
end
|
||||
end
|
16
src/telepathy/model/video.cr
Normal file
16
src/telepathy/model/video.cr
Normal file
@ -0,0 +1,16 @@
|
||||
require "json"
|
||||
require "./photo_size.cr"
|
||||
|
||||
module Telepathy
|
||||
class Video
|
||||
JSON.mapping(
|
||||
file_id: String,
|
||||
width: Int64,
|
||||
height: Int64,
|
||||
duration: Int64,
|
||||
thumb: PhotoSize?,
|
||||
mime_type: String?,
|
||||
file_size: Int64?
|
||||
)
|
||||
end
|
||||
end
|
14
src/telepathy/model/video_note.cr
Normal file
14
src/telepathy/model/video_note.cr
Normal file
@ -0,0 +1,14 @@
|
||||
require "json"
|
||||
require "./photo_size.cr"
|
||||
|
||||
module Telepathy
|
||||
class VideoNote
|
||||
JSON.mapping(
|
||||
file_id: String,
|
||||
length: Int64,
|
||||
duration: Int64,
|
||||
thumb: PhotoSize?,
|
||||
file_size: Int64?
|
||||
)
|
||||
end
|
||||
end
|
13
src/telepathy/model/voice.cr
Normal file
13
src/telepathy/model/voice.cr
Normal file
@ -0,0 +1,13 @@
|
||||
require "json"
|
||||
require "./photo_size.cr"
|
||||
|
||||
module Telepathy
|
||||
class Voice
|
||||
JSON.mapping(
|
||||
file_id: String,
|
||||
duration: Int64,
|
||||
mime_type: String?,
|
||||
file_size: Int64?
|
||||
)
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user