Class: Fastlane::Actions::MicrosftTeamsMessageCardAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



52
53
54
# File 'lib/fastlane/plugin/microsft_teams_message_card/actions/microsft_teams_message_card_action.rb', line 52

def self.authors
  ["Dorian Cheignon"]
end

.available_optionsObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
# File 'lib/fastlane/plugin/microsft_teams_message_card/actions/microsft_teams_message_card_action.rb', line 65

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :title,
                                 env_name: "TEAMS_MESSAGE_CARD_TITLE",
                                 description: "The title that should be displayed on Teams"),
    FastlaneCore::ConfigItem.new(key: :summary,
                                 env_name: "TEAMS_MESSAGE_CARD_SUMMARY",
                                 description: "The summary that should be displayed on Teams"),
    FastlaneCore::ConfigItem.new(key: :activity_title,
                                 env_name: "TEAMS_MESSAGE_CARD_ACTIVITY_TITLE",
                                 description: "Use activityTitle to summarize the action. Be clear and concise"),
    FastlaneCore::ConfigItem.new(key: :activity_subtitle,
                                 env_name: "TEAMS_MESSAGE_CARD_ACTIVITY_SUBTITLE",
                                 description: "Use activity subtitle to display, for example, the date and time of the action, or the person's identifier"),
    FastlaneCore::ConfigItem.new(key: :activity_image,
                                 env_name: "TEAMS_MESSAGE_CARD_ACTIVITY_IMAGE",
                                 sensitive: true,
                                 description: "Use activityImage to display the image of that person",
                                 verify_block: proc do |value|
                                   UI.user_error!("Invalid URL, must start with https://") unless value.start_with? "https://"
                                 end),
    FastlaneCore::ConfigItem.new(key: :text,
                                 env_name: "TEAMS_MESSAGE_CARD_TEXT",
                                 description: "The message that should be displayed on Teams. This supports the standard Teams markup language"),
    FastlaneCore::ConfigItem.new(key: :facts,
                                 type: Array,
                                 env_name: "TEAMS_MESSAGE_CARD_FACTS",
                                 description: "Optional facts"),
    FastlaneCore::ConfigItem.new(key: :potential_action,
                                 type: Array,
                                 env_name: "TEAMS_MESSAGE_CARD_POTENTIAL_ACTION",
                                 description: "Optional facts"),
    FastlaneCore::ConfigItem.new(key: :teams_url,
                                 env_name: "TEAMS_MESSAGE_CARD_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: "TEAMS_MESSAGE_CARD_THEME_COLOR",
                                 description: "Theme color of the message card",
                                 default_value: "8e8e93")
  ]
end

.categoryObject



147
148
149
# File 'lib/fastlane/plugin/microsft_teams_message_card/actions/microsft_teams_message_card_action.rb', line 147

def self.category
  :notifications
end

.check_response_code(response) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/fastlane/plugin/microsft_teams_message_card/actions/microsft_teams_message_card_action.rb', line 40

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



48
49
50
# File 'lib/fastlane/plugin/microsft_teams_message_card/actions/microsft_teams_message_card_action.rb', line 48

def self.description
  "Send a message card to your Microsoft teams channel"
end

.detailsObject



60
61
62
63
# File 'lib/fastlane/plugin/microsft_teams_message_card/actions/microsft_teams_message_card_action.rb', line 60

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

.example_codeObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/fastlane/plugin/microsft_teams_message_card/actions/microsft_teams_message_card_action.rb', line 111

def self.example_code
  [
    'microsft_teams_message_card(
      title: "Fastlane says hello",
      summary: "Test summary",
      text: "Test text",
      activity_title: "Someone",
      activity_subtitle: "9/13/2016, 3:34pm",
      activity_image: "https://connectorsdemo.azurewebsites.net/images/MSC12_Oscar_002.jpg",
      facts:[
        {
          "name"=>"Platform",
          "value"=>"iOS"
        },
        {
          "name"=>"Lane",
          "value"=>"iOS internal"
        }
      ],
      potential_action:[
        {
          "@type": "OpenUri",
          "name": "View in Trello",
          "targets": [
            { 
              "os": "default", 
              "uri": "https://..."
            }
          ]
        }
      ],
      teams_url: "https://outlook.office.com/webhook/..."
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


151
152
153
154
155
156
157
# File 'lib/fastlane/plugin/microsft_teams_message_card/actions/microsft_teams_message_card_action.rb', line 151

def self.is_supported?(platform)
  # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
  # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
  #
  # [:ios, :mac, :android].include?(platform)
  true
end

.return_valueObject



56
57
58
# File 'lib/fastlane/plugin/microsft_teams_message_card/actions/microsft_teams_message_card_action.rb', line 56

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
32
33
34
35
36
37
38
# File 'lib/fastlane/plugin/microsft_teams_message_card/actions/microsft_teams_message_card_action.rb', line 7

def self.run(params)
  require 'net/http'
  require 'uri'

  payload = {
    "@type" => "MessageCard", 
    "@context" => "http://schema.org/extensions",
    "themeColor" => params[:theme_color],
    "title" => params[:title],
    "summary" => params[:summary],
    "sections" => 
    [
      {
        "activityTitle" => params[:activity_title],
        "activitySubtitle" => params[:activity_subtitle],
        "activityImage"  => params[:activity_image],
        "text" => params[:text],
        "facts" => params[:facts],
        "potentialAction" => params[:potential_action]
      }
    ]
  }

  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