Class: Fastlane::Actions::TelegramAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::TelegramAction
- Defined in:
- lib/fastlane/plugin/telegram/actions/telegram_action.rb
Class Method Summary collapse
- .authors ⇒ Object
- .available_options ⇒ Object
- .description ⇒ Object
- .details ⇒ Object
- .is_supported?(platform) ⇒ Boolean
- .return_value ⇒ Object
- .run(params) ⇒ Object
Class Method Details
.authors ⇒ Object
58 59 60 |
# File 'lib/fastlane/plugin/telegram/actions/telegram_action.rb', line 58 def self. ["sergpetrov"] end |
.available_options ⇒ Object
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 110 111 112 113 |
# File 'lib/fastlane/plugin/telegram/actions/telegram_action.rb', line 70 def self. [ 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: :file, env_name: "TELEGRAM_FILE", description: "File path to the file to be sent", optional: true, type: String), FastlaneCore::ConfigItem.new(key: :mime_type, env_name: "TELEGRAM_FILE_MIME_TYPE", description: "Mime type of file to be sent", optional: true, 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), FastlaneCore::ConfigItem.new(key: :message_thread_id, env_name: "TELEGRAM_MESSAGE_THREAD_ID", description: "message_thread_id TOPIC GROUP CHAT", optional: true, type: String) ] end |
.description ⇒ Object
54 55 56 |
# File 'lib/fastlane/plugin/telegram/actions/telegram_action.rb', line 54 def self.description "Allows post messages to telegram channel" end |
.details ⇒ Object
66 67 68 |
# File 'lib/fastlane/plugin/telegram/actions/telegram_action.rb', line 66 def self.details "Allows post messages to telegram channel" end |
.is_supported?(platform) ⇒ Boolean
115 116 117 |
# File 'lib/fastlane/plugin/telegram/actions/telegram_action.rb', line 115 def self.is_supported?(platform) true end |
.return_value ⇒ Object
62 63 64 |
# File 'lib/fastlane/plugin/telegram/actions/telegram_action.rb', line 62 def self.return_value response end |
.run(params) ⇒ Object
4 5 6 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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fastlane/plugin/telegram/actions/telegram_action.rb', line 4 def self.run(params) UI.("Sending message to a telegram channel") token = params[:token] chat_id = params[:chat_id] text = params[:text] parse_mode = params[:parse_mode] file_path = params[:file] mime_type = params[:mime_type] = params[:message_thread_id] file = nil if file_path != nil if File.exist?(file_path) if mime_type == nil UI.user_error!("The mime type, required for send file") end file = UploadIO.new(file_path, mime_type) end end if file_path != nil && file == nil UI.("Can't find file on path location") end method = (file == nil ? "sendMessage" : "sendDocument") uri = URI.parse("https://api.telegram.org/bot#{token}/#{method}") http = Net::HTTP.new(uri.host, uri.port) if params[:proxy] proxy_uri = URI.parse(params[:proxy]) http = Net::HTTP.new(uri.host, uri.port, proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password) end http.use_ssl = true require 'net/http/post/multipart' text_parameter = (file == nil ? "text" : "caption") request = Net::HTTP::Post::Multipart.new(uri, { "message_thread_id" => , "chat_id" => chat_id, text_parameter => text, "parse_mode" => parse_mode, "document" => file }) response = http.request(request) end |