feat: Customizable webhook timeout configuration (#12777)

## Summary
- Ability to configure the webhook timeout for Chatwoot self hosted
installations

fixes: https://github.com/chatwoot/chatwoot/issues/12754
This commit is contained in:
Sojan Jose
2025-11-17 14:43:23 -08:00
committed by GitHub
parent bf806f0c28
commit 5b56f64838
4 changed files with 61 additions and 8 deletions

View File

@@ -13,9 +13,12 @@ describe Webhooks::Trigger do
let(:webhook_type) { :api_inbox_webhook }
let!(:url) { 'https://test.com' }
let(:agent_bot_error_content) { I18n.t('conversations.activity.agent_bot.error_moved_to_open') }
let(:default_timeout) { 5 }
let(:webhook_timeout) { default_timeout }
before do
ActiveJob::Base.queue_adapter = :test
allow(GlobalConfig).to receive(:get_value).with('WEBHOOK_TIMEOUT').and_return(webhook_timeout)
end
after do
@@ -33,7 +36,7 @@ describe Webhooks::Trigger do
url: url,
payload: payload.to_json,
headers: { content_type: :json, accept: :json },
timeout: 5
timeout: webhook_timeout
).once
trigger.execute(url, payload, webhook_type)
end
@@ -47,7 +50,7 @@ describe Webhooks::Trigger do
url: url,
payload: payload.to_json,
headers: { content_type: :json, accept: :json },
timeout: 5
timeout: webhook_timeout
).and_raise(RestClient::ExceptionWithResponse.new('error', 500)).once
expect { trigger.execute(url, payload, webhook_type) }.to change { message.reload.status }.from('sent').to('failed')
@@ -62,7 +65,7 @@ describe Webhooks::Trigger do
url: url,
payload: payload.to_json,
headers: { content_type: :json, accept: :json },
timeout: 5
timeout: webhook_timeout
).and_raise(RestClient::ExceptionWithResponse.new('error', 500)).once
expect { trigger.execute(url, payload, webhook_type) }.to change { message.reload.status }.from('sent').to('failed')
end
@@ -80,7 +83,7 @@ describe Webhooks::Trigger do
url: url,
payload: payload.to_json,
headers: { content_type: :json, accept: :json },
timeout: 5
timeout: webhook_timeout
).and_raise(RestClient::ExceptionWithResponse.new('error', 500)).once
expect do
@@ -105,7 +108,7 @@ describe Webhooks::Trigger do
url: url,
payload: payload.to_json,
headers: { content_type: :json, accept: :json },
timeout: 5
timeout: webhook_timeout
).and_raise(RestClient::ExceptionWithResponse.new('error', 500)).once
expect do
@@ -128,9 +131,47 @@ describe Webhooks::Trigger do
url: url,
payload: payload.to_json,
headers: { content_type: :json, accept: :json },
timeout: 5
timeout: webhook_timeout
).and_raise(RestClient::ExceptionWithResponse.new('error', 500)).once
expect { trigger.execute(url, payload, webhook_type) }.not_to(change { message.reload.status })
end
context 'when webhook timeout configuration is blank' do
let(:webhook_timeout) { nil }
it 'falls back to default timeout' do
payload = { hello: :hello }
expect(RestClient::Request).to receive(:execute)
.with(
method: :post,
url: url,
payload: payload.to_json,
headers: { content_type: :json, accept: :json },
timeout: default_timeout
).once
trigger.execute(url, payload, webhook_type)
end
end
context 'when webhook timeout configuration is invalid' do
let(:webhook_timeout) { -1 }
it 'falls back to default timeout' do
payload = { hello: :hello }
expect(RestClient::Request).to receive(:execute)
.with(
method: :post,
url: url,
payload: payload.to_json,
headers: { content_type: :json, accept: :json },
timeout: default_timeout
).once
trigger.execute(url, payload, webhook_type)
end
end
end