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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/heathrow/wizards/slack_wizard.rb', line 11
def self.run
puts "\n=== Slack Setup Wizard ==="
puts "This will help you configure Slack integration for Heathrow.\n\n"
puts "You'll need a Slack API token. You can get one by:"
puts "1. Creating a Slack App at https://api.slack.com/apps"
puts "2. Installing it to your workspace"
puts "3. Getting a User OAuth Token (xoxp-...) or Bot Token (xoxb-...)"
puts "\nFor full access to all channels and DMs, use a User Token."
puts "For limited bot access, use a Bot Token.\n\n"
config = {}
print "Enter your Slack API token (xoxp-... or xoxb-...): "
config['api_token'] = gets.chomp
print "\nTesting connection..."
test_source = Heathrow::Sources::Slack.new(config)
unless test_source.test_connection
puts "\nFailed to connect. Please check your token and try again."
return nil
end
puts " Success!\n\n"
print "Enter a name for this workspace (optional, for display): "
workspace = gets.chomp
config['workspace'] = workspace unless workspace.empty?
puts "\nChannel Configuration:"
puts "1. Monitor all channels I have access to (default)"
puts "2. Monitor specific channels only"
print "Choose option [1]: "
choice = gets.chomp
choice = '1' if choice.empty?
if choice == '2'
puts "\nEnter channel IDs to monitor (one per line, empty line to finish):"
puts "Example: C1234567890"
puts "You can find channel IDs in Slack by right-clicking a channel."
channels = []
loop do
print "> "
channel = gets.chomp
break if channel.empty?
channels << channel
end
config['channel_ids'] = channels unless channels.empty?
end
puts "\nDirect Message Configuration:"
puts "1. Monitor all DMs (default)"
puts "2. Monitor specific users only"
print "Choose option [1]: "
choice = gets.chomp
choice = '1' if choice.empty?
if choice == '2'
puts "\nEnter user IDs to monitor DMs with (one per line, empty line to finish):"
puts "Example: U1234567890"
users = []
loop do
print "> "
user = gets.chomp
break if user.empty?
users << user
end
config['dm_user_ids'] = users unless users.empty?
end
print "\nHow often to fetch messages (in seconds) [300]: "
interval = gets.chomp
config['fetch_interval'] = interval.empty? ? 300 : interval.to_i
source_name = workspace.empty? ? 'slack' : "slack_#{workspace.downcase.gsub(/\s+/, '_')}"
config_file = File.join(Dir.home, '.config', 'heathrow', 'sources', "#{source_name}.json")
FileUtils.mkdir_p(File.dirname(config_file))
File.write(config_file, JSON.pretty_generate(config))
puts "\n✓ Slack configuration saved to: #{config_file}"
puts "\nYou can now use this source in Heathrow!"
puts "The source will appear as: #{source_name}"
config
end
|