iachat/lib/webhooks/trigger.rb
Pranav 8f95fafff4
feat: Add a setting to keep conversations pending on bot failures (#13512)
Adds an account-level setting `keep_pending_on_bot_failure` to control
whether conversations should move from pending to open when agent bot
webhooks fail.

Some users experience occasional message drops and don't want
conversations to automatically reopen due to transient bot failures.
This setting gives accounts control over that behavior. This is a
temporary setting which will be removed in future once a proper fix for
it is done, so it is not added in the UI.
2026-02-10 17:27:42 -08:00

38 lines
886 B
Ruby

class Webhooks::Trigger
def initialize(url, payload, webhook_type)
@url = url
@payload = payload
@webhook_type = webhook_type
end
def self.execute(url, payload, webhook_type)
new(url, payload, webhook_type).execute
end
def execute
perform_request
rescue StandardError => e
Rails.logger.warn "Webhook request failed for #{@url}: #{e.message}"
raise CustomExceptions::Webhook::RetriableError, "Webhook request failed: #{e.message}"
end
private
def perform_request
RestClient::Request.execute(
method: :post,
url: @url,
payload: @payload.to_json,
headers: { content_type: :json, accept: :json },
timeout: webhook_timeout
)
end
def webhook_timeout
raw_timeout = GlobalConfig.get_value('WEBHOOK_TIMEOUT')
timeout = raw_timeout.presence&.to_i
timeout&.positive? ? timeout : 5
end
end