Some checks failed
Lock Threads / action (push) Has been cancelled
Mark stale issues and pull requests / stale (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot EE docker images / merge (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot CE docker images / merge (push) Has been cancelled
Run Chatwoot CE spec / lint-backend (push) Has been cancelled
Run Chatwoot CE spec / lint-frontend (push) Has been cancelled
Run Chatwoot CE spec / frontend-tests (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (0, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (1, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (10, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (11, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (12, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (13, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (14, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (15, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (2, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (3, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (4, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (5, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (6, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (7, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (8, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (9, 16) (push) Has been cancelled
Run Linux nightly installer / nightly (push) Has been cancelled
- Add Logistics component with progress tracking - Add OrderDetail component for order information - Support data-driven steps and actions - Add blue color scale to widget SCSS - Fix node overflow and progress bar rendering issues - Add English translations for dashboard components Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
88 lines
2.2 KiB
Ruby
88 lines
2.2 KiB
Ruby
class Webhooks::Trigger
|
|
SUPPORTED_ERROR_HANDLE_EVENTS = %w[message_created message_updated].freeze
|
|
|
|
def initialize(url, payload, webhook_type, user_token = nil)
|
|
@url = url
|
|
@payload = payload
|
|
@webhook_type = webhook_type
|
|
@user_token = user_token
|
|
end
|
|
|
|
def self.execute(url, payload, webhook_type, user_token = nil)
|
|
new(url, payload, webhook_type, user_token).execute
|
|
end
|
|
|
|
def execute
|
|
perform_request
|
|
rescue StandardError => e
|
|
handle_error(e)
|
|
Rails.logger.warn "Exception: Invalid webhook URL #{@url} : #{e.message}"
|
|
end
|
|
|
|
private
|
|
|
|
def perform_request
|
|
headers = { content_type: :json, accept: :json }
|
|
headers[:cookie] = "token=#{@user_token}" if @user_token.present?
|
|
|
|
RestClient::Request.execute(
|
|
method: :post,
|
|
url: @url,
|
|
payload: @payload.to_json,
|
|
headers: headers,
|
|
timeout: webhook_timeout
|
|
)
|
|
end
|
|
|
|
def handle_error(error)
|
|
return unless SUPPORTED_ERROR_HANDLE_EVENTS.include?(@payload[:event])
|
|
return unless message
|
|
|
|
case @webhook_type
|
|
when :agent_bot_webhook
|
|
conversation = message.conversation
|
|
return unless conversation&.pending?
|
|
|
|
conversation.open!
|
|
create_agent_bot_error_activity(conversation)
|
|
when :api_inbox_webhook
|
|
update_message_status(error)
|
|
end
|
|
end
|
|
|
|
def create_agent_bot_error_activity(conversation)
|
|
content = I18n.t('conversations.activity.agent_bot.error_moved_to_open')
|
|
Conversations::ActivityMessageJob.perform_later(conversation, activity_message_params(conversation, content))
|
|
end
|
|
|
|
def activity_message_params(conversation, content)
|
|
{
|
|
account_id: conversation.account_id,
|
|
inbox_id: conversation.inbox_id,
|
|
message_type: :activity,
|
|
content: content
|
|
}
|
|
end
|
|
|
|
def update_message_status(error)
|
|
Messages::StatusUpdateService.new(message, 'failed', error.message).perform
|
|
end
|
|
|
|
def message
|
|
return if message_id.blank?
|
|
|
|
@message ||= Message.find_by(id: message_id)
|
|
end
|
|
|
|
def message_id
|
|
@payload[:id]
|
|
end
|
|
|
|
def webhook_timeout
|
|
raw_timeout = GlobalConfig.get_value('WEBHOOK_TIMEOUT')
|
|
timeout = raw_timeout.presence&.to_i
|
|
|
|
timeout&.positive? ? timeout : 5
|
|
end
|
|
end
|