Add link to Fizzy to Slack message

This makes it nice to use with a Slack webhook enabled, see
also this discussion: https://github.com/basecamp/fizzy/discussions/2238
This commit is contained in:
Jankees van Woezik
2025-12-24 11:16:03 +01:00
parent 83c71ce336
commit cf82ead0e3
2 changed files with 20 additions and 3 deletions
+5 -1
View File
@@ -14,7 +14,7 @@ class Event::Description
end
def to_plain_text
to_sentence(creator_name, h(card.title))
to_sentence(creator_name, quoted(card.title))
end
private
@@ -41,6 +41,10 @@ class Event::Description
h(event.creator.name)
end
def quoted(text)
%("#{h text}")
end
def card
@card ||= event.action.comment_created? ? event.eventable.card : event.eventable
end
+15 -2
View File
@@ -1,4 +1,6 @@
class Webhook::Delivery < ApplicationRecord
include Rails.application.routes.url_helpers
class ResponseTooLarge < StandardError; end
STALE_TRESHOLD = 7.days
@@ -130,8 +132,7 @@ class Webhook::Delivery < ApplicationRecord
elsif webhook.for_campfire?
render_payload(formats: :html)
elsif webhook.for_slack?
html = render_payload(formats: :html)
{ text: convert_html_to_mrkdwn(html) }.to_json
slack_payload
else
render_payload(formats: :json)
end
@@ -158,4 +159,16 @@ class Webhook::Delivery < ApplicationRecord
document.text
end
def slack_payload
text = event.description_for(nil).to_plain_text
url = polymorphic_url(event.eventable, base_url_options.merge(script_name: account.slug))
{ text: "#{text} <#{url}|Open in Fizzy>" }.to_json
end
def base_url_options
Rails.application.routes.default_url_options.presence ||
Rails.application.config.action_mailer.default_url_options
end
end