Retrospring/app/helpers/social_helper/telegram_methods.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

24 lines
635 B
Ruby
Raw Normal View History

2023-02-19 11:58:47 -08:00
# frozen_string_literal: true
require "cgi"
module SocialHelper::TelegramMethods
include MarkdownHelper
def telegram_text(answer)
# using twitter_markdown here as it removes all formatting
"#{twitter_markdown answer.question.content}\n———\n#{twitter_markdown answer.content}"
end
def telegram_share_url(answer)
url = answer_url(
id: answer.id,
username: answer.user.screen_name,
host: APP_CONFIG["hostname"],
protocol: (APP_CONFIG["https"] ? :https : :http),
2023-02-19 11:58:47 -08:00
)
%(https://t.me/share/url?url=#{CGI.escape(url)}&text=#{CGI.escape(telegram_text(answer))})
end
end