Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace utils

Index

Functions

  • chunks<T>(arr: T[], size?: number): Generator<T[]>
  • Turns the given iterable into chunks of the specified size, which is 100 by default since that's what Telegram uses the most.

    Type Parameters

    • T

    Parameters

    • arr: T[]
    • size: number = 100

    Returns Generator<T[]>

  • getInputPeer(entity: any, allowSelf?: boolean, checkHash?: boolean): TypeInputPeer
  • Gets the input peer for the given "entity" (user, chat or channel).

    A TypeError is raised if the given entity isn't a supported type or if check_hash is True but the entity's accessHash is None or* the entity contains min information. In this case, the hash cannot be used for general purposes, and thus is not returned to avoid any issues which can derive from invalid access hashes.

    Note that checkHash is ignored if an input peer is already passed since in that case we assume the user knows what they're doing. This is key to getting entities by explicitly passing hash = 0.

    Parameters

    • entity: any
    • allowSelf: boolean = true
    • checkHash: boolean = true

    Returns TypeInputPeer

  • Similar to :meth:getInputPeer, but for :tl:InputUser's alone.

    .. important::

    This method does not validate for invalid general-purpose access hashes, unlike get_input_peer. Consider using instead: get_input_channel(get_input_peer(channel)).

    Parameters

    Returns TypeInputUser

  • strippedPhotoToJpg(stripped: Buffer): Buffer
  • isAudio(file: any): boolean
  • Returns True if the file has an audio mime type.

    Parameters

    • file: any

    Returns boolean

  • isImage(file: any): boolean
  • Returns True if the file has an image mime type.

    Parameters

    • file: any

    Returns boolean

  • getExtension(media: any): string
  • Similar to :meth:get_input_peer, but for media.

    If the media is :tl:InputFile and is_photo is known to be True, it will be treated as an :tl:InputMediaUploadedPhoto. Else, the rest of parameters will indicate how to treat it.

    Parameters

    Returns TypeInputMedia

  • getAppropriatedPartSize(fileSize: BigInteger): 256 | 512 | 128
  • Gets the appropriated part size when uploading or downloading files, given an initial file size.

    Parameters

    • fileSize: BigInteger

    Returns 256 | 512 | 128

  • getPeer(peer: any): any
  • getPeerId(peer: EntityLike, addMark?: boolean): string
  • Convert the given peer into its marked ID by default.

    This "mark" comes from the "bot api" format, and with it the peer type can be identified back. User ID is left unmodified, chat ID is negated, and channel ID is prefixed with -100:

    userId -chatId -100channel_id

    The original ID and the peer type class can be returned with a call to :meth:resolve_id(marked_id).

    Parameters

    Returns string

  • parsePhone(phone: string): undefined | string
  • Parses the given phone, or returns undefined if it's invalid.

    Parameters

    • phone: string

    Returns undefined | string

  • parseID(id: string): undefined | BigInteger
  • Parses a string ID into a big int

    Parameters

    • id: string

    Returns undefined | BigInteger

  • resolveInviteLink(link: string): [number, number, number]
  • parseUsername(username: string): { username?: string; isInvite: boolean }
  • Parses the given username or channel access hash, given a string, username or URL. Returns a tuple consisting of both the stripped, lowercase username and whether it is a joinchat/ hash (in which case is not lowercase'd).

    Returns (undefined, false) if the username or link is not valid.

    Parameters

    • username: string

    Returns { username?: string; isInvite: boolean }

    • Optional username?: string
    • isInvite: boolean
  • rtrim(s: string, mask: string): string
  • Gets the display name for the given :tl:User, :tl:Chat or :tl:Channel. Returns an empty string otherwise

    Parameters

    Returns string

Generated using TypeDoc