fix: Update Slack integration to fix message delivery issues (#6093)

This commit is contained in:
Pranav Raj S
2022-12-17 16:41:11 -08:00
committed by GitHub
parent 4d2b7c37a0
commit 38587b3aa1
6 changed files with 52 additions and 9 deletions

View File

@@ -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

View File

@@ -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)