Class: Fastlane::Actions::DeleteSlackMessageAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/slack_bot/actions/delete_slack_message.rb

Class Method Summary collapse

Class Method Details

.authorsObject



72
73
74
# File 'lib/fastlane/plugin/slack_bot/actions/delete_slack_message.rb', line 72

def self.authors
  ["crazymanish"]
end

.available_optionsObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/fastlane/plugin/slack_bot/actions/delete_slack_message.rb', line 50

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :api_token,
                                 env_name: "FL_DELETE_SLACK_MESSAGE_BOT_TOKEN",
                                 description: "Slack bot Token",
                                 sensitive: true,
                                 code_gen_sensitive: true,
                                 is_string: true,
                                 default_value: ENV["SLACK_API_TOKEN"],
                                 default_value_dynamic: true,
                                 optional: false),
    FastlaneCore::ConfigItem.new(key: :ts,
                                 env_name: "FL_DELETE_SLACK_MESSAGE_TS",
                                 description: "Timestamp of the message to be deleted",
                                 optional: false),
    FastlaneCore::ConfigItem.new(key: :channel,
                                 env_name: "FL_DELETE_SLACK_MESSAGE_CHANNEL",
                                 description: "Slack channel_id containing the message to be deleted. i.e C1234567890",
                                 optional: false)
  ]
end

.descriptionObject



46
47
48
# File 'lib/fastlane/plugin/slack_bot/actions/delete_slack_message.rb', line 46

def self.description
  "Deleate a slack message using time-stamp(ts) value"
end

.example_codeObject



76
77
78
79
80
81
82
83
# File 'lib/fastlane/plugin/slack_bot/actions/delete_slack_message.rb', line 76

def self.example_code
  [
    'delete_slack_message(
      ts: "1609711037.000100",
      channel: "C1234567890"
    )'
  ]
end

.formatted_result(response) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/fastlane/plugin/slack_bot/actions/delete_slack_message.rb', line 30

def self.formatted_result(response)
  result = {
    status: response[:status],
    body: response.body || "",
    json: self.parse_json(response.body) || {}
  }
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/fastlane/plugin/slack_bot/actions/delete_slack_message.rb', line 85

def self.is_supported?(platform)
  true
end

.parse_json(value) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/fastlane/plugin/slack_bot/actions/delete_slack_message.rb', line 38

def self.parse_json(value)
  require 'json'

  JSON.parse(value)
rescue JSON::ParserError
  nil
end

.run(options) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fastlane/plugin/slack_bot/actions/delete_slack_message.rb', line 10

def self.run(options)
  begin
    require 'excon'

    api_url = "https://slack.com/api/chat.delete"
    headers = { "Content-Type": "application/json", "Authorization": "Bearer #{options[:api_token]}" }
    payload = { channel: options[:channel], ts: options[:ts] }.to_json

    response = Excon.post(api_url, headers: headers, body: payload)
    result = self.formatted_result(response)
  rescue => exception
    UI.error("Exception: #{exception}")
    return nil
  else
    UI.success("Successfully deleted the Slack message!")
    Actions.lane_context[SharedValues::DELETE_SLACK_MESSAGE_RESULT] = result
    return result
  end
end