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: