class Telecr::Api::Client

Overview

Main client class for making requests to Telegram Bot API

Defined in:

api/client.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(token : String, **options) #

Initialize a new Telegram bot client

@param token [String] Bot token from @BotFather @param options [Hash] Optional configuration @option options [Int32] :timeout Request timeout in seconds (default 30)


[View source]

Instance Method Detail

def call(method : String, params = {} of String => String) : JSON::Any #

Make a blocking API call (raises on error)

@param method [String] Telegram API method name (e.g., "sendMessage") @param params [Hash(String, String)] Method parameters @return [JSON::Any] API response result @raise [APIError] If Telegram returns error


[View source]
def call!(method : String, params = {} of String => String, &block : JSON::Any | Nil, Exception | Nil -> ) #

Make an API call with callback block (non-blocking style)

@param method [String] Telegram API method name @param params [Hash(String, String)] Method parameters @yield [JSON::Any?, Exception?] Passes result or error to block


[View source]
def download(file_id : String, destination_path : String | Nil = nil) : String | Nil #

Download a file from Telegram servers

@param file_id [String] Telegram file_id from message @param destination_path [String?] Where to save file (optional) @return [String] File content if no destination, otherwise path @raise [NetworkError] If download fails


[View source]
def get_updates(offset : Int32 | Nil = nil, timeout : Int32 = 30, limit : Int32 = 100, allowed_updates : Array(String) | Nil = nil) : JSON::Any #

Get updates from Telegram (long polling)

@param offset [Int32?] Last update ID + 1 @param timeout [Int32] Long polling timeout in seconds @param limit [Int32] Max number of updates to receive @param allowed_updates [Array(String)?] Which update types to receive @return [JSON::Any] Array of updates


[View source]
def upload(method : String, params : Hash(String, String)) : JSON::Any #

Upload a file using multipart/form-data

@param method [String] Upload method (sendPhoto, sendDocument, etc.) @param params [Hash(String, String)] Parameters including file paths @return [JSON::Any] API response result


[View source]