コード例 #1
0
        internal static MessageResponse Parse(JsonData data)
        {
            if (data == null || !data.Has("message_id") || !data.Has("from") || !data.Has("date") || !data.Has("chat"))
            {
                return(null);
            }

            var messageResponse = new MessageResponse
            {
                MessageId             = data.Get <int>("message_id"),
                From                  = UserResponse.Parse(data.GetJson("from")),
                Date                  = data.GetDateTime("date"),
                Chat                  = ChatResponse.Parse(data.GetJson("chat")),
                ForwardFrom           = UserResponse.Parse(data.GetJson("forward_from")),
                ForwardDate           = data.GetDateTime("forward_date"),
                ReplyToMessage        = Parse(data.GetJson("reply_to_message")),
                Text                  = data.Get <string>("text"),
                Audio                 = AudioResponse.Parse(data.GetJson("audio")),
                Document              = DocumentResponse.Parse(data.GetJson("document")),
                Sticker               = StickerResponse.Parse(data.GetJson("sticker")),
                Video                 = VideoResponse.Parse(data.GetJson("video")),
                Voice                 = VoiceResponse.Parse(data.GetJson("voice")),
                Caption               = data.Get <string>("caption"),
                Contact               = ContactResponse.Parse(data.GetJson("contact")),
                Location              = LocationResponse.Parse(data.GetJson("location")),
                NewChatParticipant    = UserResponse.Parse(data.GetJson("new_chat_participant")),
                LeftChatParticipant   = UserResponse.Parse(data.GetJson("left_chat_participant")),
                NewChatTitle          = data.Get <string>("new_chat_title"),
                DeleteChatPhoto       = data.Get <bool?>("delete_chat_photo"),
                GroupChatCreated      = data.Get <bool?>("group_chat_created"),
                SupergroupChatCreated = data.Get <bool?>("supergroup_chat_created"),
                ChannelChatCreated    = data.Get <bool?>("channel_chat_created"),
                MigrateToChatId       = data.Get <int?>("migrate_to_chat_id"),
                MigrateFromChatId     = data.Get <int?>("migrate_from_chat_id")
            };

            if (data.Has("photo"))
            {
                foreach (var photo in data.GetJsonList("photo"))
                {
                    messageResponse.Photo.Add(PhotoSizeResponse.Parse(photo));
                }
            }
            if (data.Has("new_chat_photo"))
            {
                foreach (var photo in data.GetJsonList("new_chat_photo"))
                {
                    messageResponse.NewChatPhoto.Add(PhotoSizeResponse.Parse(photo));
                }
            }

            return(messageResponse);
        }
コード例 #2
0
        internal static DocumentResponse Parse(JsonData data)
        {
            if (data == null || !data.Has("file_id"))
            {
                return(null);
            }

            return(new DocumentResponse
            {
                FileId = data.Get <string>("file_id"),
                Thumb = PhotoSizeResponse.Parse(data.GetJson("thumb")),
                FileName = data.Get <string>("file_name"),
                MimeType = data.Get <string>("mime_type"),
                FileSize = data.Get <int?>("file_size")
            });
        }
コード例 #3
0
        internal static StickerResponse Parse(JsonData data)
        {
            if (data == null || !data.Has("file_id") || !data.Has("width") || !data.Has("height"))
            {
                return(null);
            }

            return(new StickerResponse
            {
                FileId = data.Get <string>("file_id"),
                Width = data.Get <int>("width"),
                Height = data.Get <int>("height"),
                Thumb = PhotoSizeResponse.Parse(data.GetJson("thumb")),
                FileSize = data.Get <int?>("file_size")
            });
        }
コード例 #4
0
        internal static VideoResponse Parse(JsonData data)
        {
            if (data == null || !data.Has("file_id") || !data.Has("width") || !data.Has("height") || !data.Has("duration"))
            {
                return(null);
            }

            return(new VideoResponse
            {
                FileId = data.Get <string>("file_id"),
                Width = data.Get <int>("width"),
                Height = data.Get <int>("height"),
                Duration = data.Get <int>("duration"),
                Thumb = PhotoSizeResponse.Parse(data.GetJson("thumb")),
                MimeType = data.Get <string>("mime_type"),
                FileSize = data.Get <int?>("file_size")
            });
        }
コード例 #5
0
        internal static UserProfilePhotosResponse Parse(JsonData data)
        {
            if (data == null || !data.Has("total_count") || !data.Has("photos"))
            {
                return(null);
            }

            var userProfilePhotosResponse = new UserProfilePhotosResponse
            {
                TotalCount = data.Get <int>("total_count")
            };

            foreach (var photo in data.GetJsonList("photo"))
            {
                userProfilePhotosResponse.Photos.Add(PhotoSizeResponse.Parse(photo));
            }

            return(userProfilePhotosResponse);
        }