mirror of
https://github.com/docusealco/docuseal.git
synced 2026-08-07 07:14:43 +00:00
add started and viewed webhook events
This commit is contained in:
@@ -9,6 +9,8 @@ module Api
|
||||
|
||||
SubmissionEvents.create_with_tracking_data(submitter, 'view_form', request)
|
||||
|
||||
SendFormViewedWebhookRequestJob.perform_later(submitter)
|
||||
|
||||
render json: {}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -18,7 +18,7 @@ class WebhookSettingsController < ApplicationController
|
||||
def update
|
||||
submitter = current_account.submitters.where.not(completed_at: nil).order(:id).last
|
||||
|
||||
SendWebhookRequestJob.perform_later(submitter)
|
||||
SendFormCompletedWebhookRequestJob.perform_later(submitter)
|
||||
|
||||
redirect_back(fallback_location: settings_webhooks_path, notice: 'Webhook request has been sent.')
|
||||
end
|
||||
|
||||
@@ -11,7 +11,7 @@ class ProcessSubmitterCompletionJob < ApplicationJob
|
||||
Submissions::EnsureResultGenerated.call(submitter)
|
||||
|
||||
if submitter.account.encrypted_configs.exists?(key: EncryptedConfig::WEBHOOK_URL_KEY)
|
||||
SendWebhookRequestJob.perform_later(submitter)
|
||||
SendFormCompletedWebhookRequestJob.perform_later(submitter)
|
||||
end
|
||||
|
||||
return unless is_all_completed
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SendWebhookRequestJob < ApplicationJob
|
||||
class SendFormCompletedWebhookRequestJob < ApplicationJob
|
||||
USER_AGENT = 'DocuSeal.co Webhook'
|
||||
|
||||
def perform(submitter)
|
||||
@@ -14,7 +14,7 @@ class SendWebhookRequestJob < ApplicationJob
|
||||
|
||||
Faraday.post(config.value,
|
||||
{
|
||||
event_type: 'form.submitted',
|
||||
event_type: 'form.completed',
|
||||
timestamp: Time.current.iso8601,
|
||||
data: Submitters::SerializeForWebhook.call(submitter)
|
||||
}.to_json,
|
||||
@@ -0,0 +1,22 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SendFormStartedWebhookRequestJob < ApplicationJob
|
||||
USER_AGENT = 'DocuSeal.co Webhook'
|
||||
|
||||
def perform(submitter)
|
||||
config = submitter.submission.account.encrypted_configs.find_by(key: EncryptedConfig::WEBHOOK_URL_KEY)
|
||||
|
||||
return if config.blank? || config.value.blank?
|
||||
|
||||
ActiveStorage::Current.url_options = Docuseal.default_url_options
|
||||
|
||||
Faraday.post(config.value,
|
||||
{
|
||||
event_type: 'form.started',
|
||||
timestamp: Time.current.iso8601,
|
||||
data: Submitters::SerializeForWebhook.call(submitter)
|
||||
}.to_json,
|
||||
'Content-Type' => 'application/json',
|
||||
'User-Agent' => USER_AGENT)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,22 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SendFormViewedWebhookRequestJob < ApplicationJob
|
||||
USER_AGENT = 'DocuSeal.co Webhook'
|
||||
|
||||
def perform(submitter)
|
||||
config = submitter.submission.account.encrypted_configs.find_by(key: EncryptedConfig::WEBHOOK_URL_KEY)
|
||||
|
||||
return if config.blank? || config.value.blank?
|
||||
|
||||
ActiveStorage::Current.url_options = Docuseal.default_url_options
|
||||
|
||||
Faraday.post(config.value,
|
||||
{
|
||||
event_type: 'form.viewed',
|
||||
timestamp: Time.current.iso8601,
|
||||
data: Submitters::SerializeForWebhook.call(submitter)
|
||||
}.to_json,
|
||||
'Content-Type' => 'application/json',
|
||||
'User-Agent' => USER_AGENT)
|
||||
end
|
||||
end
|
||||
@@ -30,7 +30,7 @@
|
||||
<div class="collapse-content" style="display: inherit">
|
||||
<div class="mockup-code overflow-hidden relative">
|
||||
<span class="top-0 right-0 absolute">
|
||||
<%= render 'shared/clipboard_copy', icon: 'copy', text: code = JSON.pretty_generate({ event_type: 'form.submitted', timestamp: Time.current.iso8601, data: Submitters::SerializeForWebhook.call(submitter) }).gsub(/^/, ' ').sub(/^\s+/, ''), class: 'btn btn-ghost text-white', icon_class: 'w-6 h-6 text-white', copy_title: 'Copy', copied_title: 'Copied' %>
|
||||
<%= render 'shared/clipboard_copy', icon: 'copy', text: code = JSON.pretty_generate({ event_type: 'form.completed', timestamp: Time.current.iso8601, data: Submitters::SerializeForWebhook.call(submitter) }).gsub(/^/, ' ').sub(/^\s+/, ''), class: 'btn btn-ghost text-white', icon_class: 'w-6 h-6 text-white', copy_title: 'Copy', copied_title: 'Copied' %>
|
||||
</span>
|
||||
<pre><code class="overflow-hidden w-full"><%= code %></code></pre>
|
||||
</div>
|
||||
|
||||
@@ -18,7 +18,8 @@ module Submitters
|
||||
end
|
||||
|
||||
def build_values_array(submitter)
|
||||
fields_index = submitter.submission.template_fields.index_by { |e| e['uuid'] }
|
||||
fields_index = (submitter.submission.template_fields ||
|
||||
submitter.submission.template.fields).index_by { |e| e['uuid'] }
|
||||
attachments_index = submitter.attachments.preload(:blob).index_by(&:uuid)
|
||||
submitter_field_counters = Hash.new { 0 }
|
||||
|
||||
|
||||
@@ -7,10 +7,12 @@ module Submitters
|
||||
module_function
|
||||
|
||||
def call(submitter, params, request)
|
||||
if submitter.submission.template_fields.blank?
|
||||
Submissions.update_template_fields!(submitter.submission)
|
||||
Submissions.update_template_fields!(submitter.submission) if submitter.submission.template_fields.blank?
|
||||
|
||||
unless submitter.submission_events.exists?(event_type: 'start_form')
|
||||
SubmissionEvents.create_with_tracking_data(submitter, 'start_form', request)
|
||||
|
||||
SendFormStartedWebhookRequestJob.perform_later(submitter)
|
||||
end
|
||||
|
||||
update_submitter!(submitter, params, request)
|
||||
|
||||
Reference in New Issue
Block a user