Bug: Fix autoload_paths for facebook bot (#877)

* Fix autoload_paths for facebook bot
This commit is contained in:
Pranav Raj S 2020-05-18 15:32:26 +05:30 committed by GitHub
parent 6e92d9be9e
commit 3f5ce2ddbf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 22 deletions

View file

@ -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
View 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

View file

@ -6,7 +6,7 @@ class Facebook::SendReplyService
return if inbox.channel.class.to_s != 'Channel::FacebookPage' return if inbox.channel.class.to_s != 'Channel::FacebookPage'
return unless outgoing_message_from_chatwoot? 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 end
private private

View file

@ -18,7 +18,7 @@ module Chatwoot
# This is required in production for zeitwerk to autoload the file # This is required in production for zeitwerk to autoload the file
config.paths.add File.join('app', 'bot'), glob: File.join('**', '*.rb') 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. # Settings in config/environments/* take precedence over those specified here.
# Application configuration can go into files in config/initializers # Application configuration can go into files in config/initializers

View file

@ -9,7 +9,7 @@ describe Facebook::SendReplyService do
end end
let!(:account) { create(:account) } 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!(:widget_inbox) { create(:inbox, account: account) }
let!(:facebook_channel) { create(:channel_facebook_page, account: account) } let!(:facebook_channel) { create(:channel_facebook_page, account: account) }
let!(:facebook_inbox) { create(:inbox, channel: facebook_channel, account: account) } let!(:facebook_inbox) { create(:inbox, channel: facebook_channel, account: account) }