mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-11-03 20:48:07 +00:00 
			
		
		
		
	Added support for typing events in webhooks. Two new events are now available: `conversation_typing_on` and `conversation_typing_off`. <img width="746" alt="Screenshot 2025-05-08 at 4 50 24 PM" src="https://github.com/user-attachments/assets/62da7b38-de0f-42c5-84f4-066e653da331" /> --------- Co-authored-by: Pranav <pranav@chatwoot.com> Co-authored-by: Pranav <pranavrajs@gmail.com>
		
			
				
	
	
		
			43 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
# == Schema Information
 | 
						|
#
 | 
						|
# Table name: webhooks
 | 
						|
#
 | 
						|
#  id            :bigint           not null, primary key
 | 
						|
#  subscriptions :jsonb
 | 
						|
#  url           :string
 | 
						|
#  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')
 |