Files
leadchat/app/models/webhook.rb
Tanmay Deep Sharma e58600d1b9 fix: the webhook url to be text (#13157)
## Description
Change the url type from string to text, to support more than 255
characters

Fixes # (issue)
https://app.chatwoot.com/app/accounts/1/conversations/65240

## Type of change

Please delete options that are not relevant.

- [ ] Bug fix (non-breaking change which fixes an issue)


## Checklist:

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
- [ ] I have commented on my code, particularly in hard-to-understand
areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream
modules
2026-01-06 15:23:54 +05:30

44 lines
1.5 KiB
Ruby

# == Schema Information
#
# Table name: webhooks
#
# id :bigint not null, primary key
# name :string
# subscriptions :jsonb
# url :text
# webhook_type :integer default("account_type")
# created_at :datetime not null
# updated_at :datetime not null
# account_id :integer
# inbox_id :integer
#
# Indexes
#
# index_webhooks_on_account_id_and_url (account_id,url) UNIQUE
#
class Webhook < ApplicationRecord
belongs_to :account
belongs_to :inbox, optional: true
validates :account_id, presence: true
validates :url, uniqueness: { scope: [:account_id] }, format: URI::DEFAULT_PARSER.make_regexp(%w[http https])
validate :validate_webhook_subscriptions
enum webhook_type: { account_type: 0, inbox_type: 1 }
ALLOWED_WEBHOOK_EVENTS = %w[conversation_status_changed conversation_updated conversation_created contact_created contact_updated
message_created message_updated webwidget_triggered inbox_created inbox_updated
conversation_typing_on conversation_typing_off].freeze
private
def validate_webhook_subscriptions
invalid_subscriptions = !subscriptions.instance_of?(Array) ||
subscriptions.blank? ||
(subscriptions.uniq - ALLOWED_WEBHOOK_EVENTS).length.positive?
errors.add(:subscriptions, I18n.t('errors.webhook.invalid')) if invalid_subscriptions
end
end
Webhook.include_mod_with('Audit::Webhook')