Resolves 26 conflicts via manual review. Key decisions: - signature: kept fork's send-time architecture (PR #79), discarded upstream's editor-manipulation functions - WhatsApp incoming: combined fork's two-layer locking (source_id + contact phone) with upstream's blocked-contact drop. Fixed pre-existing regression where echoes were silently dropped - InstallationConfig: upstream's simplified coder (validated against legacy YAML-in-jsonb data) - schema.rb: regenerated, stripped kanban tables from other branches, restored f_unaccent SQL function
49 lines
1.8 KiB
Ruby
49 lines
1.8 KiB
Ruby
# == Schema Information
|
|
#
|
|
# Table name: webhooks
|
|
#
|
|
# id :bigint not null, primary key
|
|
# name :string
|
|
# secret :string
|
|
# subscriptions :jsonb
|
|
# url :text
|
|
# webhook_type :integer default("account_type")
|
|
# created_at :datetime not null
|
|
# updated_at :datetime not null
|
|
# account_id :integer
|
|
# inbox_id :integer
|
|
#
|
|
# Indexes
|
|
#
|
|
# index_webhooks_on_account_id_and_url (account_id,url) UNIQUE
|
|
#
|
|
|
|
class Webhook < ApplicationRecord
|
|
belongs_to :account
|
|
belongs_to :inbox, optional: true
|
|
|
|
include WebhookSecretable
|
|
|
|
validates :account_id, presence: true
|
|
validates :url, uniqueness: { scope: [:account_id] }, format: URI::DEFAULT_PARSER.make_regexp(%w[http https])
|
|
validate :validate_webhook_subscriptions
|
|
enum webhook_type: { account_type: 0, inbox_type: 1 }
|
|
|
|
ALLOWED_WEBHOOK_EVENTS = %w[conversation_status_changed conversation_updated conversation_created contact_created contact_updated
|
|
message_created message_incoming message_outgoing message_updated webwidget_triggered
|
|
inbox_created inbox_updated conversation_typing_on conversation_typing_off conversation_recording
|
|
provider_event_received internal_chat_message_created internal_chat_message_updated
|
|
internal_chat_message_deleted internal_chat_channel_updated].freeze
|
|
|
|
private
|
|
|
|
def validate_webhook_subscriptions
|
|
invalid_subscriptions = !subscriptions.instance_of?(Array) ||
|
|
subscriptions.blank? ||
|
|
(subscriptions.uniq - ALLOWED_WEBHOOK_EVENTS).length.positive?
|
|
errors.add(:subscriptions, I18n.t('errors.webhook.invalid')) if invalid_subscriptions
|
|
end
|
|
end
|
|
|
|
Webhook.include_mod_with('Audit::Webhook')
|