iachat/app/services/whatsapp/baileys_handlers/connection_update.rb
Cayo P. R. Oliveira 76deea996d
chore: refactor incoming_message_baileys_service using composition and fix some failure points (#53)
* feat: implement connection update handling for Baileys

* feat: add message update handling for Baileys integration

* feat: implement message processing and handling for Baileys integration

* fix: clear message source ID from Redis when contact is not found

* fix: raise error when attachment file is not found during media handling

* refactor: reorganize includes in incoming_message_baileys_service

* feat: add helper methods for message handling in Baileys integration

* feat: include IncomingMessageServiceHelpers in MessagesUpdate module

* refactor: replace IncomingMessageServiceHelpers with BaileysHandlers::Helpers in connection_update, messages_update, and messages_upsert modules

* fix: mark message as unsupported when attachment file is not found

* refactor: remove unnecessary namespace for includes in IncomingMessageBaileysService

* refactor: add private visibility to methods in connection_update, helpers, messages_update, and messages_upsert modules

* refactor: preserve original message in handle_edited_content method

* fix: attachment error handling

* feat: implement conversation creation logic in set_conversation method

* refactor: remove unused error handling for attachment not found in messages update and upsert

* feat: update last seen timestamps in conversation on message status update

* feat: log warning for unsupported message update status in Baileys service

* chore: merge

---------

Co-authored-by: gabrieljablonski <contact@gabrieljablonski.com>
2025-05-29 10:56:39 -03:00

23 lines
985 B
Ruby

module Whatsapp::BaileysHandlers::ConnectionUpdate
include Whatsapp::BaileysHandlers::Helpers
private
def process_connection_update
data = processed_params[:data]
# NOTE: `connection` values
# - `close`: Never opened, or closed and no longer able to send/receive messages
# - `connecting`: In the process of connecting, expecting QR code to be read
# - `reconnecting`: Connection has been established, but not open (i.e. device is being linked for the first time, or Baileys server restart)
# - `open`: Open and ready to send/receive messages
inbox.channel.update_provider_connection!({
connection: data[:connection] || inbox.channel.provider_connection['connection'],
qr_data_url: data[:qrDataUrl] || nil,
error: data[:error] ? I18n.t("errors.inboxes.channel.provider_connection.#{data[:error]}") : nil
}.compact)
Rails.logger.error "Baileys connection error: #{data[:error]}" if data[:error].present?
end
end