Class: Slack::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/utilities/slack/cli.rb

Direct Known Subclasses

Mcpeasy::SlackCommands

Instance Method Summary collapse

Instance Method Details

#listObject



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 = options[:limit]
  exclude_archived = !options[: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.message}"
  exit 1
end

#postObject



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 = options[:channel]
  text = options[:message]
  username = options[:username]
  thread_ts = options[:timestamp]

  response = tool.post_message(
    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.message}"
  exit 1
end

#testObject



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.message}"
  exit 1
end