From d42206e03be4719e092b99944b6cf23393772a19 Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Wed, 16 Aug 2023 15:47:35 +0530 Subject: [PATCH 1/4] chore: move lib to services --- {lib => app/services}/integrations/bot_processor_service.rb | 0 {lib => app/services}/integrations/csml/processor_service.rb | 0 .../services}/integrations/dialogflow/processor_service.rb | 0 {lib => app/services}/integrations/dyte/processor_service.rb | 0 .../services}/integrations/facebook/delivery_status.rb | 0 .../services}/integrations/facebook/message_creator.rb | 0 {lib => app/services}/integrations/facebook/message_parser.rb | 0 .../integrations/google_translate/detect_language_service.rb | 0 .../integrations/google_translate/processor_service.rb | 0 .../services}/integrations/openai/openai_prompts/reply.txt | 0 .../services}/integrations/openai/openai_prompts/summary.txt | 0 .../services}/integrations/openai/processor_service.rb | 0 {lib => app/services}/integrations/openai_base_service.rb | 0 {lib => app/services}/integrations/slack/channel_builder.rb | 0 {lib => app/services}/integrations/slack/hook_builder.rb | 0 .../services}/integrations/slack/incoming_message_builder.rb | 4 ++++ .../services}/integrations/slack/send_on_slack_service.rb | 0 .../services}/integrations/widget/incoming_message_builder.rb | 0 .../services}/integrations/widget/outgoing_message_builder.rb | 0 19 files changed, 4 insertions(+) rename {lib => app/services}/integrations/bot_processor_service.rb (100%) rename {lib => app/services}/integrations/csml/processor_service.rb (100%) rename {lib => app/services}/integrations/dialogflow/processor_service.rb (100%) rename {lib => app/services}/integrations/dyte/processor_service.rb (100%) rename {lib => app/services}/integrations/facebook/delivery_status.rb (100%) rename {lib => app/services}/integrations/facebook/message_creator.rb (100%) rename {lib => app/services}/integrations/facebook/message_parser.rb (100%) rename {lib => app/services}/integrations/google_translate/detect_language_service.rb (100%) rename {lib => app/services}/integrations/google_translate/processor_service.rb (100%) rename {lib => app/services}/integrations/openai/openai_prompts/reply.txt (100%) rename {lib => app/services}/integrations/openai/openai_prompts/summary.txt (100%) rename {lib => app/services}/integrations/openai/processor_service.rb (100%) rename {lib => app/services}/integrations/openai_base_service.rb (100%) rename {lib => app/services}/integrations/slack/channel_builder.rb (100%) rename {lib => app/services}/integrations/slack/hook_builder.rb (100%) rename {lib => app/services}/integrations/slack/incoming_message_builder.rb (97%) rename {lib => app/services}/integrations/slack/send_on_slack_service.rb (100%) rename {lib => app/services}/integrations/widget/incoming_message_builder.rb (100%) rename {lib => app/services}/integrations/widget/outgoing_message_builder.rb (100%) diff --git a/lib/integrations/bot_processor_service.rb b/app/services/integrations/bot_processor_service.rb similarity index 100% rename from lib/integrations/bot_processor_service.rb rename to app/services/integrations/bot_processor_service.rb diff --git a/lib/integrations/csml/processor_service.rb b/app/services/integrations/csml/processor_service.rb similarity index 100% rename from lib/integrations/csml/processor_service.rb rename to app/services/integrations/csml/processor_service.rb diff --git a/lib/integrations/dialogflow/processor_service.rb b/app/services/integrations/dialogflow/processor_service.rb similarity index 100% rename from lib/integrations/dialogflow/processor_service.rb rename to app/services/integrations/dialogflow/processor_service.rb diff --git a/lib/integrations/dyte/processor_service.rb b/app/services/integrations/dyte/processor_service.rb similarity index 100% rename from lib/integrations/dyte/processor_service.rb rename to app/services/integrations/dyte/processor_service.rb diff --git a/lib/integrations/facebook/delivery_status.rb b/app/services/integrations/facebook/delivery_status.rb similarity index 100% rename from lib/integrations/facebook/delivery_status.rb rename to app/services/integrations/facebook/delivery_status.rb diff --git a/lib/integrations/facebook/message_creator.rb b/app/services/integrations/facebook/message_creator.rb similarity index 100% rename from lib/integrations/facebook/message_creator.rb rename to app/services/integrations/facebook/message_creator.rb diff --git a/lib/integrations/facebook/message_parser.rb b/app/services/integrations/facebook/message_parser.rb similarity index 100% rename from lib/integrations/facebook/message_parser.rb rename to app/services/integrations/facebook/message_parser.rb diff --git a/lib/integrations/google_translate/detect_language_service.rb b/app/services/integrations/google_translate/detect_language_service.rb similarity index 100% rename from lib/integrations/google_translate/detect_language_service.rb rename to app/services/integrations/google_translate/detect_language_service.rb diff --git a/lib/integrations/google_translate/processor_service.rb b/app/services/integrations/google_translate/processor_service.rb similarity index 100% rename from lib/integrations/google_translate/processor_service.rb rename to app/services/integrations/google_translate/processor_service.rb diff --git a/lib/integrations/openai/openai_prompts/reply.txt b/app/services/integrations/openai/openai_prompts/reply.txt similarity index 100% rename from lib/integrations/openai/openai_prompts/reply.txt rename to app/services/integrations/openai/openai_prompts/reply.txt diff --git a/lib/integrations/openai/openai_prompts/summary.txt b/app/services/integrations/openai/openai_prompts/summary.txt similarity index 100% rename from lib/integrations/openai/openai_prompts/summary.txt rename to app/services/integrations/openai/openai_prompts/summary.txt diff --git a/lib/integrations/openai/processor_service.rb b/app/services/integrations/openai/processor_service.rb similarity index 100% rename from lib/integrations/openai/processor_service.rb rename to app/services/integrations/openai/processor_service.rb diff --git a/lib/integrations/openai_base_service.rb b/app/services/integrations/openai_base_service.rb similarity index 100% rename from lib/integrations/openai_base_service.rb rename to app/services/integrations/openai_base_service.rb diff --git a/lib/integrations/slack/channel_builder.rb b/app/services/integrations/slack/channel_builder.rb similarity index 100% rename from lib/integrations/slack/channel_builder.rb rename to app/services/integrations/slack/channel_builder.rb diff --git a/lib/integrations/slack/hook_builder.rb b/app/services/integrations/slack/hook_builder.rb similarity index 100% rename from lib/integrations/slack/hook_builder.rb rename to app/services/integrations/slack/hook_builder.rb diff --git a/lib/integrations/slack/incoming_message_builder.rb b/app/services/integrations/slack/incoming_message_builder.rb similarity index 97% rename from lib/integrations/slack/incoming_message_builder.rb rename to app/services/integrations/slack/incoming_message_builder.rb index 44d373259..6d0cccad0 100644 --- a/lib/integrations/slack/incoming_message_builder.rb +++ b/app/services/integrations/slack/incoming_message_builder.rb @@ -39,6 +39,10 @@ class Integrations::Slack::IncomingMessageBuilder params[:event][:user].present? && params[:event][:subtype].blank? end + def valid_event_subtype? + params[:event][:subtype].blank? || params[:event][:subtype] == 'file_share' + end + def supported_event? hook_verification? || SUPPORTED_EVENTS.include?(params[:event][:type]) end diff --git a/lib/integrations/slack/send_on_slack_service.rb b/app/services/integrations/slack/send_on_slack_service.rb similarity index 100% rename from lib/integrations/slack/send_on_slack_service.rb rename to app/services/integrations/slack/send_on_slack_service.rb diff --git a/lib/integrations/widget/incoming_message_builder.rb b/app/services/integrations/widget/incoming_message_builder.rb similarity index 100% rename from lib/integrations/widget/incoming_message_builder.rb rename to app/services/integrations/widget/incoming_message_builder.rb diff --git a/lib/integrations/widget/outgoing_message_builder.rb b/app/services/integrations/widget/outgoing_message_builder.rb similarity index 100% rename from lib/integrations/widget/outgoing_message_builder.rb rename to app/services/integrations/widget/outgoing_message_builder.rb From 68205d8fd379f8918ab4cd796198780eac8f7dae Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Wed, 16 Aug 2023 15:47:41 +0530 Subject: [PATCH 2/4] Fix slack attachment issues --- app/services/integrations/facebook/message_creator.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/integrations/facebook/message_creator.rb b/app/services/integrations/facebook/message_creator.rb index cf28743f9..b67c162fc 100644 --- a/app/services/integrations/facebook/message_creator.rb +++ b/app/services/integrations/facebook/message_creator.rb @@ -29,14 +29,14 @@ class Integrations::Facebook::MessageCreator end def create_agent_message - Channel::FacebookPage.where(page_id: response.sender_id).each do |page| + Channel::FacebookPage.where(page_id: response.sender_id).find_each do |page| mb = Messages::Facebook::MessageBuilder.new(response, page.inbox, outgoing_echo: true) mb.perform end end def create_contact_message - Channel::FacebookPage.where(page_id: response.recipient_id).each do |page| + Channel::FacebookPage.where(page_id: response.recipient_id).find_each do |page| mb = Messages::Facebook::MessageBuilder.new(response, page.inbox) mb.perform end From 7f8d8a112d96d91c92384b8827b732dabfceef13 Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Fri, 25 Aug 2023 10:59:41 +0530 Subject: [PATCH 3/4] chore: fix slack attachment issue --- .../slack/incoming_message_builder.rb | 16 +++++++++------- config/integration/apps.yml | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/services/integrations/slack/incoming_message_builder.rb b/app/services/integrations/slack/incoming_message_builder.rb index 6d0cccad0..23d633b1d 100644 --- a/app/services/integrations/slack/incoming_message_builder.rb +++ b/app/services/integrations/slack/incoming_message_builder.rb @@ -36,7 +36,7 @@ class Integrations::Slack::IncomingMessageBuilder def should_process_event? return true if params[:type] != 'event_callback' - params[:event][:user].present? && params[:event][:subtype].blank? + params[:event][:user].present? && valid_event_subtype? end def valid_event_subtype? @@ -97,7 +97,14 @@ class Integrations::Slack::IncomingMessageBuilder def create_message return unless conversation - @message = conversation.messages.create!( + build_message + process_attachments(params[:event][:files]) if params[:event][:files].present? + @message.save! + { status: 'success' } + end + + def build_message + @message = conversation.messages.build( message_type: :outgoing, account_id: conversation.account_id, inbox_id: conversation.inbox_id, @@ -106,10 +113,6 @@ class Integrations::Slack::IncomingMessageBuilder private: private_note?, sender: sender ) - - process_attachments(params[:event][:files]) if params[:event][:files].present? - - { status: 'success' } end def slack_client @@ -135,7 +138,6 @@ class Integrations::Slack::IncomingMessageBuilder attachment_obj = @message.attachments.new(attachment_params) attachment_obj.file.content_type = attachment[:mimetype] - attachment_obj.save! end end diff --git a/config/integration/apps.yml b/config/integration/apps.yml index 05add0c1a..b71df9813 100644 --- a/config/integration/apps.yml +++ b/config/integration/apps.yml @@ -13,7 +13,7 @@ slack: id: slack logo: slack.png i18n_key: slack - action: https://slack.com/oauth/v2/authorize?scope=commands,chat:write,channels:read,channels:manage,channels:join,groups:read,groups:write,im:write,mpim:write,users:read,users:read.email,chat:write.customize,channels:history,groups:history,mpim:history,im:history + action: https://slack.com/oauth/v2/authorize?scope=commands,chat:write,channels:read,channels:manage,channels:join,groups:read,groups:write,im:write,mpim:write,users:read,users:read.email,chat:write.customize,channels:history,groups:history,mpim:history,im:history,files:read hook_type: account allow_multiple_hooks: false webhooks: From 2971d78f8c1aa2a8dc9d7ecfed34655115232838 Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Fri, 25 Aug 2023 11:39:46 +0530 Subject: [PATCH 4/4] Revert facebook code --- app/services/integrations/facebook/message_creator.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/integrations/facebook/message_creator.rb b/app/services/integrations/facebook/message_creator.rb index b67c162fc..cf28743f9 100644 --- a/app/services/integrations/facebook/message_creator.rb +++ b/app/services/integrations/facebook/message_creator.rb @@ -29,14 +29,14 @@ class Integrations::Facebook::MessageCreator end def create_agent_message - Channel::FacebookPage.where(page_id: response.sender_id).find_each do |page| + Channel::FacebookPage.where(page_id: response.sender_id).each do |page| mb = Messages::Facebook::MessageBuilder.new(response, page.inbox, outgoing_echo: true) mb.perform end end def create_contact_message - Channel::FacebookPage.where(page_id: response.recipient_id).find_each do |page| + Channel::FacebookPage.where(page_id: response.recipient_id).each do |page| mb = Messages::Facebook::MessageBuilder.new(response, page.inbox) mb.perform end