Class: Telegrama::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/telegrama/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/telegrama/configuration.rb', line 56

def initialize
  # Credentials (must be set via initializer)
  @bot_token = nil
  @chat_id = nil

  # Defaults for message formatting
  @default_parse_mode = 'MarkdownV2'
  @disable_web_page_preview = true

  # Message prefix/suffix defaults to nil (no prefix/suffix)
  @message_prefix = nil
  @message_suffix = nil

  # Sensible defaults for formatting options.
  @formatting_options = {
    escape_markdown: true,
    obfuscate_emails: false,
    escape_html: false,
    truncate: 4096
  }

  # Client options
  @client_options = {
    timeout: 30,
    retry_count: 3,
    retry_delay: 1
  }

  @deliver_message_async = false
  @deliver_message_queue = 'default'
end

Instance Attribute Details

#bot_tokenObject

Your Telegram Bot API token



7
8
9
# File 'lib/telegrama/configuration.rb', line 7

def bot_token
  @bot_token
end

#chat_idObject

Default chat ID for sending messages. You can override this on the fly when sending messages.



11
12
13
# File 'lib/telegrama/configuration.rb', line 11

def chat_id
  @chat_id
end

#client_optionsObject

Client options for API connection and request handling Available keys:

:timeout          (Integer) - API request timeout in seconds.
:retry_count      (Integer) - Number of retries for failed requests.
:retry_delay      (Integer) - Delay between retries in seconds.


46
47
48
# File 'lib/telegrama/configuration.rb', line 46

def client_options
  @client_options
end

#default_parse_modeObject

Default parse mode for messages (e.g. “MarkdownV2” or “HTML”).



14
15
16
# File 'lib/telegrama/configuration.rb', line 14

def default_parse_mode
  @default_parse_mode
end

#deliver_message_asyncObject

Whether to deliver messages asynchronously via ActiveJob. Defaults to false



50
51
52
# File 'lib/telegrama/configuration.rb', line 50

def deliver_message_async
  @deliver_message_async
end

#deliver_message_queueObject

The ActiveJob queue name to use when enqueuing messages. Defaults to ‘default’



54
55
56
# File 'lib/telegrama/configuration.rb', line 54

def deliver_message_queue
  @deliver_message_queue
end

#disable_web_page_previewObject

Whether to disable web page previews by default.



17
18
19
# File 'lib/telegrama/configuration.rb', line 17

def disable_web_page_preview
  @disable_web_page_preview
end

#formatting_optionsObject

Formatting options used by the Formatter module. Available keys:

:escape_markdown   (Boolean) - Escape Telegram markdown special characters.
:obfuscate_emails  (Boolean) - Obfuscate email addresses found in messages.
:escape_html       (Boolean) - Escape HTML entities (<, >, &).
:truncate          (Integer) - Maximum allowed message length.


35
36
37
# File 'lib/telegrama/configuration.rb', line 35

def formatting_options
  @formatting_options
end

#message_prefixObject

Optional prefix to prepend to all messages (e.g. “[MyApp] n”)



20
21
22
# File 'lib/telegrama/configuration.rb', line 20

def message_prefix
  @message_prefix
end

#message_suffixObject

Optional suffix to append to all messages (e.g. “n– Sent from MyApp”)



23
24
25
# File 'lib/telegrama/configuration.rb', line 23

def message_suffix
  @message_suffix
end

Instance Method Details

#validate!Object

Validate the configuration. Raise descriptive errors if required settings are missing or invalid.



90
91
92
93
94
95
96
# File 'lib/telegrama/configuration.rb', line 90

def validate!
  validate_bot_token!
  validate_default_parse_mode!
  validate_formatting_options!
  validate_client_options!
  true
end