wmakeev
11/20/2016 - 7:51 AM

telegram typings #telegram #typings

telegram typings #telegram #typings

// A typings definition of some telegram data structure
// author: Richard He<richard9372@gmail.com>
// https://gist.github.com/richard1122/1eb54cd4e422aeb707718ab307decd34
// see more detail: https://core.telegram.org/bots/api

declare namespace TL {
    export interface IResponse<T> {
        ok:boolean
        result:T
    }
    
    export interface IMessage {
        message_id:number
        from:IUser
        date:number
        chat:IChat
        forward_from?:IUser
        forward_from_chat?:IChat
        forward_date?:number
        reply_to_message?:IMessage
        edit_date?:number
        text?:string
        entities?:Array<IMessageEntity>
        audio?:IAudio
        document?:IDocument
        photo?:Array<IPhotoSize>
        sticker?:ISticker
        video?:IVideo
        voice?:IVoice
        caption?:string
        contack?:IContact
        location?:ILocation
        venue?:IVenue
        new_chat_member?:IUser
        left_chat_member?:IUser
        new_chat_title?:string
        new_chat_photo?:Array<IPhotoSize>
        delete_chat_photo?:boolean
        group_chat_created?:boolean
        supergroup_chat_created?:boolean
        channel_chat_created?:boolean
        migrate_to_chat_id?:number
        migrate_from_chat_id?:number
        pinned_message:IMessage
    }
    
    export interface IMessageUpdate {
        update_id:number
        message:IMessage
    }
    
    export interface IUser {
        id:number
        first_name:string
        last_name?:string
        username?:string
    }
    
    export type ChatType = 'private' | 'group' | 'supergroup' | 'channel'
    
    export interface IChat {
        id:number
        type:ChatType
        title?:string
        username?:string
        first_name?:string
        last_name?:string
    }
    
    export type MessageEntityType = 'mention' | 'hashtag' | 'bot_command' | 'url' | 'email' | 'bold' | 'italic' | 'code' | 'pre' | 'text_link' | 'text_mention'
    
    export interface IMessageEntity {
        type:MessageEntityType
        offset:number
        length:number
        url?:string
        user?:IUser
    }
    
    export interface IFile {
        file_id:string
        file_size?:number
        file_path?:string
    }
    
    export interface IPhotoSize extends IFile {
        width:number
        height:number
    }
    
    export interface IAudio extends IFile {
        duration:number
        performer?:string
        title?:string
        mime_type?:string
    }
    
    export interface IDocument extends IFile {
        thumb?:IPhotoSize
        file_name?:string
        mime_type?:string
    }
    
    export interface ISticker extends IFile {
        width:number
        height:number
        thumb?:IPhotoSize
        emoji?:string
    }
    
    export interface IVideo extends IFile {
        width:number
        height:number
        duration:number
        thumb?:IPhotoSize
        mime_type?:string
    }
    
    export interface IVoice extends IFile {
        duration:number
        mime_type?:string
    }
    
    export interface IContact {
        phone_number:string
        first_name:string
        last_name?:string
        user_id?:number
    }
    
    export interface ILocation {
        longitude:number
        latitude:number
    }
    
    export interface IVenue {
        location:ILocation
        title:string
        address:string
        foursquare_id?:string
    }
    
    export interface IUserProfilePhotos {
        total_count:number
        photos:Array<IPhotoSize>
    }
}