Telegram::JSONHelper
Comprehensive JSON serialization helper for Telegram Bot API
This module provides utilities for converting Crystal types to JSON-compatible formats while handling the specific requirements of the Telegram Bot API. It includes:
- Safe type conversion with comprehensive error handling
- Support for all Telegram API types including file uploads
- Performance optimizations to minimize allocations
- Validation for API-specific constraints
Example
class MyClient
include Telegram::JSONHelper
def send_message(text : String, keyboard : InlineKeyboardMarkup? = nil)
params = build_request_hash(
"text" => text,
"reply_markup" => keyboard
)
# params will only include non-nil values
end
end