Class: Fastlane::Actions::MsTeamsAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



45
46
47
# File 'lib/fastlane/plugin/ms_teams/actions/ms_teams_action.rb', line 45

def self.authors
  ["Thang Nguyen"]
end

.available_optionsObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/fastlane/plugin/ms_teams/actions/ms_teams_action.rb', line 58

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :title,
                                 env_name: "MS_TEAMS_TITLE",
                                 description: "The title that should be displayed on Teams"),
    FastlaneCore::ConfigItem.new(key: :sections,
                                 type: Array,
                                 env_name: "MS_TEAMS_SECTIONS",
                                 description: "The section that should be displayed on Teams"),
    FastlaneCore::ConfigItem.new(key: :potential_action,
                                 type: Array,
                                 env_name: "MS_TEAMS_ACTION",
                                 description: "Optional Potential Action"),
    FastlaneCore::ConfigItem.new(key: :teams_url,
                                 env_name: "MS_TEAMS_URL",
                                 sensitive: true,
                                 description: "Create an Incoming WebHook for your Teams channel",
                                 verify_block: proc do |value|
                                   UI.user_error!("Invalid URL, must start with https://") unless value.start_with? "https://"
                                 end),
    FastlaneCore::ConfigItem.new(key: :theme_color,
                                 env_name: "FL_TEAMS_THEME_COLOR",
                                 description: "Theme color of the message card",
                                 default_value: "0078D7")
  ]
end

.categoryObject



115
116
117
# File 'lib/fastlane/plugin/ms_teams/actions/ms_teams_action.rb', line 115

def self.category
  :notifications
end

.check_response_code(response) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/fastlane/plugin/ms_teams/actions/ms_teams_action.rb', line 33

def self.check_response_code(response)
  if response.code.to_i == 200 && response.body.to_i == 1
    true
  else
    UI.user_error!("An error occurred: #{response.body}")
  end
end

.descriptionObject



41
42
43
# File 'lib/fastlane/plugin/ms_teams/actions/ms_teams_action.rb', line 41

def self.description
  "Send a message to your Microsoft Teams channel via the webhook connector"
end

.detailsObject



53
54
55
56
# File 'lib/fastlane/plugin/ms_teams/actions/ms_teams_action.rb', line 53

def self.details
  # Optional:
  "Send a message to your Microsoft Teams channel"
end

.example_codeObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/fastlane/plugin/ms_teams/actions/ms_teams_action.rb', line 85

def self.example_code
  [
    'ms_teams(
       title: "Title",
       sections: [{
          "activityTitle": "TEST",
          "activitySubtitle": "Version: 1.0",
          "activityImage": "https://...icon.png",
          "facts": [{
           "name": "Change logs:",
           "value": "- function 1 \t - function 2"
          }],
          "markdown": true
       }],
       potential_action: [
         {
          "@type": "OpenUri",
          "name": "Download",
          "targets": [{
              "os": "default",
              "uri": "https://app.download"
          }]
        }
       ],
       theme_color: "FFFFFF",
       teams_url: https://outlook.office.com/webhook/...
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


119
120
121
# File 'lib/fastlane/plugin/ms_teams/actions/ms_teams_action.rb', line 119

def self.is_supported?(platform)
  true
end

.return_valueObject



49
50
51
# File 'lib/fastlane/plugin/ms_teams/actions/ms_teams_action.rb', line 49

def self.return_value
  # If your method provides a return value, you can describe here what it does
end

.run(params) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fastlane/plugin/ms_teams/actions/ms_teams_action.rb', line 7

def self.run(params)
  require 'net/http'
  require 'uri'
  #https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using#example-connector-message
  payload = {
    "@type" => "MessageCard",
    "@context" => "http://schema.org/extensions",
    "themeColor" => params[:theme_color],
    "title" => params[:title],
    "summary" => params[:title],
    "sections" => params[:sections]
  }

  if params[:potential_action]
    payload["potentialAction"] = params[:potential_action]
  end

  json_headers = { 'Content-Type' => 'application/json' }
  uri = URI.parse(params[:teams_url])
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  response = http.post(uri.path, payload.to_json, json_headers)

  check_response_code(response)
end