Bug: Fix Facebook v7.0 API issues (#863)
* Fix v7.0 API issues Co-authored-by: Sojan <sojan@pepalo.com>
This commit is contained in:
@@ -28,13 +28,26 @@ class Channel::FacebookPage < ApplicationRecord
|
||||
|
||||
has_one :inbox, as: :channel, dependent: :destroy
|
||||
|
||||
after_create_commit :subscribe
|
||||
before_destroy :unsubscribe
|
||||
|
||||
private
|
||||
def subscribe
|
||||
# ref https://developers.facebook.com/docs/messenger-platform/reference/webhook-events
|
||||
response = Facebook::Messenger::Subscriptions.subscribe(
|
||||
access_token: page_access_token,
|
||||
subscribed_fields: %w[
|
||||
messages message_deliveries message_echoes message_reads
|
||||
]
|
||||
)
|
||||
rescue => e
|
||||
Rails.logger.debug "Rescued: #{e.inspect}"
|
||||
true
|
||||
end
|
||||
|
||||
def unsubscribe
|
||||
Facebook::Messenger::Subscriptions.unsubscribe(access_token: page_access_token)
|
||||
rescue => e
|
||||
Rails.logger.debug "Rescued: #{e.inspect}"
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -41,7 +41,6 @@ class Inbox < ApplicationRecord
|
||||
has_one :agent_bot, through: :agent_bot_inbox
|
||||
has_many :webhooks, dependent: :destroy
|
||||
|
||||
after_create :subscribe_webhook, if: :facebook?
|
||||
after_destroy :delete_round_robin_agents
|
||||
|
||||
def add_member(user_id)
|
||||
@@ -83,16 +82,4 @@ class Inbox < ApplicationRecord
|
||||
def round_robin_key
|
||||
format(Constants::RedisKeys::ROUND_ROBIN_AGENTS, inbox_id: id)
|
||||
end
|
||||
|
||||
def subscribe_webhook
|
||||
Facebook::Messenger::Subscriptions.subscribe(
|
||||
access_token: channel.page_access_token,
|
||||
subscribed_fields: %w[
|
||||
messages messaging_postbacks messaging_optins message_deliveries
|
||||
message_reads messaging_payments messaging_pre_checkouts messaging_checkout_updates
|
||||
messaging_account_linking messaging_referrals message_echoes messaging_game_plays
|
||||
standby messaging_handovers messaging_policy_enforcement message_reactions
|
||||
]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user