Chatwoot/app/models/channel/api.rb
Simon 91d9584fcb
feat: show HMAC and enforcement for identity validation for API inbox (#4807)
Display HMAC token in Settings of Inbox API and enable enforcement option. I have also adjusted the copy so that it can apply to all inbox types.

Fixes: #4804
2022-07-06 21:47:39 +02:00

47 lines
1.3 KiB
Ruby

# == Schema Information
#
# Table name: channel_api
#
# id :bigint not null, primary key
# additional_attributes :jsonb
# hmac_mandatory :boolean default(FALSE)
# hmac_token :string
# identifier :string
# webhook_url :string
# created_at :datetime not null
# updated_at :datetime not null
# account_id :integer not null
#
# Indexes
#
# index_channel_api_on_hmac_token (hmac_token) UNIQUE
# index_channel_api_on_identifier (identifier) UNIQUE
#
class Channel::Api < ApplicationRecord
include Channelable
self.table_name = 'channel_api'
EDITABLE_ATTRS = [:webhook_url, :hmac_mandatory, { additional_attributes: {} }].freeze
has_secure_token :identifier
has_secure_token :hmac_token
validate :ensure_valid_agent_reply_time_window
def name
'API'
end
def messaging_window_enabled?
additional_attributes.present? && additional_attributes['agent_reply_time_window'].present?
end
private
def ensure_valid_agent_reply_time_window
return if additional_attributes['agent_reply_time_window'].blank?
return if additional_attributes['agent_reply_time_window'].to_i.positive?
errors.add(:agent_reply_time_window, 'agent_reply_time_window must be greater than 0')
end
end