class Fastlane::Actions::TelegramAction

Public Class Methods

authors() click to toggle source
# File lib/fastlane/plugin/telegram/actions/telegram_action.rb, line 30
def self.authors
  ["sergpetrov"]
end
available_options() click to toggle source
# File lib/fastlane/plugin/telegram/actions/telegram_action.rb, line 42
def self.available_options
  [
             FastlaneCore::ConfigItem.new(key: :token,
                                     env_name: "TELEGRAM_TOKEN",
                                  description: "A unique authentication token given when a bot is created",
                                     optional: false,
                                         type: String),
             FastlaneCore::ConfigItem.new(key: :chat_id,
                                     env_name: "TELEGRAM_CHAT_ID",
                                  description: "Unique identifier for the target chat (not in the format @channel). For getting chat id you can send any message to your bot and get chat id from response https://api.telegram.org/botYOUR_TOKEN/getupdates",
                                     optional: false,
                                         type: String),
             FastlaneCore::ConfigItem.new(key: :text,
                                     env_name: "TELEGRAM_TEXT",
                                  description: "Text of the message to be sent",
                                     optional: false,
                                         type: String),
             FastlaneCore::ConfigItem.new(key: :parse_mode,
                                     env_name: "TELEGRAM_PARSE_MODE",
                                  description: "Param (Markdown / HTML) for using markdown or HTML support in message",
                                     optional: true,
                                         type: String),
             FastlaneCore::ConfigItem.new(key: :proxy,
                                     env_name: "TELEGRAM_PROXY",
                                  description: "Proxy URL to be used in network requests. Example: (https://123.45.67.89:80)",
                                     optional: true,
                                         type: String)
          ]
end
description() click to toggle source
# File lib/fastlane/plugin/telegram/actions/telegram_action.rb, line 26
def self.description
  "Allows post messages to telegram channel"
end
details() click to toggle source
# File lib/fastlane/plugin/telegram/actions/telegram_action.rb, line 38
def self.details
  "Allows post messages to telegram channel"
end
is_supported?(platform) click to toggle source
# File lib/fastlane/plugin/telegram/actions/telegram_action.rb, line 72
def self.is_supported?(platform)
  true
end
return_value() click to toggle source
# File lib/fastlane/plugin/telegram/actions/telegram_action.rb, line 34
def self.return_value
  response
end
run(params) click to toggle source
# File lib/fastlane/plugin/telegram/actions/telegram_action.rb, line 4
def self.run(params)
  UI.message("Sending message to a telegram channel")

  token = params[:token]
  chat_id = params[:chat_id]
  text = params[:text]
  parse_mode = params[:parse_mode]

  uri = URI.parse("https://api.telegram.org/bot#{token}/sendMessage")
  
  if params[:proxy] 
    proxy_uri = URI.parse(params[:proxy])
    http = Net::HTTP.new(uri.host, uri.port, proxy_uri.host, proxy_uri.port)
    http.use_ssl = true
    request = Net::HTTP::Post.new(uri.request_uri)
    request.set_form_data({"chat_id" => chat_id, "text" => text, "parse_mode" => parse_mode})
    response = http.request(request)
  else
    response = Net::HTTP.post_form(uri, {:chat_id => chat_id, :text => text, :parse_mode => parse_mode})
  end
end