Bug: Fix autoload_paths for facebook bot (#877)
* Fix autoload_paths for facebook bot
This commit is contained in:
parent
6e92d9be9e
commit
3f5ce2ddbf
5 changed files with 25 additions and 22 deletions
|
@ -1,19 +0,0 @@
|
|||
# app/bot/facebook_bot.rb
|
||||
require 'facebook/messenger'
|
||||
include Facebook::Messenger
|
||||
|
||||
Bot.on :message do |message|
|
||||
response = ::Integrations::Facebook::MessageParser.new(message)
|
||||
::Integrations::Facebook::MessageCreator.new(response).perform
|
||||
end
|
||||
|
||||
Bot.on :delivery do |delivery|
|
||||
# delivery.ids # => 'mid.1457764197618:41d102a3e1ae206a38'
|
||||
# delivery.sender # => { 'id' => '1008372609250235' }
|
||||
# delivery.recipient # => { 'id' => '2015573629214912' }
|
||||
# delivery.at # => 2016-04-22 21:30:36 +0200
|
||||
# delivery.seq # => 37
|
||||
updater = Integrations::Facebook::DeliveryStatus.new(delivery)
|
||||
updater.perform
|
||||
puts "Human was online at #{delivery.at}"
|
||||
end
|
22
app/bot/facebook_bot.rb
Normal file
22
app/bot/facebook_bot.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
require 'facebook/messenger'
|
||||
|
||||
class FacebookBot
|
||||
include Facebook::Messenger
|
||||
|
||||
Bot.on :message do |message|
|
||||
Rails.logger.info "MESSAGE_RECIEVED #{message}"
|
||||
response = ::Integrations::Facebook::MessageParser.new(message)
|
||||
::Integrations::Facebook::MessageCreator.new(response).perform
|
||||
end
|
||||
|
||||
Bot.on :delivery do |delivery|
|
||||
# delivery.ids # => 'mid.1457764197618:41d102a3e1ae206a38'
|
||||
# delivery.sender # => { 'id' => '1008372609250235' }
|
||||
# delivery.recipient # => { 'id' => '2015573629214912' }
|
||||
# delivery.at # => 2016-04-22 21:30:36 +0200
|
||||
# delivery.seq # => 37
|
||||
updater = Integrations::Facebook::DeliveryStatus.new(delivery)
|
||||
updater.perform
|
||||
Rails.logger.info "Human was online at #{delivery.at}"
|
||||
end
|
||||
end
|
|
@ -6,7 +6,7 @@ class Facebook::SendReplyService
|
|||
return if inbox.channel.class.to_s != 'Channel::FacebookPage'
|
||||
return unless outgoing_message_from_chatwoot?
|
||||
|
||||
Bot.deliver(delivery_params, access_token: message.channel_token)
|
||||
FacebookBot::Bot.deliver(delivery_params, access_token: message.channel_token)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -18,7 +18,7 @@ module Chatwoot
|
|||
|
||||
# This is required in production for zeitwerk to autoload the file
|
||||
config.paths.add File.join('app', 'bot'), glob: File.join('**', '*.rb')
|
||||
config.autoload_paths << Rails.root.join('app/bot')
|
||||
config.autoload_paths << Rails.root.join('app/bot/*')
|
||||
|
||||
# Settings in config/environments/* take precedence over those specified here.
|
||||
# Application configuration can go into files in config/initializers
|
||||
|
|
|
@ -9,7 +9,7 @@ describe Facebook::SendReplyService do
|
|||
end
|
||||
|
||||
let!(:account) { create(:account) }
|
||||
let(:bot) { class_double('Bot').as_stubbed_const }
|
||||
let(:bot) { class_double('FacebookBot::Bot').as_stubbed_const }
|
||||
let!(:widget_inbox) { create(:inbox, account: account) }
|
||||
let!(:facebook_channel) { create(:channel_facebook_page, account: account) }
|
||||
let!(:facebook_inbox) { create(:inbox, channel: facebook_channel, account: account) }
|
||||
|
|
Loading…
Reference in a new issue