Class: Integrations::SlackEvents::AppHomeOpenedService
- Inherits:
-
Object
- Object
- Integrations::SlackEvents::AppHomeOpenedService
- Includes:
- Gitlab::Utils::StrongMemoize
- Defined in:
- app/services/integrations/slack_events/app_home_opened_service.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(params) ⇒ AppHomeOpenedService
constructor
A new instance of AppHomeOpenedService.
Constructor Details
#initialize(params) ⇒ AppHomeOpenedService
Returns a new instance of AppHomeOpenedService.
14 15 16 17 |
# File 'app/services/integrations/slack_events/app_home_opened_service.rb', line 14 def initialize(params) @slack_user_id = params.dig(:event, :user) @slack_workspace_id = params[:team_id] end |
Instance Method Details
#execute ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/services/integrations/slack_events/app_home_opened_service.rb', line 19 def execute # Legacy Slack App integrations will not yet have a token we can use # to call the Slack API. Do nothing, and consider the service successful. unless slack_installation logger.info( slack_user_id: slack_user_id, slack_workspace_id: slack_workspace_id, message: 'SlackInstallation record has no bot token' ) return ServiceResponse.success end begin response = ::Slack::API.new(slack_installation).post( 'views.publish', payload ) rescue *Gitlab::HTTP::HTTP_ERRORS => e return ServiceResponse .error(message: 'HTTP exception when calling Slack API') .track_exception( as: e.class, slack_user_id: slack_user_id, slack_workspace_id: slack_workspace_id ) end return ServiceResponse.success if response['ok'] # For a list of errors, see: # https://api.slack.com/methods/views.publish#errors ServiceResponse.error( message: 'Slack API returned an error', payload: response ).track_exception( slack_user_id: slack_user_id, slack_workspace_id: slack_workspace_id, response: response.to_h ) end |