Routine weeding of the codebase (#163)
* Routine weeding of the codebase * fix the spec
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
class Channel < ApplicationRecord
|
||||
has_many :conversations
|
||||
end
|
||||
26
app/models/channel/facebook_page.rb
Normal file
26
app/models/channel/facebook_page.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
module Channel
|
||||
class FacebookPage < ApplicationRecord
|
||||
self.table_name = 'channel_facebook_pages'
|
||||
|
||||
validates :account_id, presence: true
|
||||
validates_uniqueness_of :page_id, scope: :account_id
|
||||
mount_uploader :avatar, AvatarUploader
|
||||
belongs_to :account
|
||||
|
||||
has_one :inbox, as: :channel, dependent: :destroy
|
||||
|
||||
before_destroy :unsubscribe
|
||||
|
||||
def name
|
||||
`Facebook`
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def unsubscribe
|
||||
Facebook::Messenger::Subscriptions.unsubscribe(access_token: page_access_token)
|
||||
rescue => e
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
8
app/models/channel/web_widget.rb
Normal file
8
app/models/channel/web_widget.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
module Channel
|
||||
class WebWidget < ApplicationRecord
|
||||
self.table_name = 'channel_web_widgets'
|
||||
|
||||
belongs_to :account
|
||||
has_one :inbox, as: :channel, dependent: :destroy
|
||||
end
|
||||
end
|
||||
@@ -1,4 +0,0 @@
|
||||
class Channel::Widget < ApplicationRecord
|
||||
belongs_to :account
|
||||
has_one :inbox, as: :channel, dependent: :destroy
|
||||
end
|
||||
@@ -25,7 +25,7 @@ class Inbox < ApplicationRecord
|
||||
end
|
||||
|
||||
def facebook?
|
||||
channel.class.name.to_s == 'FacebookPage'
|
||||
channel.class.name.to_s == 'Channel::FacebookPage'
|
||||
end
|
||||
|
||||
def next_available_agent
|
||||
|
||||
@@ -4,7 +4,7 @@ module Facebook
|
||||
|
||||
def perform
|
||||
return if message.private
|
||||
return if inbox.channel.class.to_s != 'FacebookPage'
|
||||
return if inbox.channel.class.to_s != 'Channel::FacebookPage'
|
||||
return unless outgoing_message_from_chatwoot?
|
||||
|
||||
Bot.deliver(delivery_params, access_token: message.channel_token)
|
||||
@@ -55,14 +55,14 @@ module Facebook
|
||||
|
||||
is_after_24_hours = (Time.current - last_incoming_message.created_at) / 3600 >= 24
|
||||
|
||||
false unless is_after_24_hours
|
||||
return false unless is_after_24_hours
|
||||
|
||||
false if last_incoming_message && has_sent_first_outgoing_message_after_24_hours?(last_incoming_message.id)
|
||||
return false if last_incoming_message && sent_first_outgoing_message_after_24_hours?(last_incoming_message.id)
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def has_sent_first_outgoing_message_after_24_hours?(last_incoming_message_id)
|
||||
def sent_first_outgoing_message_after_24_hours?(last_incoming_message_id)
|
||||
# we can send max 1 message after 24 hour window
|
||||
conversation.messages.outgoing.where('id > ?', last_incoming_message_id).count == 1
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user