Class: SlackProcessor
- Defined in:
- lib/Processors/SlackProcessor.rb
Defined Under Namespace
Classes: Payload
Instance Attribute Summary collapse
-
#attachmentGroupByNumber ⇒ Object
Returns the value of attribute attachmentGroupByNumber.
-
#botToken ⇒ Object
Returns the value of attribute botToken.
-
#inCommingWebHookURL ⇒ Object
Returns the value of attribute inCommingWebHookURL.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#targetChannel ⇒ Object
Returns the value of attribute targetChannel.
-
#timeZoneOffset ⇒ Object
Returns the value of attribute timeZoneOffset.
Attributes inherited from Processor
#baseExecutePath, #config, #configFilePath
Instance Method Summary collapse
-
#initialize(config, configFilePath, baseExecutePath) ⇒ SlackProcessor
constructor
A new instance of SlackProcessor.
- #processReviews(reviews, platform) ⇒ Object
- #sendWelcomMessage(platform) ⇒ Object
Constructor Details
#initialize(config, configFilePath, baseExecutePath) ⇒ SlackProcessor
Returns a new instance of SlackProcessor.
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/Processors/SlackProcessor.rb', line 15 def initialize(config, configFilePath, baseExecutePath) @config = config @configFilePath = configFilePath @baseExecutePath = baseExecutePath @logger = ZLogger.new(baseExecutePath) @botToken = config["slackBotToken"] @inCommingWebHookURL = config["slackInCommingWebHookURL"] @targetChannel = config["slackBotTargetChannel"] @timeZoneOffset = Helper.unwrapRequiredParameter(config, "slackTimeZoneOffset") @attachmentGroupByNumber = 1 if !config['slackAttachmentGroupByNumber'].nil? && config['slackAttachmentGroupByNumber'] != "" && config['slackAttachmentGroupByNumber'].to_i > 0 && config['slackAttachmentGroupByNumber'].to_i < 100 @attachmentGroupByNumber = config['slackAttachmentGroupByNumber'].to_i end if (botToken.nil? && inCommingWebHookURL.nil?) || (botToken == "" && inCommingWebHookURL == "") raise "must specify slackBotToken or slackInCommingWebHookURL in SlackProcessor." elsif !botToken.nil? && botToken != "" && (targetChannel.nil? || targetChannel == "") raise "must specify slackBotTargetChannel in SlackProcessor." end puts "[SlackProcessor] Init Success." end |
Instance Attribute Details
#attachmentGroupByNumber ⇒ Object
Returns the value of attribute attachmentGroupByNumber.
13 14 15 |
# File 'lib/Processors/SlackProcessor.rb', line 13 def @attachmentGroupByNumber end |
#botToken ⇒ Object
Returns the value of attribute botToken.
13 14 15 |
# File 'lib/Processors/SlackProcessor.rb', line 13 def botToken @botToken end |
#inCommingWebHookURL ⇒ Object
Returns the value of attribute inCommingWebHookURL.
13 14 15 |
# File 'lib/Processors/SlackProcessor.rb', line 13 def inCommingWebHookURL @inCommingWebHookURL end |
#logger ⇒ Object
Returns the value of attribute logger.
13 14 15 |
# File 'lib/Processors/SlackProcessor.rb', line 13 def logger @logger end |
#targetChannel ⇒ Object
Returns the value of attribute targetChannel.
13 14 15 |
# File 'lib/Processors/SlackProcessor.rb', line 13 def targetChannel @targetChannel end |
#timeZoneOffset ⇒ Object
Returns the value of attribute timeZoneOffset.
13 14 15 |
# File 'lib/Processors/SlackProcessor.rb', line 13 def timeZoneOffset @timeZoneOffset end |
Instance Method Details
#processReviews(reviews, platform) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 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 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/Processors/SlackProcessor.rb', line 40 def processReviews(reviews, platform) if reviews.length < 1 return reviews end pendingPayloads = [] # Slack Message Limit: posting one message per second per channel reviews.each_slice() do |reviewGroup| payload = Payload.new() payload. = [] reviewGroup.each do |review| = Payload::Attachment.new() stars = "★" * review. + "☆" * (5 - review.) color = review. >= 4 ? "good" : (review. > 2 ? "warning" : "danger") date = Time.at(review.createdDateTimestamp).getlocal(timeZoneOffset) title = "#{stars}" if !review.title.nil? title = "#{review.title} - #{stars}" end .color = color . = review.userName .fallback = title .title = title .text = review.body . = "#{platform} - #{review.platform} - #{review.appVersion} - #{review.territory} - <#{review.url}|#{date}>" payload..append() end pendingPayloads.append(payload) end loop do payload = pendingPayloads.shift result = request(payload) if !result[:ok] logger.logError(payload) logger.logError(result) if result[:message] == "ratelimited" puts "[SlackProcessor] Reached Rate Limited, sleep 1 sec..." sleep(1) pendingPayloads.insert(0, payload) end end puts "[SlackProcessor] Send new Review messages, rest: #{pendingPayloads.length}" break if pendingPayloads.length < 1 end return reviews end |
#sendWelcomMessage(platform) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/Processors/SlackProcessor.rb', line 98 def sendWelcomMessage(platform) payload = Payload.new() payload. = [] = Payload::Attachment.new() title = "ZReviewTender Standing By :astronaut:" body = "#{platform} Init Success!, will resend App Review to this channel automatically." .color = "good" . = "ZhgChgLi" .fallback = title .title = title .text = body . = "<https://github.com/ZhgChgLi/ZReviewTender|ZReviewTender>, <https://github.com/ZhgChgLi/ZReviewTender/issues|Report an issue>, Powered by <https://zhgchg.li|ZhgChgLi>." payload..append() puts "[SlackProcessor] sendWelcomMessage(#{title})" request(payload) end |