Class: WhatsAppNotifier::SessionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/whatsapp_notifier/sessions_controller.rb

Instance Method Summary collapse

Instance Method Details

#qrObject

GET /qr — the latest QR for the current user (nil while initializing)



13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/whatsapp_notifier/sessions_controller.rb', line 13

def qr
  qr_code = WhatsAppNotifier.scan_qr(metadata: )
  if qr_code
    render json: { qr: qr_code }
  else
    render json: { error: "No QR available" }, status: :not_found
  end
rescue StandardError => e
  render json: { error: "Failed to fetch QR: #{e.message}" },
         status: :internal_server_error
end

#showObject

GET /status — connection state for the current user



4
5
6
7
8
9
10
# File 'app/controllers/whatsapp_notifier/sessions_controller.rb', line 4

def show
  data = WhatsAppNotifier.connection_status(metadata: )
  render json: data.merge(hasQR: data[:has_qr])
rescue StandardError => e
  render json: { error: "Failed to fetch status: #{e.message}" },
         status: :internal_server_error
end