This PR fixes an issue where Slack emojis are rendered as text shortcodes (e.g. 🚀) instead of the actual emoji characters in Chatwoot messages. It introduces a new EmojiFormatter class that uses the emoji-data mapping to convert shortcodes to unicode characters. --------- Co-authored-by: Sony Mathew <sony@chatwoot.com> Co-authored-by: Sony Mathew <2040199+sony-mathew@users.noreply.github.com>
17 lines
522 B
Ruby
17 lines
522 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Integrations::Slack::EmojiFormatter
|
|
def self.format(text)
|
|
return text if text.blank?
|
|
|
|
text.gsub(/:([a-zA-Z0-9_+-]+):/) do |match|
|
|
short_code = Regexp.last_match(1)
|
|
# gemoji exposes find_by_alias; Rails/DynamicFindBy is a false positive because Emoji is not an ActiveRecord model.
|
|
# rubocop:disable Rails/DynamicFindBy
|
|
emoji = Emoji.find_by_alias(short_code)
|
|
# rubocop:enable Rails/DynamicFindBy
|
|
emoji ? emoji.raw : match
|
|
end
|
|
end
|
|
end
|