fix: Update Slack integration to fix message delivery issues (#6093)
This commit is contained in:
@@ -22,13 +22,23 @@ class Integrations::Slack::IncomingMessageBuilder
|
||||
private
|
||||
|
||||
def valid_event?
|
||||
supported_event_type? && supported_event?
|
||||
supported_event_type? && supported_event? && should_process_event?
|
||||
end
|
||||
|
||||
def supported_event_type?
|
||||
SUPPORTED_EVENT_TYPES.include?(params[:type])
|
||||
end
|
||||
|
||||
# Discard all the subtype of a message event
|
||||
# We are only considering the actual message sent by a Slack user
|
||||
# Any reactions or messages sent by the bot will be ignored.
|
||||
# https://api.slack.com/events/message#subtypes
|
||||
def should_process_event?
|
||||
return true if params[:type] != 'event_callback'
|
||||
|
||||
params[:event][:user].present? && params[:event][:subtype].blank?
|
||||
end
|
||||
|
||||
def supported_event?
|
||||
hook_verification? || SUPPORTED_EVENTS.include?(params[:event][:type])
|
||||
end
|
||||
|
||||
@@ -36,12 +36,13 @@ class Integrations::Slack::SendOnSlackService < Base::SendOnChannelService
|
||||
if conversation.identifier.present?
|
||||
"#{private_indicator}#{message.content}"
|
||||
else
|
||||
"*Inbox: #{message.inbox.name} [#{message.inbox.inbox_type}]* \n\n #{message.content}"
|
||||
"\n*Inbox:* #{message.inbox.name} (#{message.inbox.inbox_type})\n\n#{message.content}"
|
||||
end
|
||||
end
|
||||
|
||||
def avatar_url(sender)
|
||||
sender.try(:avatar_url) || "#{ENV.fetch('FRONTEND_URL', nil)}/admin/avatar_square.png"
|
||||
sender_type = sender.instance_of?(Contact) ? 'contact' : 'user'
|
||||
"#{ENV.fetch('FRONTEND_URL', nil)}/integrations/slack/#{sender_type}.png"
|
||||
end
|
||||
|
||||
def send_message
|
||||
@@ -86,7 +87,7 @@ class Integrations::Slack::SendOnSlackService < Base::SendOnChannelService
|
||||
end
|
||||
|
||||
def sender_name(sender)
|
||||
sender.try(:name) ? "#{sender_type(sender)}: #{sender.try(:name)}" : sender_type(sender)
|
||||
sender.try(:name) ? "#{sender.try(:name)} (#{sender_type(sender)})" : sender_type(sender)
|
||||
end
|
||||
|
||||
def sender_type(sender)
|
||||
|
||||
Reference in New Issue
Block a user