use webhook urls instead of encrypted configs

This commit is contained in:
Alex Turchyn
2024-10-28 20:39:09 +02:00
committed by Pete Matsyburka
parent f669045362
commit 84edb6dbda
50 changed files with 1350 additions and 269 deletions
@@ -14,21 +14,19 @@ class SendSubmissionCompletedWebhookRequestJob
attempt = params['attempt'].to_i
webhook_url = submission.account.webhook_urls.find(params['webhook_url_id'])
webhook_url = submission.account.webhook_urls.find_by(id: params['webhook_url_id'])
url = webhook_url.url if webhook_url.events.include?('submission.completed')
return if url.blank?
return unless webhook_url
return if webhook_url.url.blank? || webhook_url.events.exclude?('submission.completed')
resp = begin
Faraday.post(url,
Faraday.post(webhook_url.url,
{
event_type: 'submission.completed',
timestamp: Time.current,
data: Submissions::SerializeForApi.call(submission)
}.to_json,
**EncryptedConfig.find_or_initialize_by(account_id: submission.account_id,
key: EncryptedConfig::WEBHOOK_SECRET_KEY)&.value.to_h,
**webhook_url.secret.to_h,
'Content-Type' => 'application/json',
'User-Agent' => USER_AGENT)
rescue Faraday::Error