Module: WhatsAppNotifier

Defined in:
lib/whatsapp_notifier.rb,
lib/whatsapp_notifier/cli.rb,
lib/whatsapp_notifier/client.rb,
lib/whatsapp_notifier/doctor.rb,
lib/whatsapp_notifier/engine.rb,
lib/whatsapp_notifier/errors.rb,
lib/whatsapp_notifier/result.rb,
lib/whatsapp_notifier/railtie.rb,
lib/whatsapp_notifier/version.rb,
lib/whatsapp_notifier/error_code.rb,
lib/whatsapp_notifier/web_adapter.rb,
lib/whatsapp_notifier/notification.rb,
lib/whatsapp_notifier/configuration.rb,
lib/whatsapp_notifier/session/store.rb,
lib/whatsapp_notifier/providers/base.rb,
lib/whatsapp_notifier/bulk/dispatcher.rb,
lib/whatsapp_notifier/bulk/rate_limiter.rb,
lib/whatsapp_notifier/bulk/retry_policy.rb,
lib/whatsapp_notifier/session/qr_service.rb,
lib/whatsapp_notifier/jobs/send_message_job.rb,
lib/whatsapp_notifier/providers/web_automation.rb,
lib/generators/whatsapp_notifier/install_generator.rb,
app/controllers/whatsapp_notifier/messages_controller.rb,
app/controllers/whatsapp_notifier/sessions_controller.rb,
app/controllers/whatsapp_notifier/application_controller.rb,
lib/generators/whatsapp_notifier/install_service_generator.rb

Defined Under Namespace

Modules: Bulk, Doctor, ErrorCode, Generators, Jobs, Providers, Session Classes: ApplicationController, CLI, Client, Configuration, ConfigurationError, DeliveryError, Engine, Error, MessagesController, Notification, Railtie, Result, ServiceError, SessionsController, WebAdapter

Constant Summary collapse

VERSION =
"0.9.1"

Class Method Summary collapse

Class Method Details

.clientObject



40
41
42
# File 'lib/whatsapp_notifier.rb', line 40

def client
  @client ||= Client.new(configuration: configuration)
end

.configurationObject



31
32
33
# File 'lib/whatsapp_notifier.rb', line 31

def configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



21
22
23
24
25
# File 'lib/whatsapp_notifier.rb', line 21

def configure
  yield(configuration)
  configuration.validate!
  @client = Client.new(configuration: configuration)
end

.connection_status(provider: nil, metadata: {}) ⇒ Object



62
63
64
# File 'lib/whatsapp_notifier.rb', line 62

def connection_status(provider: nil, metadata: {})
  client.connection_status(provider: provider, metadata: )
end

.delete_media(message_id:, provider: nil, metadata: {}) ⇒ Object



84
85
86
# File 'lib/whatsapp_notifier.rb', line 84

def delete_media(message_id:, provider: nil, metadata: {})
  client.delete_media(message_id: message_id, provider: provider, metadata: )
end

.deliver(to:, body:, metadata: {}, provider: nil, idempotency_key: nil) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/whatsapp_notifier.rb', line 44

def deliver(to:, body:, metadata: {}, provider: nil, idempotency_key: nil)
  client.deliver(
    to: to,
    body: body,
    metadata: ,
    provider: provider,
    idempotency_key: idempotency_key
  )
end

.deliver_bulk(messages, provider: nil, sleeper: ->(seconds) { sleep(seconds) }, rng: Random.new) ⇒ Object



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

def deliver_bulk(messages, provider: nil, sleeper: ->(seconds) { sleep(seconds) }, rng: Random.new)
  client.deliver_bulk(messages, provider: provider, sleeper: sleeper, rng: rng)
end

.fetch_history(chat_id:, limit: 50, provider: nil, metadata: {}) ⇒ Object



96
97
98
# File 'lib/whatsapp_notifier.rb', line 96

def fetch_history(chat_id:, limit: 50, provider: nil, metadata: {})
  client.fetch_history(chat_id: chat_id, limit: limit, provider: provider, metadata: )
end

.fetch_inbound(provider: nil, metadata: {}) ⇒ Object



76
77
78
# File 'lib/whatsapp_notifier.rb', line 76

def fetch_inbound(provider: nil, metadata: {})
  client.fetch_inbound(provider: provider, metadata: )
end

.fetch_media(message_id:, provider: nil, metadata: {}) ⇒ Object



80
81
82
# File 'lib/whatsapp_notifier.rb', line 80

def fetch_media(message_id:, provider: nil, metadata: {})
  client.fetch_media(message_id: message_id, provider: provider, metadata: )
end

.list_chats(provider: nil, metadata: {}) ⇒ Object



92
93
94
# File 'lib/whatsapp_notifier.rb', line 92

def list_chats(provider: nil, metadata: {})
  client.list_chats(provider: provider, metadata: )
end

.logout(provider: nil, metadata: {}) ⇒ Object



100
101
102
# File 'lib/whatsapp_notifier.rb', line 100

def logout(provider: nil, metadata: {})
  client.logout(provider: provider, metadata: )
end

.refetch_media(message_id:, chat_id:, provider: nil, metadata: {}) ⇒ Object



88
89
90
# File 'lib/whatsapp_notifier.rb', line 88

def refetch_media(message_id:, chat_id:, provider: nil, metadata: {})
  client.refetch_media(message_id: message_id, chat_id: chat_id, provider: provider, metadata: )
end

.reset!Object



35
36
37
38
# File 'lib/whatsapp_notifier.rb', line 35

def reset!
  @configuration = Configuration.new
  @client = Client.new(configuration: @configuration)
end

.scan_qr(provider: nil, metadata: {}) ⇒ Object



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

def scan_qr(provider: nil, metadata: {})
  client.scan_qr(provider: provider, metadata: )
end

.service_pathObject



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

def service_path
  File.expand_path("whatsapp_notifier/services/web_automation", __dir__)
end

.session_ready?(user_id: nil, provider: nil, metadata: {}) ⇒ Boolean

One call for "can this operator send right now?" — an authenticated session answers true, everything else (including an unreachable status endpoint) answers false. user_id: is sugar for the metadata key every multi-user host passes; both forms work.

Returns:

  • (Boolean)


70
71
72
73
74
# File 'lib/whatsapp_notifier.rb', line 70

def session_ready?(user_id: nil, provider: nil, metadata: {})
  meta = .to_h
  meta = meta.merge(user_id: user_id) unless user_id.nil?
  client.session_ready?(provider: provider, metadata: meta)
end