Class: Slack::CLI
- Inherits:
-
Thor
- Object
- Thor
- Slack::CLI
- Defined in:
- lib/utilities/slack/cli.rb
Direct Known Subclasses
Instance Method Summary collapse
Instance Method Details
#list ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/utilities/slack/cli.rb', line 28 def list all_channels = [] cursor = nil limit = [:limit] exclude_archived = ![:include_archived] loop do result = tool.list_channels(limit: limit, cursor: cursor, exclude_archived: exclude_archived) all_channels.concat(result[:channels]) break unless result[:has_more] && all_channels.count < limit cursor = result[:next_cursor] end if all_channels && !all_channels.empty? puts "📋 Available channels (#{all_channels.count} total):" all_channels.each do |channel| puts " ##{channel[:name]} (ID: #{channel[:id]})" end end rescue RuntimeError => e warn "❌ Failed to list channels: #{e.}" exit 1 end |
#post ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/utilities/slack/cli.rb', line 58 def post channel = [:channel] text = [:message] username = [:username] thread_ts = [:timestamp] response = tool.( channel: channel, text: text, username: username, thread_ts: thread_ts ) if response["ok"] puts "✅ Message posted successfully to ##{channel}" puts " Message timestamp: #{response["ts"]}" else warn "❌ Failed to post message: #{response["error"]}" exit 1 end rescue RuntimeError => e warn "❌ Unexpected error: #{e.}" exit 1 end |
#test ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/utilities/slack/cli.rb', line 10 def test response = tool.test_connection if response["ok"] puts "✅ Successfully connected to Slack" puts " Bot name: #{response["user"]}" puts " Team: #{response["team"]}" else warn "❌ Authentication failed: #{response["error"]}" end rescue RuntimeError => e puts "❌ Failed to connect to Slack: #{e.}" exit 1 end |