Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Notifications
- module SlackServices
- class Base
- SLACK_BOT_WEBHOOK_PATH = 'https://hooks.slack.com/services'.freeze
- attr_accessor :user, :slack_token, :client
- def initialize(user)
- raise ArgumentError.new('SlackNotify Service [User] must be exists') unless user.present?
- @user = user
- @client = Slack::Notifier.new slack_token
- end
- def perform
- #notify unless Rails.env.development? || Rails.env.test?
- binding.pry
- notify
- rescue StandardError => e
- raise e
- end
- #protected
- def notify
- client.post text: notify_text,
- icon_url: ActionController::Base.helpers.asset_path('logo-arv-left-nav.svg'),
- attachments: [message]
- end
- def notify_text
- "#{ENV['APP_NAME']}: #{user&.full_name}"
- end
- #private
- def slack_token
- @slack_token = "#{SLACK_BOT_WEBHOOK_PATH}#{ENV['SLACK_BOT_CLIENT_NAME']}"
- end
- def default_message_params
- {
- color: 'good',
- fields: [
- {
- title: 'First Name',
- value: user&.first_name&.capitalize,
- short: true
- },
- {
- title: 'Last Name',
- value: user&.last_name&.capitalize,
- short: true
- },
- {
- title: 'Email',
- value: user.email,
- short: true
- }
- ]
- }
- end
- def message
- default_message_params
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement