Understand the library structure: Configs, Helpers, and Methods
masterThe library is organized into three primary components to interact with the Telegram Bot API:
Configs: Structs that represent the parameters for a specific Telegram endpoint. There is a one-to-one relationship between endpoints and configs. They typically follow the naming pattern of removing the
sendprefix from the endpoint name and adding aConfigsuffix (e.g.,MessageConfigforsendMessage).- Configs implementing the
Chattableinterface can be used with methods requiring a chat ID. - Configs implementing the
Fileableinterface support file uploads.
- Configs implementing the
Helpers: Functions used to simplify the creation of Configs. They are generally named by replacing the
sendprefix of a method withNew(e.g.,NewMessageinstead ofsendMessage). These helpers typically require the minimum necessary parameters to succeed, allowing you to set additional optional fields on the returned struct.Methods: Functions used to execute the requests.
Requestis the primary low-level method. It accepts aChattableparameter and handles file uploads automatically. It returns anAPIResponse.- Specific methods exist for endpoints with unique return types (e.g.,
getFilereturns aFile). - Most methods return a
Message, which can be processed usingSend.