add webhook events

This commit is contained in:
Alex Turchyn
2025-07-04 21:11:08 +03:00
committed by Pete Matsyburka
parent 1b60b42428
commit 988a5361a6
54 changed files with 825 additions and 160 deletions
+1
View File
@@ -33,6 +33,7 @@ class Account < ApplicationRecord
has_many :account_linked_accounts, dependent: :destroy
has_many :email_events, dependent: :destroy
has_many :webhook_urls, dependent: :destroy
has_many :webhook_events, dependent: nil
has_many :account_accesses, dependent: :destroy
has_many :account_testing_accounts, -> { testing }, dependent: :destroy,
class_name: 'AccountLinkedAccount',
+25
View File
@@ -0,0 +1,25 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: webhook_attempts
#
# id :bigint not null, primary key
# attempt :integer not null
# response_body :text
# response_status_code :integer not null
# created_at :datetime not null
# updated_at :datetime not null
# webhook_event_id :bigint not null
#
# Indexes
#
# index_webhook_attempts_on_webhook_event_id (webhook_event_id)
#
class WebhookAttempt < ApplicationRecord
belongs_to :webhook_event
def success?
response_status_code.to_i / 100 == 2
end
end
+32
View File
@@ -0,0 +1,32 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: webhook_events
#
# id :bigint not null, primary key
# event_type :string not null
# record_type :string not null
# status :string not null
# uuid :string not null
# created_at :datetime not null
# updated_at :datetime not null
# account_id :bigint not null
# record_id :bigint not null
# webhook_url_id :bigint not null
#
# Indexes
#
# index_webhook_events_error (webhook_url_id,id) WHERE ((status)::text = 'error'::text)
# index_webhook_events_on_uuid_and_webhook_url_id (uuid,webhook_url_id) UNIQUE
# index_webhook_events_on_webhook_url_id_and_id (webhook_url_id,id)
#
class WebhookEvent < ApplicationRecord
attribute :uuid, :string, default: -> { SecureRandom.uuid }
belongs_to :webhook_url, optional: true
belongs_to :account, optional: true
belongs_to :record, polymorphic: true, optional: true
has_many :webhook_attempts, dependent: nil
end
+1
View File
@@ -37,6 +37,7 @@ class WebhookUrl < ApplicationRecord
].freeze
belongs_to :account
has_many :webhook_events, dependent: nil
attribute :events, :string, default: -> { %w[form.viewed form.started form.completed form.declined] }
attribute :secret, :string, default: -> { {} }