Class: Whatsapp::Configuration
- Inherits:
-
Object
- Object
- Whatsapp::Configuration
- Defined in:
- lib/whatsapp/configuration.rb
Overview
Global configuration for whatsapp-ruby.
Constant Summary collapse
- SAFETY_PRESETS =
Safety presets for anti-ban protection.
{ strict: { rate_limit_per_minute: 6, rate_limit_per_hour: 40, rate_limit_per_day: 150, rate_limit_per_recipient_per_hour: 5, min_delay_between_messages: 3.0, delay_jitter: 5.0, max_new_chats_per_day: 10, post_connect_delay: 60.0, idle_threshold: 1800.0, warmup_messages: 5, warmup_delay_factor: 3.0, ramp_up_enabled: true, typing_simulation: true, auto_read_receipts: true, auto_presence_updates: false, ramp_up_days: 7 }, moderate: { rate_limit_per_minute: 10, rate_limit_per_hour: 80, rate_limit_per_day: 300, rate_limit_per_recipient_per_hour: 10, min_delay_between_messages: 2.0, delay_jitter: 3.0, max_new_chats_per_day: 20, post_connect_delay: 30.0, idle_threshold: 3600.0, warmup_messages: 3, warmup_delay_factor: 2.0, ramp_up_enabled: true, typing_simulation: false, auto_read_receipts: false, auto_presence_updates: false, ramp_up_days: 3 }, manual: {}, off: { rate_limit_per_minute: 999, rate_limit_per_hour: 9999, rate_limit_per_day: 99_999, rate_limit_per_recipient_per_hour: 999, min_delay_between_messages: 0.0, delay_jitter: 0.0, max_new_chats_per_day: 9999, post_connect_delay: 0.0, idle_threshold: 999_999.0, warmup_messages: 0, warmup_delay_factor: 0.0, ramp_up_enabled: false, typing_simulation: false, auto_read_receipts: false, auto_presence_updates: false, ramp_up_days: 0 } }.freeze
Connection collapse
-
#auth_dir ⇒ String
Directory for storing WhatsApp auth state.
-
#auto_reconnect ⇒ Boolean
Whether to auto-reconnect on disconnect.
-
#bridge_timeout ⇒ Integer
Seconds to wait for the bridge to become ready.
-
#http_open_timeout ⇒ Integer
HTTP open timeout in seconds for bridge requests.
-
#http_read_timeout ⇒ Integer
HTTP read timeout in seconds for bridge requests.
-
#http_write_timeout ⇒ Integer
HTTP write timeout in seconds for bridge requests.
-
#log_path ⇒ String, IO
Log output path or IO object.
-
#max_reconnect_attempts ⇒ Integer
Maximum number of reconnection attempts.
-
#node_command ⇒ String
Path to the Node.js binary.
-
#reconnect_interval ⇒ Integer
Base interval (seconds) between reconnection attempts.
Rate Limiting collapse
-
#delay_jitter ⇒ Float
Maximum random jitter in seconds (gaussian distribution).
-
#min_delay_between_messages ⇒ Float
Minimum delay between messages in seconds.
-
#rate_limit_per_day ⇒ Integer
Max messages per day (global).
-
#rate_limit_per_hour ⇒ Integer
Max messages per hour (global).
-
#rate_limit_per_minute ⇒ Integer
Max messages per minute (global).
-
#rate_limit_per_recipient_per_hour ⇒ Integer
Max messages per hour per recipient.
-
#rate_limiting_enabled ⇒ Boolean
Whether rate limiting is enabled.
Anti-Ban Safety collapse
-
#auto_presence_updates ⇒ Boolean
Whether to send presence updates (available/unavailable) on connect/disconnect.
-
#auto_read_receipts ⇒ Boolean
Whether to auto-send read receipts for incoming messages.
-
#idle_threshold ⇒ Float
Idle threshold in seconds — if no message sent for this long, the ramp-up warmup kicks in.
-
#max_new_chats_per_day ⇒ Integer
Max new conversations initiated per day.
-
#post_connect_delay ⇒ Float
Delay in seconds before first message after connection.
-
#ramp_up_days ⇒ Integer
Number of days for progressive account warmup.
-
#ramp_up_enabled ⇒ Boolean
Whether ramp-up after idle is enabled.
-
#ramp_up_started_at ⇒ Time?
When the account started sending (for warmup calculation).
-
#typing_simulation ⇒ Boolean
Whether to auto-send "composing" presence before messages.
-
#warmup_delay_factor ⇒ Float
Extra delay multiplier applied during warmup (decays linearly).
-
#warmup_messages ⇒ Integer
Number of messages over which to ramp up after idle.
Webhook Security collapse
-
#webhook_secret ⇒ String?
HMAC-SHA256 secret for verifying webhook payloads.
Logging collapse
-
#log_level ⇒ Symbol
Log level (:debug, :info, :warn, :error, :fatal).
Heartbeat collapse
-
#heartbeat_enabled ⇒ Boolean
Whether periodic health checks are enabled.
-
#heartbeat_interval ⇒ Integer
Health check interval in seconds.
Message Handling collapse
-
#message_handler ⇒ Class, ...
Handler class for incoming messages (must respond to +.new.call(message, session:)+).
Instance Attribute Summary collapse
-
#safety_preset ⇒ Symbol
Current safety preset.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/whatsapp/configuration.rb', line 215 def initialize # Connection @auth_dir = default_auth_dir @log_path = $stdout @bridge_timeout = 15 @node_command = "node" @http_open_timeout = 5 @http_read_timeout = 10 @http_write_timeout = 10 @auto_reconnect = true @max_reconnect_attempts = 5 @reconnect_interval = 3 # Rate limiting — strict preset by default @rate_limiting_enabled = true @safety_preset = :strict apply_safety_preset!(:strict) # Webhook security @webhook_secret = nil # Logging @log_level = :info # Heartbeat @heartbeat_enabled = true @heartbeat_interval = 30 # seconds # Message handler @message_handler = nil end |
Instance Attribute Details
#auth_dir ⇒ String
Returns directory for storing WhatsApp auth state.
22 23 24 |
# File 'lib/whatsapp/configuration.rb', line 22 def auth_dir @auth_dir end |
#auto_presence_updates ⇒ Boolean
Returns whether to send presence updates (available/unavailable) on connect/disconnect.
109 110 111 |
# File 'lib/whatsapp/configuration.rb', line 109 def auto_presence_updates @auto_presence_updates end |
#auto_read_receipts ⇒ Boolean
Returns whether to auto-send read receipts for incoming messages.
105 106 107 |
# File 'lib/whatsapp/configuration.rb', line 105 def auto_read_receipts @auto_read_receipts end |
#auto_reconnect ⇒ Boolean
Returns whether to auto-reconnect on disconnect.
43 44 45 |
# File 'lib/whatsapp/configuration.rb', line 43 def auto_reconnect @auto_reconnect end |
#bridge_timeout ⇒ Integer
Returns seconds to wait for the bridge to become ready.
28 29 30 |
# File 'lib/whatsapp/configuration.rb', line 28 def bridge_timeout @bridge_timeout end |
#delay_jitter ⇒ Float
Returns maximum random jitter in seconds (gaussian distribution).
71 72 73 |
# File 'lib/whatsapp/configuration.rb', line 71 def delay_jitter @delay_jitter end |
#heartbeat_enabled ⇒ Boolean
Returns whether periodic health checks are enabled.
141 142 143 |
# File 'lib/whatsapp/configuration.rb', line 141 def heartbeat_enabled @heartbeat_enabled end |
#heartbeat_interval ⇒ Integer
Returns health check interval in seconds.
144 145 146 |
# File 'lib/whatsapp/configuration.rb', line 144 def heartbeat_interval @heartbeat_interval end |
#http_open_timeout ⇒ Integer
Returns HTTP open timeout in seconds for bridge requests.
34 35 36 |
# File 'lib/whatsapp/configuration.rb', line 34 def http_open_timeout @http_open_timeout end |
#http_read_timeout ⇒ Integer
Returns HTTP read timeout in seconds for bridge requests.
37 38 39 |
# File 'lib/whatsapp/configuration.rb', line 37 def http_read_timeout @http_read_timeout end |
#http_write_timeout ⇒ Integer
Returns HTTP write timeout in seconds for bridge requests.
40 41 42 |
# File 'lib/whatsapp/configuration.rb', line 40 def http_write_timeout @http_write_timeout end |
#idle_threshold ⇒ Float
Returns idle threshold in seconds — if no message sent for this long, the ramp-up warmup kicks in.
88 89 90 |
# File 'lib/whatsapp/configuration.rb', line 88 def idle_threshold @idle_threshold end |
#log_level ⇒ Symbol
Returns log level (:debug, :info, :warn, :error, :fatal).
134 135 136 |
# File 'lib/whatsapp/configuration.rb', line 134 def log_level @log_level end |
#log_path ⇒ String, IO
Returns log output path or IO object.
25 26 27 |
# File 'lib/whatsapp/configuration.rb', line 25 def log_path @log_path end |
#max_new_chats_per_day ⇒ Integer
Returns max new conversations initiated per day.
81 82 83 |
# File 'lib/whatsapp/configuration.rb', line 81 def max_new_chats_per_day @max_new_chats_per_day end |
#max_reconnect_attempts ⇒ Integer
Returns maximum number of reconnection attempts.
46 47 48 |
# File 'lib/whatsapp/configuration.rb', line 46 def max_reconnect_attempts @max_reconnect_attempts end |
#message_handler ⇒ Class, ...
Returns handler class for incoming messages (must respond to +.new.call(message, session:)+).
152 153 154 |
# File 'lib/whatsapp/configuration.rb', line 152 def @message_handler end |
#min_delay_between_messages ⇒ Float
Returns minimum delay between messages in seconds.
68 69 70 |
# File 'lib/whatsapp/configuration.rb', line 68 def @min_delay_between_messages end |
#node_command ⇒ String
Returns path to the Node.js binary.
31 32 33 |
# File 'lib/whatsapp/configuration.rb', line 31 def node_command @node_command end |
#post_connect_delay ⇒ Float
Returns delay in seconds before first message after connection.
84 85 86 |
# File 'lib/whatsapp/configuration.rb', line 84 def post_connect_delay @post_connect_delay end |
#ramp_up_days ⇒ Integer
Returns number of days for progressive account warmup. Day 1 = limits / ramp_up_days, linearly increasing to full limits. Set to 0 to disable.
114 115 116 |
# File 'lib/whatsapp/configuration.rb', line 114 def ramp_up_days @ramp_up_days end |
#ramp_up_enabled ⇒ Boolean
Returns whether ramp-up after idle is enabled.
97 98 99 |
# File 'lib/whatsapp/configuration.rb', line 97 def ramp_up_enabled @ramp_up_enabled end |
#ramp_up_started_at ⇒ Time?
Returns when the account started sending (for warmup calculation). Auto-set on first message if nil.
118 119 120 |
# File 'lib/whatsapp/configuration.rb', line 118 def ramp_up_started_at @ramp_up_started_at end |
#rate_limit_per_day ⇒ Integer
Returns max messages per day (global).
62 63 64 |
# File 'lib/whatsapp/configuration.rb', line 62 def rate_limit_per_day @rate_limit_per_day end |
#rate_limit_per_hour ⇒ Integer
Returns max messages per hour (global).
59 60 61 |
# File 'lib/whatsapp/configuration.rb', line 59 def rate_limit_per_hour @rate_limit_per_hour end |
#rate_limit_per_minute ⇒ Integer
Returns max messages per minute (global).
56 57 58 |
# File 'lib/whatsapp/configuration.rb', line 56 def rate_limit_per_minute @rate_limit_per_minute end |
#rate_limit_per_recipient_per_hour ⇒ Integer
Returns max messages per hour per recipient.
65 66 67 |
# File 'lib/whatsapp/configuration.rb', line 65 def rate_limit_per_recipient_per_hour @rate_limit_per_recipient_per_hour end |
#rate_limiting_enabled ⇒ Boolean
Returns whether rate limiting is enabled.
74 75 76 |
# File 'lib/whatsapp/configuration.rb', line 74 def rate_limiting_enabled @rate_limiting_enabled end |
#reconnect_interval ⇒ Integer
Returns base interval (seconds) between reconnection attempts.
49 50 51 |
# File 'lib/whatsapp/configuration.rb', line 49 def reconnect_interval @reconnect_interval end |
#safety_preset ⇒ Symbol
Returns current safety preset.
261 262 263 |
# File 'lib/whatsapp/configuration.rb', line 261 def safety_preset @safety_preset end |
#typing_simulation ⇒ Boolean
Returns whether to auto-send "composing" presence before messages. When enabled, send_message will automatically send a typing indicator proportional to the message length before actually sending.
102 103 104 |
# File 'lib/whatsapp/configuration.rb', line 102 def typing_simulation @typing_simulation end |
#warmup_delay_factor ⇒ Float
Returns extra delay multiplier applied during warmup (decays linearly).
94 95 96 |
# File 'lib/whatsapp/configuration.rb', line 94 def warmup_delay_factor @warmup_delay_factor end |
#warmup_messages ⇒ Integer
Returns number of messages over which to ramp up after idle.
91 92 93 |
# File 'lib/whatsapp/configuration.rb', line 91 def @warmup_messages end |
#webhook_secret ⇒ String?
Returns HMAC-SHA256 secret for verifying webhook payloads. When set, the bridge signs all WebSocket events and the Rails middleware rejects unsigned or invalid payloads.
127 128 129 |
# File 'lib/whatsapp/configuration.rb', line 127 def webhook_secret @webhook_secret end |