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.



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
87
88
89
90
91
# File 'lib/telegrama/configuration.rb', line 60

def initialize
  # Credentials (must be set via initializer)
  @bot_token = nil
  @chat_id = nil
  @message_thread_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.


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

def client_options
  @client_options
end

#default_parse_modeObject

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



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

def default_parse_mode
  @default_parse_mode
end

#deliver_message_asyncObject

Whether to deliver messages asynchronously via ActiveJob. Defaults to false



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

def deliver_message_async
  @deliver_message_async
end

#deliver_message_queueObject

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



58
59
60
# File 'lib/telegrama/configuration.rb', line 58

def deliver_message_queue
  @deliver_message_queue
end

#disable_web_page_previewObject

Whether to disable web page previews by default.



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

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.


39
40
41
# File 'lib/telegrama/configuration.rb', line 39

def formatting_options
  @formatting_options
end

#message_prefixObject

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



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

def message_prefix
  @message_prefix
end

#message_suffixObject

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



27
28
29
# File 'lib/telegrama/configuration.rb', line 27

def message_suffix
  @message_suffix
end

#message_thread_idObject

Default message thread ID for sending messages to a forum topic. You can override this on the fly when sending messages.



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

def message_thread_id
  @message_thread_id
end

Instance Method Details

#validate!Object

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



95
96
97
98
99
100
101
102
# File 'lib/telegrama/configuration.rb', line 95

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