2021-06-07 08:28:01 +00:00
|
|
|
# Remember that Rails only eager loads everything in its production environment.
|
|
|
|
# In the development and test environments, it only requires files as you reference constants.
|
|
|
|
# You'll need to explicitly load app/bot
|
|
|
|
|
2019-08-14 09:48:44 +00:00
|
|
|
unless Rails.env.production?
|
|
|
|
bot_files = Dir[Rails.root.join('app', 'bot', '**', '*.rb')]
|
|
|
|
bot_reloader = ActiveSupport::FileUpdateChecker.new(bot_files) do
|
2019-10-20 08:47:26 +00:00
|
|
|
bot_files.each { |file| require_dependency file }
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|
|
|
|
|
2019-08-19 08:19:57 +00:00
|
|
|
ActiveSupport::Reloader.to_prepare do
|
2019-08-14 09:48:44 +00:00
|
|
|
bot_reloader.execute_if_updated
|
|
|
|
end
|
|
|
|
|
|
|
|
bot_files.each { |file| require_dependency file }
|
|
|
|
end
|
|
|
|
|
2021-06-07 08:28:01 +00:00
|
|
|
# ref: https://github.com/jgorset/facebook-messenger#make-a-configuration-provider
|
2019-10-20 10:49:12 +00:00
|
|
|
class ChatwootFbProvider < Facebook::Messenger::Configuration::Providers::Base
|
2019-10-20 08:47:26 +00:00
|
|
|
def valid_verify_token?(_verify_token)
|
2019-11-23 19:57:39 +00:00
|
|
|
ENV['FB_VERIFY_TOKEN']
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|
|
|
|
|
2019-10-20 08:47:26 +00:00
|
|
|
def app_secret_for(_page_id)
|
2019-11-23 19:57:39 +00:00
|
|
|
ENV['FB_APP_SECRET']
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def access_token_for(page_id)
|
2021-06-07 08:28:01 +00:00
|
|
|
Channel::FacebookPage.where(page_id: page_id).last.page_access_token
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def bot
|
2021-06-07 08:28:01 +00:00
|
|
|
Chatwoot::Bot
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Facebook::Messenger.configure do |config|
|
2019-10-20 10:49:12 +00:00
|
|
|
config.provider = ChatwootFbProvider.new
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|