iachat/app/services/whatsapp/incoming_message_baileys_service.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

22 lines
866 B
Ruby

class Whatsapp::IncomingMessageBaileysService < Whatsapp::IncomingMessageBaseService
include Whatsapp::BaileysHandlers::ConnectionUpdate
include Whatsapp::BaileysHandlers::MessagesUpsert
include Whatsapp::BaileysHandlers::MessagesUpdate
class InvalidWebhookVerifyToken < StandardError; end
def perform
raise InvalidWebhookVerifyToken if processed_params[:webhookVerifyToken] != inbox.channel.provider_config['webhook_verify_token']
return if processed_params[:event].blank? || processed_params[:data].blank?
event_prefix = processed_params[:event].gsub(/[\.-]/, '_')
method_name = "process_#{event_prefix}"
if respond_to?(method_name, true)
# TODO: Implement the methods for all expected events
send(method_name)
else
Rails.logger.warn "Baileys unsupported event: #{processed_params[:event]}"
end
end
end