feat: Remove restrictions on API channel webhook_url (#2261)
This commit is contained in:
parent
35f8d01a0c
commit
836b317b8a
6 changed files with 50 additions and 8 deletions
|
@ -56,7 +56,8 @@ import { required } from 'vuelidate/lib/validators';
|
|||
import router from '../../../../index';
|
||||
import PageHeader from '../../SettingsSubPageHeader';
|
||||
|
||||
const shouldBeWebhookUrl = (value = '') => value.startsWith('http');
|
||||
const shouldBeWebhookUrl = (value = '') =>
|
||||
value ? value.startsWith('http') : true;
|
||||
|
||||
export default {
|
||||
components: {
|
||||
|
@ -76,7 +77,7 @@ export default {
|
|||
},
|
||||
validations: {
|
||||
channelName: { required },
|
||||
webhookUrl: { required, shouldBeWebhookUrl },
|
||||
webhookUrl: { shouldBeWebhookUrl },
|
||||
},
|
||||
methods: {
|
||||
async createChannel() {
|
||||
|
|
|
@ -59,7 +59,9 @@ class WebhookListener < BaseListener
|
|||
WebhookJob.perform_later(webhook.url, payload)
|
||||
end
|
||||
|
||||
# Deliver for API Inbox
|
||||
WebhookJob.perform_later(inbox.channel.webhook_url, payload) if inbox.channel_type == 'Channel::Api'
|
||||
return unless inbox.channel_type == 'Channel::Api'
|
||||
return if inbox.channel.webhook_url.blank?
|
||||
|
||||
WebhookJob.perform_later(inbox.channel.webhook_url, payload)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
# Table name: channel_api
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# webhook_url :string not null
|
||||
# webhook_url :string
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# account_id :integer not null
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class RemoveNotNullFromWebhookUrlChannelApi < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
change_column :channel_api, :webhook_url, :string, null: true
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2021_04_30_100138) do
|
||||
ActiveRecord::Schema.define(version: 2021_05_13_083044) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pg_stat_statements"
|
||||
|
@ -139,7 +139,7 @@ ActiveRecord::Schema.define(version: 2021_04_30_100138) do
|
|||
|
||||
create_table "channel_api", force: :cascade do |t|
|
||||
t.integer "account_id", null: false
|
||||
t.string "webhook_url", null: false
|
||||
t.string "webhook_url"
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@ describe WebhookListener do
|
|||
let!(:event) { Events::Base.new(event_name, Time.zone.now, message: message) }
|
||||
|
||||
describe '#message_created' do
|
||||
let(:event_name) { :'conversation.created' }
|
||||
let(:event_name) { :'message.created' }
|
||||
|
||||
context 'when webhook is not configured' do
|
||||
it 'does not trigger webhook' do
|
||||
|
@ -29,5 +29,39 @@ describe WebhookListener do
|
|||
listener.message_created(event)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when inbox is an API Channel' do
|
||||
it 'triggers webhook if webhook_url is present' do
|
||||
channel_api = create(:channel_api, account: account)
|
||||
api_inbox = channel_api.inbox
|
||||
api_conversation = create(:conversation, account: account, inbox: api_inbox, assignee: user)
|
||||
api_message = create(
|
||||
:message,
|
||||
message_type: 'outgoing',
|
||||
account: account,
|
||||
inbox: api_inbox,
|
||||
conversation: api_conversation
|
||||
)
|
||||
api_event = Events::Base.new(event_name, Time.zone.now, message: api_message)
|
||||
expect(WebhookJob).to receive(:perform_later).with(channel_api.webhook_url, api_message.webhook_data.merge(event: 'message_created')).once
|
||||
listener.message_created(api_event)
|
||||
end
|
||||
|
||||
it 'does not trigger webhook if webhook_url is not present' do
|
||||
channel_api = create(:channel_api, webhook_url: nil, account: account)
|
||||
api_inbox = channel_api.inbox
|
||||
api_conversation = create(:conversation, account: account, inbox: api_inbox, assignee: user)
|
||||
api_message = create(
|
||||
:message,
|
||||
message_type: 'outgoing',
|
||||
account: account,
|
||||
inbox: channel_api.inbox,
|
||||
conversation: api_conversation
|
||||
)
|
||||
api_event = Events::Base.new(event_name, Time.zone.now, message: api_message)
|
||||
expect(WebhookJob).not_to receive(:perform_later)
|
||||
listener.message_created(api_event)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue