2019-11-30 13:39:55 +00:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: channel_facebook_pages
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
|
|
|
# page_access_token :string not null
|
|
|
|
# user_access_token :string not null
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
|
|
|
# account_id :integer not null
|
|
|
|
# page_id :string not null
|
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
2019-12-05 07:50:04 +00:00
|
|
|
# index_channel_facebook_pages_on_page_id (page_id)
|
|
|
|
# index_channel_facebook_pages_on_page_id_and_account_id (page_id,account_id) UNIQUE
|
2019-11-30 13:39:55 +00:00
|
|
|
#
|
|
|
|
|
2020-01-09 07:36:40 +00:00
|
|
|
class Channel::FacebookPage < ApplicationRecord
|
2020-04-19 18:10:28 +00:00
|
|
|
# FIXME: this should be removed post 1.4 release. we moved avatars to inbox
|
2020-01-09 07:36:40 +00:00
|
|
|
include Avatarable
|
2020-01-07 17:29:17 +00:00
|
|
|
|
2020-01-09 07:36:40 +00:00
|
|
|
self.table_name = 'channel_facebook_pages'
|
2019-10-20 10:49:12 +00:00
|
|
|
|
2020-01-09 07:36:40 +00:00
|
|
|
validates :account_id, presence: true
|
|
|
|
validates :page_id, uniqueness: { scope: :account_id }
|
|
|
|
belongs_to :account
|
2019-10-20 10:49:12 +00:00
|
|
|
|
2020-01-09 07:36:40 +00:00
|
|
|
has_one :inbox, as: :channel, dependent: :destroy
|
2019-10-20 10:49:12 +00:00
|
|
|
|
2020-01-09 07:36:40 +00:00
|
|
|
before_destroy :unsubscribe
|
2019-10-20 10:49:12 +00:00
|
|
|
|
2020-01-09 07:36:40 +00:00
|
|
|
private
|
2019-10-20 10:49:12 +00:00
|
|
|
|
2020-01-09 07:36:40 +00:00
|
|
|
def unsubscribe
|
|
|
|
Facebook::Messenger::Subscriptions.unsubscribe(access_token: page_access_token)
|
|
|
|
rescue => e
|
|
|
|
true
|
2019-10-20 10:49:12 +00:00
|
|
|
end
|
|
|
|
end
|