2020-07-21 06:45:24 +00:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: channel_api
|
|
|
|
#
|
2022-06-10 13:10:29 +00:00
|
|
|
# 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
|
2021-06-15 14:39:17 +00:00
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
|
|
|
# index_channel_api_on_hmac_token (hmac_token) UNIQUE
|
|
|
|
# index_channel_api_on_identifier (identifier) UNIQUE
|
2020-07-21 06:45:24 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
class Channel::Api < ApplicationRecord
|
2021-09-10 20:01:17 +00:00
|
|
|
include Channelable
|
|
|
|
|
2020-07-21 06:45:24 +00:00
|
|
|
self.table_name = 'channel_api'
|
2022-07-06 19:47:39 +00:00
|
|
|
EDITABLE_ATTRS = [:webhook_url, :hmac_mandatory, { additional_attributes: {} }].freeze
|
2020-07-21 06:45:24 +00:00
|
|
|
|
2021-06-15 14:39:17 +00:00
|
|
|
has_secure_token :identifier
|
|
|
|
has_secure_token :hmac_token
|
2022-06-14 12:35:37 +00:00
|
|
|
validate :ensure_valid_agent_reply_time_window
|
2021-06-15 14:39:17 +00:00
|
|
|
|
2020-09-04 13:43:47 +00:00
|
|
|
def name
|
|
|
|
'API'
|
|
|
|
end
|
2022-06-14 12:35:37 +00:00
|
|
|
|
|
|
|
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
|
2020-07-21 06:45:24 +00:00
|
|
|
end
|