chore: Add message_echo listener for Facebook (#1192)
Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
@@ -19,4 +19,10 @@ class FacebookBot
|
||||
updater.perform
|
||||
Rails.logger.info "Human was online at #{delivery.at}"
|
||||
end
|
||||
|
||||
Bot.on :message_echo do |message|
|
||||
Rails.logger.info "MESSAGE_ECHO #{message}"
|
||||
response = ::Integrations::Facebook::MessageParser.new(message)
|
||||
::Integrations::Facebook::MessageCreator.new(response).perform
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,8 +10,9 @@ class Messages::Facebook::MessageBuilder
|
||||
def initialize(response, inbox, outgoing_echo = false)
|
||||
@response = response
|
||||
@inbox = inbox
|
||||
@sender_id = (outgoing_echo ? @response.recipient_id : @response.sender_id)
|
||||
@message_type = (outgoing_echo ? :outgoing : :incoming)
|
||||
@outgoing_echo = outgoing_echo
|
||||
@sender_id = (@outgoing_echo ? @response.recipient_id : @response.sender_id)
|
||||
@message_type = (@outgoing_echo ? :outgoing : :incoming)
|
||||
end
|
||||
|
||||
def perform
|
||||
@@ -120,7 +121,7 @@ class Messages::Facebook::MessageBuilder
|
||||
message_type: @message_type,
|
||||
content: response.content,
|
||||
source_id: response.identifier,
|
||||
sender: contact
|
||||
sender: @outgoing_echo ? nil : contact
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
@@ -17,6 +17,10 @@ class Channel::Api < ApplicationRecord
|
||||
|
||||
has_one :inbox, as: :channel, dependent: :destroy
|
||||
|
||||
def name
|
||||
'API'
|
||||
end
|
||||
|
||||
def has_24_hour_messaging_window?
|
||||
false
|
||||
end
|
||||
|
||||
@@ -26,6 +26,10 @@ class Channel::Email < ApplicationRecord
|
||||
has_one :inbox, as: :channel, dependent: :destroy
|
||||
before_validation :ensure_forward_to_address, on: :create
|
||||
|
||||
def name
|
||||
'Email'
|
||||
end
|
||||
|
||||
def has_24_hour_messaging_window?
|
||||
false
|
||||
end
|
||||
|
||||
@@ -28,6 +28,10 @@ class Channel::FacebookPage < ApplicationRecord
|
||||
after_create_commit :subscribe
|
||||
before_destroy :unsubscribe
|
||||
|
||||
def name
|
||||
'Facebook'
|
||||
end
|
||||
|
||||
def has_24_hour_messaging_window?
|
||||
true
|
||||
end
|
||||
|
||||
@@ -30,11 +30,11 @@ class Channel::TwilioSms < ApplicationRecord
|
||||
|
||||
has_one :inbox, as: :channel, dependent: :destroy
|
||||
|
||||
def name
|
||||
medium == :sms ? 'Twilio SMS' : 'Whatsapp'
|
||||
end
|
||||
|
||||
def has_24_hour_messaging_window?
|
||||
true
|
||||
end
|
||||
|
||||
def name
|
||||
'Twilio SMS'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -26,6 +26,10 @@ class Channel::TwitterProfile < ApplicationRecord
|
||||
|
||||
before_destroy :unsubscribe
|
||||
|
||||
def name
|
||||
'Twitter'
|
||||
end
|
||||
|
||||
def has_24_hour_messaging_window?
|
||||
false
|
||||
end
|
||||
|
||||
@@ -33,6 +33,10 @@ class Channel::WebWidget < ApplicationRecord
|
||||
2 => :emoji_picker,
|
||||
:column => 'feature_flags'
|
||||
|
||||
def name
|
||||
'Website'
|
||||
end
|
||||
|
||||
def has_24_hour_messaging_window?
|
||||
false
|
||||
end
|
||||
|
||||
@@ -66,6 +66,10 @@ class Inbox < ApplicationRecord
|
||||
channel.class.name.to_s == 'Channel::WebWidget'
|
||||
end
|
||||
|
||||
def inbox_type
|
||||
channel.name
|
||||
end
|
||||
|
||||
def webhook_data
|
||||
{
|
||||
id: id,
|
||||
|
||||
Reference in New Issue
Block a user