* chore: skip notification messages * feat: contact card messages * fix: notification message handling * chore: reduce code duplication * fix: improve contact name handling in attachment * chore(zapi): promo banner with affiliate link (#126) * chore(zapi): promo banner with affiliate link * chore: remove useless comment * chore(zapi): add note about hardcoded affiliate link * feat: provider.event_received for raw provider events (#127) * chore(zapi): promo banner with affiliate link * chore: remove useless comment * feat: provider.event_received for raw provider events * feat: add provider_event_received handling in webhook listener * feat(baileys): use senderLid as contact identifier (#128) * chore(zapi): promo banner with affiliate link * chore: remove useless comment * feat: provider.event_received for raw provider events * feat(baileys): use senderLid as contact identifier * fix: simplify webhook_data method by removing unnecessary fields
26 lines
1.1 KiB
Ruby
26 lines
1.1 KiB
Ruby
class Whatsapp::IncomingMessageBaileysService < Whatsapp::IncomingMessageBaseService
|
|
include Events::Types
|
|
include Whatsapp::BaileysHandlers::ConnectionUpdate
|
|
include Whatsapp::BaileysHandlers::MessagesUpsert
|
|
include Whatsapp::BaileysHandlers::MessagesUpdate
|
|
|
|
class InvalidWebhookVerifyToken < StandardError; end
|
|
|
|
def perform # rubocop:disable Metrics/AbcSize
|
|
raise InvalidWebhookVerifyToken if processed_params[:webhookVerifyToken] != inbox.channel.provider_config['webhook_verify_token']
|
|
return if processed_params[:event].blank? || processed_params[:data].blank?
|
|
|
|
Rails.configuration.dispatcher.dispatch(PROVIDER_EVENT_RECEIVED, Time.zone.now, inbox: inbox, event: processed_params[:event],
|
|
payload: processed_params[:data])
|
|
|
|
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
|