From cb38ec32679605ed579d680a6b70ae41a5e70da2 Mon Sep 17 00:00:00 2001 From: Tejaswini Chile Date: Thu, 28 Apr 2022 01:14:03 +0530 Subject: [PATCH] chore: Allow Facebook channel to receive standby messages (#4511) --- app/models/channel/facebook_page.rb | 2 +- lib/integrations/facebook/message_parser.rb | 19 ++++++++++--------- .../slack/incoming_message_builder.rb | 6 +++++- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/app/models/channel/facebook_page.rb b/app/models/channel/facebook_page.rb index 6b36a3a54..ed599e6e2 100644 --- a/app/models/channel/facebook_page.rb +++ b/app/models/channel/facebook_page.rb @@ -54,7 +54,7 @@ class Channel::FacebookPage < ApplicationRecord response = Facebook::Messenger::Subscriptions.subscribe( access_token: page_access_token, subscribed_fields: %w[ - messages message_deliveries message_echoes message_reads + messages message_deliveries message_echoes message_reads standby messaging_handovers ] ) rescue => e diff --git a/lib/integrations/facebook/message_parser.rb b/lib/integrations/facebook/message_parser.rb index d2b943c00..ea70ca442 100644 --- a/lib/integrations/facebook/message_parser.rb +++ b/lib/integrations/facebook/message_parser.rb @@ -3,43 +3,44 @@ class Integrations::Facebook::MessageParser def initialize(response_json) @response = JSON.parse(response_json) + @messaging = @response['messaging'] || @response['standby'] end def sender_id - @response.dig 'messaging', 'sender', 'id' + @messaging.dig('sender', 'id') end def recipient_id - @response.dig 'messaging', 'recipient', 'id' + @messaging.dig('recipient', 'id') end def time_stamp - @response.dig 'messaging', 'timestamp' + @messaging['timestamp'] end def content - @response.dig 'messaging', 'message', 'text' + @messaging.dig('message', 'text') end def sequence - @response.dig 'messaging', 'message', 'seq' + @messaging.dig('message', 'seq') end def attachments - @response.dig 'messaging', 'message', 'attachments' + @messaging.dig('message', 'attachments') end def identifier - @response.dig 'messaging', 'message', 'mid' + @messaging.dig('message', 'mid') end def echo? - @response.dig 'messaging', 'message', 'is_echo' + @messaging.dig('message', 'is_echo') end # TODO : i don't think the payload contains app_id. if not remove def app_id - @response.dig 'messaging', 'message', 'app_id' + @messaging.dig('message', 'app_id') end # TODO : does this work ? diff --git a/lib/integrations/slack/incoming_message_builder.rb b/lib/integrations/slack/incoming_message_builder.rb index e655eef45..66d96be4a 100644 --- a/lib/integrations/slack/incoming_message_builder.rb +++ b/lib/integrations/slack/incoming_message_builder.rb @@ -34,7 +34,11 @@ class Integrations::Slack::IncomingMessageBuilder end def supported_message? - SUPPORTED_MESSAGE_TYPES.include?(message[:type]) if message.present? + if message.present? + SUPPORTED_MESSAGE_TYPES.include?(message[:type]) + else + params[:event][:files].any? + end end def hook_verification?