Sha256: 36800b56936590e40d812251f52f48e0ce0b52ad5a7da468ea05812cbfd9be43

Contents?: true

Size: 1.45 KB

Versions: 9

Compression:

Stored size: 1.45 KB

Contents

class HelpCenter::SupportPostNotificationJob < ApplicationJob
  include HelpCenter::Engine.routes.url_helpers

  def perform(support_post)
    send_emails(support_post) if HelpCenter.send_email_notifications
    send_webhook(support_post) if HelpCenter.send_slack_notifications
  end

  def send_emails(support_post)
    support_thread = support_post.support_thread
    users        = support_thread.subscribed_users - [support_post.user]
    users.each do |user|
      HelpCenter::UserMailer.new_post(support_post, user).deliver_later
    end
  end

  def send_webhook(support_post)
    slack_webhook_url = Rails.application.secrets.help_center_slack_url
    return if slack_webhook_url.blank?

    support_thread = support_post.support_thread
    payload = {
      fallback: "#{support_post.user.name} replied to <#{support_thread_url(support_thread, anchor: ActionView::RecordIdentifier.dom_id(support_post))}|#{support_thread.title}>",
      pretext: "#{support_post.user.name} replied to <#{support_thread_url(support_thread, anchor: ActionView::RecordIdentifier.dom_id(support_post))}|#{support_thread.title}>",
      fields: [
        {
          title: "Thread",
          value: support_thread.title,
          short: true
        },
        {
          title: "Posted By",
          value: support_post.user.name,
          short: true,
        },
      ],
      ts: support_post.created_at.to_i
    }

    HelpCenter::Slack.new(slack_webhook_url).post(payload)
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
help_center-0.1.0 app/jobs/help_center/support_post_notification_job.rb
help_center-0.0.9 app/jobs/help_center/support_post_notification_job.rb
help_center-0.0.8 app/jobs/help_center/support_post_notification_job.rb
help_center-0.0.7 app/jobs/help_center/support_post_notification_job.rb
help_center-0.0.6 app/jobs/help_center/support_post_notification_job.rb
help_center-0.0.4 app/jobs/help_center/support_post_notification_job.rb
help_center-0.0.3 app/jobs/help_center/support_post_notification_job.rb
help_center-0.0.2 app/jobs/help_center/support_post_notification_job.rb
help_center-0.0.1 app/jobs/help_center/support_post_notification_job.rb