Class: Fastlane::Actions::LineMessageAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



33
34
35
# File 'lib/fastlane/plugin/line_message/actions/line_message_action.rb', line 33

def self.authors
  ["Wasith Theerapattrathamrong"]
end

.available_optionsObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/fastlane/plugin/line_message/actions/line_message_action.rb', line 69

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :api_token,
                            env_name: "LINE_MESSAGE_API_TOKEN",
                         description: "API token for Line Messaging API",
                        verify_block: proc do |value|
                                      UI.user_error!("No API token for Line Notify given, pass using `api_token: 'token'`") unless (value and not value.empty?)
                                    end),
    FastlaneCore::ConfigItem.new(key: :to,
                            env_name: "LINE_MESSAGE_API_TO",
                         description: "Target id you want to send message",
                            optional: false,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :messages,
                            env_name: "LINE_MESSAGE_API_MESSAGES",
                         description: "Message you want to send follow https://developers.line.biz/en/docs/messaging-api/ spces",
                            optional: false,
                                type: Array),
  ]
end

.categoryObject



61
62
63
# File 'lib/fastlane/plugin/line_message/actions/line_message_action.rb', line 61

def self.category
  :notifications
end

.descriptionObject



29
30
31
# File 'lib/fastlane/plugin/line_message/actions/line_message_action.rb', line 29

def self.description
  "Use to send message to Line chat"
end

.detailsObject



65
66
67
# File 'lib/fastlane/plugin/line_message/actions/line_message_action.rb', line 65

def self.details
  "Use api from https://developers.line.biz/en/docs/messaging-api/ call api at https://api.line.me/v2/bot/message/push"
end

.example_codeObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/fastlane/plugin/line_message/actions/line_message_action.rb', line 41

def self.example_code
  [
    # TODO: default type as text
    # 'line_message(message: "App is ready!!!")',
    'line_message(
      messages: [{
        "text": "App is ready!!!"
      }, {
        "type": "text",
        "text": "Download at https://..."
      }, {
        # check sticker list https://developers.line.biz/media/messaging-api/sticker_list.pdf
        "type": "sticker",
        "packageId": "2",
        "stickerId": "144"
      }]
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


90
91
92
93
94
95
96
# File 'lib/fastlane/plugin/line_message/actions/line_message_action.rb', line 90

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



37
38
39
# File 'lib/fastlane/plugin/line_message/actions/line_message_action.rb', line 37

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

.run(params) ⇒ Object



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

def self.run(params)
  to = params[:to] || ENV["LINE_MESSAGE_TARGET"]
  api_token = params[:api_token] || ENV["LINE_MESSAGE_API_TOKEN"]

  uri = URI.parse('https://api.line.me/v2/bot/message/push')
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true

  request = Net::HTTP::Post.new(uri.request_uri)
  request["Authorization"] = "Bearer #{api_token}"
  request.body = {to: to, messages: params[:messages]}.to_json

  request["Content-Type"] = "application/json"

  response = http.request(request)

  response
end