Sha256: 16548ff0f1ff0148b44fa8384c2b6fd256cc6007a2b380635c7d749c66629ed5

Contents?: true

Size: 1.09 KB

Versions: 9

Compression:

Stored size: 1.09 KB

Contents

require 'chronic'
require 'slack-ruby-client'

Slack.configure do |config|
  config.token = ENV['SLACK_API_TOKEN']
  raise 'Missing ENV[SLACK_API_TOKEN]!' unless config.token
end

module DevTrainingBot
  class SlackService
    def initialize
      @client = Slack::Web::Client.new
      @client.auth_test
    end

    def create_poll(topics)
      return no_topics_available if topics.empty?

      next_friday = Chronic.parse('next friday').to_date

      @client.chat_command channel: ENV['SLACK_CHANNEL'],
                           command: '/poll',
                           text: "\"@here Vote for the next dev learning! [#{next_friday}]\" #{topics}"
    end

    def no_topics_available
      @client.chat_postMessage channel: ENV['SLACK_CHANNEL'],
                               text: '<!here> Please propose your topics for the next Dev Learning!',
                               as_user: true
    end

    def link_doc
      @client.chat_postMessage channel: ENV['SLACK_CHANNEL'],
                               text: GoogleDriveService::DOC_URL,
                               as_user: true
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
dev_training_bot-1.1.2 lib/dev_training_bot/services/slack_service.rb
dev_training_bot-1.1.1 lib/dev_training_bot/services/slack_service.rb
dev_training_bot-1.1.0 lib/dev_training_bot/services/slack_service.rb
dev_training_bot-1.0.5 lib/dev_training_bot/services/slack_service.rb
dev_training_bot-1.0.4 lib/dev_training_bot/services/slack_service.rb
dev_training_bot-1.0.3 lib/dev_training_bot/services/slack_service.rb
dev_training_bot-1.0.2 lib/dev_training_bot/services/slack_service.rb
dev_training_bot-1.0.1 lib/dev_training_bot/services/slack_service.rb
dev_training_bot-1.0.0 lib/dev_training_bot/services/slack_service.rb