gotd Documentation

website·Indexed 32 days ago

https://gotd.dev

Reference documentation for gotd, a Go implementation of the Telegram MTProto protocol. Includes detailed type definitions and constructors for TL classes such as tg.UserClass, tg.MessagesStickerSetClass, and tg.StarGiftClass.

Tokens
361.9K
Snippets
1.7K
Records
3.1K
Agent score
60%

What's inside gotd

  1. Overview of gotd/botapi

    gotd/botapi is a Telegram Bot API library for Go that is implemented directly over MTProto using gotd/td, rather than using the standard HTTP Bot API (api.telegram.org). By using MTProto, it avoids the Bot API server's rate limits, eliminates the need for getUpdates long-polling or webhooks via a persistent connection, and provides an 'escape hatch' to the raw gotd/td client via Bot.Raw() for functionality not yet covered by the Bot API surface.
  2. Overview of gotd MTProto client

    gotd is a Telegram MTProto API client implemented in pure Go for both users and bots. Unlike the Bot API, it provides direct access to every method of the Telegram API, speaking the same low-level protocol as official Telegram apps and TDLib. It features full MTProto 2.0 support, low memory overhead (approx 150 KB per idle client), and generated types for the entire Telegram schema.
  3. Get value information for a collectible star gift

    Use the PaymentsGetUniqueStarGiftValueInfo method to retrieve information about the value of a collectible gift. This method requires a slug obtained from a starGiftUnique object. If the provided slug is invalid, the API returns a 400 STARGIFT_SLUG_INVALID error.
    client.Run(ctx, func(ctx context.Context) error {
    	api := client.API()
    	
    	// slug is the identifier from a starGiftUnique
    	res, err := api.PaymentsGetUniqueStarGiftValueInfo(ctx, slug)
    	if err != nil {
    		return err
    	}
    	_ = res // returns *PaymentsUniqueStarGiftValueInfo
    	return nil
    })
  4. Use the tg.HelpCountry struct to represent country metadata

    The tg.HelpCountry struct (TL definition help.country#c3878e23) provides information about a specific country, including its ISO codes, localized names, and associated phone patterns. It is used when handling country-specific data in the Telegram API.
    type tg.HelpCountry struct {
        Hidden       bool
        ISO2         string
        DefaultName  string
        Name         string
        CountryCodes []tg.HelpCountryCode
    }
  5. Retrieve Telegram Premium promotion information using HelpGetPremiumPromo

    Use the HelpGetPremiumPromo method to get information about current Telegram Premium promotions. This method requires no parameters and returns a *HelpPremiumPromo object.
    client.Run(ctx, func(ctx context.Context) error {
    	api := client.API()
    	
    	res, err := api.HelpGetPremiumPromo(ctx)
    	if err != nil {
    		return err
    	}
    	_ = res // *HelpPremiumPromo
    	return nil
    })
  6. Obtain Mini App information using MessagesGetBotApp

    Use the MessagesGetBotApp method to retrieve detailed information about a direct link Mini App. This method requires an InputBotAppClass (obtained from a Direct Mini App deep link) and a cache hash.
    client.Run(ctx, func(ctx context.Context) error {
    	api := client.API()
    	
    	res, err := api.MessagesGetBotApp(ctx, &tg.MessagesGetBotAppRequest{
    		App:  inputBotApp, // InputBotAppClass
    		Hash: 0,           // int64 hash used for caching
    	})
    	if err != nil {
    		return err
    	}
    	_ = res // *MessagesBotApp
    	return nil
    })
  7. Understand tg.StatsPublicForwards fields

    The tg.StatsPublicForwards type includes the following fields:

    • Count (int, required): Total number of results.
    • Forwards ([]PublicForwardClass, required): Detailed information about the forwards of a story.
    • NextOffset (string): Offset used for pagination of results.
    • Chats ([]ChatClass, required): List of mentioned chats.
    • Users ([]UserClass, required): List of mentioned users.
  8. Use tg.StoriesFoundStories to handle global story search results

    The tg.StoriesFoundStories struct is returned when performing a global story search (e.g., via stories.searchPosts). It contains the total count of matching stories, the list of stories found, and metadata about mentioned users and chats. If NextOffset is provided, it can be used to fetch the subsequent page of results; otherwise, the current page is the final one.
    type tg.StoriesFoundStories struct {
        Count      int               // Total number of results found for the query.
        Stories    []FoundStory      // Matching stories.
        NextOffset string            // Offset used to fetch the next page; empty if this is the final page.
        Chats      []ChatClass       // Mentioned chats
        Users      []UserClass       // Mentioned users
    }
  9. Fetch bot affiliation info using PaymentsGetConnectedStarRefBot

    Use the PaymentsGetConnectedStarRefBot method to retrieve information about a specific bot affiliation. This method requires both the affiliated peer and the bot offering the affiliate program.

    Parameters:

    • Peer (InputPeerClass): The affiliated peer (Required).
    • Bot (InputUserClass): The bot that offers the affiliate program (Required).

    Returns:

    • *PaymentsConnectedStarRefBots

    Possible Errors:

    • 400 PEER_ID_INVALID: The provided peer id is invalid.
    client.Run(ctx, func(ctx context.Context) error {
    	api := client.API()
    	
    	res, err := api.PaymentsGetConnectedStarRefBot(ctx, &tg.PaymentsGetConnectedStarRefBotRequest{
    		Peer: peer, // InputPeerClass
    		Bot:  bot,  // InputUserClass
    	})
    	if err != nil {
    		return err
    	}
    	_ = res // *PaymentsConnectedStarRefBots
    	return nil
    })
  10. Handle Telegram Terms of Service updates with HelpTermsOfServiceUpdate

    The tg.HelpTermsOfServiceUpdate struct provides information about an update to Telegram's terms of service. If a user declines the updated terms of service, the application should call the account.deleteAccount method using the reason "Decline ToS update".
    type tg.HelpTermsOfServiceUpdate struct {
        Expires        int
        TermsOfService HelpTermsOfService
    }
  11. Inform the server of pending bot updates using HelpSetBotUpdatesStatus

    The HelpSetBotUpdatesStatus method is used exclusively by bots to notify the server about the number of pending updates that have not been processed for a long time. This helps the server track the bot's processing status.

    Constraints:

    • This method can only be called by a bot. Calling it from a user account will result in a 400 USER_BOT_REQUIRED error.
    client.Run(ctx, func(ctx context.Context) error {
    	api := client.API()
    	
    	res, err := api.HelpSetBotUpdatesStatus(ctx, &tg.HelpSetBotUpdatesStatusRequest{
    		PendingUpdatesCount: 100, // Number of pending updates
    		Message:             "Processing delay due to high load", // Error message, if present
    	})
    	if err != nil {
    		return err
    	}
    	_ = res // returns bool
    	return nil
    })
  12. Retrieve all languages in a localization pack using LangpackGetLanguages

    Use the LangpackGetLanguages method to get information about all languages available in a specific localization pack. This method requires a platform identifier (e.g., 'android', 'tdesktop') to specify which language pack to query.
    client.Run(ctx, func(ctx context.Context) error {
    	api := client.API()
    	
    	// 'langpack' is the platform identifier, e.g., "android"
    	res, err := api.LangpackGetLanguages(ctx, "android")
    	if err != nil {
    		return err
    	}
    	_ = res // returns []LangPackLanguage
    	return nil
    })