slack-ruby-client-bhe 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +17 -0
- data/.gitignore +4 -0
- data/.gitmodules +3 -0
- data/.rspec +2 -0
- data/.rubocop.yml +6 -0
- data/.rubocop_todo.yml +78 -0
- data/.travis.yml +26 -0
- data/CHANGELOG.md +79 -0
- data/CONTRIBUTING.md +157 -0
- data/Gemfile +5 -0
- data/LICENSE.md +22 -0
- data/README.md +385 -0
- data/RELEASING.md +69 -0
- data/Rakefile +19 -0
- data/UPGRADING.md +26 -0
- data/bin/commands.rb +21 -0
- data/bin/commands/api.rb +14 -0
- data/bin/commands/auth.rb +12 -0
- data/bin/commands/channels.rb +149 -0
- data/bin/commands/chat.rb +47 -0
- data/bin/commands/dnd.rb +47 -0
- data/bin/commands/emoji.rb +12 -0
- data/bin/commands/files.rb +72 -0
- data/bin/commands/groups.rb +167 -0
- data/bin/commands/im.rb +53 -0
- data/bin/commands/mpim.rb +53 -0
- data/bin/commands/oauth.rb +16 -0
- data/bin/commands/pins.rb +37 -0
- data/bin/commands/reactions.rb +53 -0
- data/bin/commands/rtm.rb +15 -0
- data/bin/commands/search.rb +40 -0
- data/bin/commands/stars.rb +37 -0
- data/bin/commands/team.rb +32 -0
- data/bin/commands/usergroups.rb +73 -0
- data/bin/commands/users.rb +57 -0
- data/bin/slack +50 -0
- data/examples/hi_real_time/Gemfile +5 -0
- data/examples/hi_real_time/hi.gif +0 -0
- data/examples/hi_real_time/hi.rb +32 -0
- data/examples/hi_real_time_and_web/Gemfile +5 -0
- data/examples/hi_real_time_and_web/hi.gif +0 -0
- data/examples/hi_real_time_and_web/hi.rb +24 -0
- data/examples/hi_real_time_async/Gemfile +5 -0
- data/examples/hi_real_time_async/hi.rb +29 -0
- data/examples/hi_web/Gemfile +3 -0
- data/examples/hi_web/hi.gif +0 -0
- data/examples/hi_web/hi.rb +12 -0
- data/examples/new_ticket/Gemfile +3 -0
- data/examples/new_ticket/new_ticket.rb +25 -0
- data/lib/slack-ruby-client.rb +29 -0
- data/lib/slack.rb +1 -0
- data/lib/slack/config.rb +21 -0
- data/lib/slack/messages/formatting.rb +30 -0
- data/lib/slack/real_time/api/message.rb +20 -0
- data/lib/slack/real_time/api/message_id.rb +14 -0
- data/lib/slack/real_time/api/ping.rb +16 -0
- data/lib/slack/real_time/api/typing.rb +17 -0
- data/lib/slack/real_time/client.rb +152 -0
- data/lib/slack/real_time/concurrency.rb +8 -0
- data/lib/slack/real_time/concurrency/celluloid.rb +93 -0
- data/lib/slack/real_time/concurrency/eventmachine.rb +39 -0
- data/lib/slack/real_time/config.rb +55 -0
- data/lib/slack/real_time/socket.rb +81 -0
- data/lib/slack/version.rb +3 -0
- data/lib/slack/web/api/endpoints.rb +53 -0
- data/lib/slack/web/api/endpoints/api.rb +24 -0
- data/lib/slack/web/api/endpoints/auth.rb +20 -0
- data/lib/slack/web/api/endpoints/channels.rb +220 -0
- data/lib/slack/web/api/endpoints/chat.rb +91 -0
- data/lib/slack/web/api/endpoints/dnd.rb +64 -0
- data/lib/slack/web/api/endpoints/emoji.rb +20 -0
- data/lib/slack/web/api/endpoints/files.rb +108 -0
- data/lib/slack/web/api/endpoints/groups.rb +247 -0
- data/lib/slack/web/api/endpoints/im.rb +85 -0
- data/lib/slack/web/api/endpoints/mpim.rb +84 -0
- data/lib/slack/web/api/endpoints/oauth.rb +32 -0
- data/lib/slack/web/api/endpoints/pins.rb +64 -0
- data/lib/slack/web/api/endpoints/presence.rb +23 -0
- data/lib/slack/web/api/endpoints/reactions.rb +89 -0
- data/lib/slack/web/api/endpoints/rtm.rb +27 -0
- data/lib/slack/web/api/endpoints/search.rb +65 -0
- data/lib/slack/web/api/endpoints/stars.rb +61 -0
- data/lib/slack/web/api/endpoints/team.rb +47 -0
- data/lib/slack/web/api/endpoints/usergroups.rb +113 -0
- data/lib/slack/web/api/endpoints/users.rb +73 -0
- data/lib/slack/web/api/error.rb +14 -0
- data/lib/slack/web/api/mixins.rb +3 -0
- data/lib/slack/web/api/mixins/channels.id.json +20 -0
- data/lib/slack/web/api/mixins/channels.id.rb +26 -0
- data/lib/slack/web/api/mixins/groups.id.json +20 -0
- data/lib/slack/web/api/mixins/groups.id.rb +26 -0
- data/lib/slack/web/api/mixins/users.id.json +20 -0
- data/lib/slack/web/api/mixins/users.id.rb +26 -0
- data/lib/slack/web/api/patches/chat.1.text-attachments-required.patch +13 -0
- data/lib/slack/web/api/patches/chat.2.attachments-json.patch +17 -0
- data/lib/slack/web/api/schema/group.json +14 -0
- data/lib/slack/web/api/schema/method.json +45 -0
- data/lib/slack/web/api/tasks/generate.rake +61 -0
- data/lib/slack/web/api/templates/command.erb +34 -0
- data/lib/slack/web/api/templates/commands.erb +5 -0
- data/lib/slack/web/api/templates/endpoints.erb +21 -0
- data/lib/slack/web/api/templates/method.erb +49 -0
- data/lib/slack/web/client.rb +28 -0
- data/lib/slack/web/config.rb +41 -0
- data/lib/slack/web/faraday/connection.rb +29 -0
- data/lib/slack/web/faraday/request.rb +39 -0
- data/lib/slack/web/faraday/response/raise_error.rb +15 -0
- data/lib/slack_ruby_client.rb +1 -0
- data/screenshots/register-bot.png +0 -0
- data/slack-ruby-client.gemspec +31 -0
- data/slack.png +0 -0
- data/spec/fixtures/slack/web/429_error.yml +83 -0
- data/spec/fixtures/slack/web/auth_test_error.yml +48 -0
- data/spec/fixtures/slack/web/auth_test_success.yml +57 -0
- data/spec/fixtures/slack/web/channels_info.yml +46 -0
- data/spec/fixtures/slack/web/groups_info.yml +43 -0
- data/spec/fixtures/slack/web/rtm_start.yml +73 -0
- data/spec/fixtures/slack/web/users_info.yml +130 -0
- data/spec/fixtures/slack/web/users_list.yml +72 -0
- data/spec/integration/integration_spec.rb +107 -0
- data/spec/slack/config_spec.rb +14 -0
- data/spec/slack/messages/formatting_spec.rb +43 -0
- data/spec/slack/real_time/api/message_spec.rb +15 -0
- data/spec/slack/real_time/api/ping_spec.rb +15 -0
- data/spec/slack/real_time/api/typing_spec.rb +15 -0
- data/spec/slack/real_time/client_spec.rb +198 -0
- data/spec/slack/real_time/concurrency/celluloid_spec.rb +58 -0
- data/spec/slack/real_time/concurrency/eventmachine_spec.rb +49 -0
- data/spec/slack/slack_spec.rb +58 -0
- data/spec/slack/version_spec.rb +7 -0
- data/spec/slack/web/api/endpoints/auth_spec.rb +20 -0
- data/spec/slack/web/api/endpoints/channels_spec.rb +11 -0
- data/spec/slack/web/api/endpoints/chat_spec.rb +33 -0
- data/spec/slack/web/api/endpoints/groups_spec.rb +11 -0
- data/spec/slack/web/api/endpoints/users_spec.rb +17 -0
- data/spec/slack/web/api/error_spec.rb +14 -0
- data/spec/slack/web/api/mixins/channels_spec.rb +31 -0
- data/spec/slack/web/api/mixins/groups_spec.rb +31 -0
- data/spec/slack/web/api/mixins/users_spec.rb +31 -0
- data/spec/slack/web/client_spec.rb +134 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/support/queue_with_timeout.rb +34 -0
- data/spec/support/real_time/concurrency/mock.rb +31 -0
- data/spec/support/real_time/connected_client.rb +16 -0
- data/spec/support/token.rb +10 -0
- data/spec/support/vcr.rb +8 -0
- metadata +392 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
# This file was auto-generated by lib/slack/web/api/tasks/generate.rake
|
2
|
+
|
3
|
+
desc 'Team methods.'
|
4
|
+
command 'team' do |g|
|
5
|
+
g.desc 'This method is used to get the access logs for users on a team.'
|
6
|
+
g.long_desc %( This method is used to get the access logs for users on a team. )
|
7
|
+
g.command 'accessLogs' do |c|
|
8
|
+
c.action do |_global_options, options, _args|
|
9
|
+
puts JSON.dump($client.team_accessLogs(options))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
g.desc 'This method provides information about your team.'
|
14
|
+
g.long_desc %( This method provides information about your team. )
|
15
|
+
g.command 'info' do |c|
|
16
|
+
c.action do |_global_options, options, _args|
|
17
|
+
puts JSON.dump($client.team_info(options))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
g.desc 'This method lists the integration activity logs for a team, including when integrations are added, modified and removed. This method can only be called by Admins.'
|
22
|
+
g.long_desc %( This method lists the integration activity logs for a team, including when integrations are added, modified and removed. This method can only be called by Admins. )
|
23
|
+
g.command 'integrationLogs' do |c|
|
24
|
+
c.flag 'service_id', desc: 'Filter logs to this service. Defaults to all logs.'
|
25
|
+
c.flag 'app_id', desc: 'Filter logs to this Slack app. Defaults to all logs.'
|
26
|
+
c.flag 'user', desc: "Filter logs generated by this user's actions. Defaults to all logs."
|
27
|
+
c.flag 'change_type', desc: 'Filter logs with this change type. Defaults to all logs.'
|
28
|
+
c.action do |_global_options, options, _args|
|
29
|
+
puts JSON.dump($client.team_integrationLogs(options))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# This file was auto-generated by lib/slack/web/api/tasks/generate.rake
|
2
|
+
|
3
|
+
desc "Get info on your team's user groups."
|
4
|
+
command 'usergroups' do |g|
|
5
|
+
g.desc 'This method is used to create a user group.'
|
6
|
+
g.long_desc %( This method is used to create a user group. )
|
7
|
+
g.command 'create' do |c|
|
8
|
+
c.flag 'name', desc: 'A name for the user group. Must be unique among user groups.'
|
9
|
+
c.flag 'handle', desc: 'A mention handle. Must be unique among channels, users and user groups.'
|
10
|
+
c.flag 'description', desc: 'A short description of the user group.'
|
11
|
+
c.flag 'channels', desc: 'A comma separated string of encoded channel IDs for which the user group uses as a default.'
|
12
|
+
c.flag 'include_count', desc: 'Include the number of users in each user group.'
|
13
|
+
c.action do |_global_options, options, _args|
|
14
|
+
puts JSON.dump($client.usergroups_create(options))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
g.desc 'This method disables an existing user group.'
|
19
|
+
g.long_desc %( This method disables an existing user group. )
|
20
|
+
g.command 'disable' do |c|
|
21
|
+
c.flag 'usergroup', desc: 'The encoded ID of the user group to disable.'
|
22
|
+
c.flag 'include_count', desc: 'Include the number of users in the user group.'
|
23
|
+
c.action do |_global_options, options, _args|
|
24
|
+
puts JSON.dump($client.usergroups_disable(options))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
g.desc 'This method enables a user group which was previously disabled.'
|
29
|
+
g.long_desc %( This method enables a user group which was previously disabled. )
|
30
|
+
g.command 'enable' do |c|
|
31
|
+
c.flag 'usergroup', desc: 'The encoded ID of the user group to enable.'
|
32
|
+
c.flag 'include_count', desc: 'Include the number of users in the user group.'
|
33
|
+
c.action do |_global_options, options, _args|
|
34
|
+
puts JSON.dump($client.usergroups_enable(options))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
g.desc 'This method returns a list of all user groups in the team. This can optionally include disabled user groups.'
|
39
|
+
g.long_desc %( This method returns a list of all user groups in the team. This can optionally include disabled user groups. )
|
40
|
+
g.command 'list' do |c|
|
41
|
+
c.flag 'include_disabled', desc: 'Include disabled user groups.'
|
42
|
+
c.flag 'include_count', desc: 'Include the number of users in each user group.'
|
43
|
+
c.flag 'include_users', desc: 'Include the list of users for each user group.'
|
44
|
+
c.action do |_global_options, options, _args|
|
45
|
+
puts JSON.dump($client.usergroups_list(options))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
g.desc 'This method updates the properties of an existing user group.'
|
50
|
+
g.long_desc %( This method updates the properties of an existing user group. )
|
51
|
+
g.command 'update' do |c|
|
52
|
+
c.flag 'usergroup', desc: 'The encoded ID of the user group to update.'
|
53
|
+
c.flag 'name', desc: 'A name for the user group. Must be unique among user groups.'
|
54
|
+
c.flag 'handle', desc: 'A mention handle. Must be unique among channels, users and user groups.'
|
55
|
+
c.flag 'description', desc: 'A short description of the user group.'
|
56
|
+
c.flag 'channels', desc: 'A comma separated string of encoded channel IDs for which the user group uses as a default.'
|
57
|
+
c.flag 'include_count', desc: 'Include the number of users in the user group.'
|
58
|
+
c.action do |_global_options, options, _args|
|
59
|
+
puts JSON.dump($client.usergroups_update(options))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
g.desc 'This method updates the list of users that belong to a user group. This method replaces all users in a user group with the list of users provided in the users parameter.'
|
64
|
+
g.long_desc %( This method updates the list of users that belong to a user group. This method replaces all users in a user group with the list of users provided in the users parameter. )
|
65
|
+
g.command 'users' do |c|
|
66
|
+
c.flag 'usergroup', desc: 'The encoded ID of the user group to update.'
|
67
|
+
c.flag 'users', desc: 'A comma separated string of encoded user IDs that represent the entire list of users for the user group.'
|
68
|
+
c.flag 'include_count', desc: 'Include the number of users in the user group.'
|
69
|
+
c.action do |_global_options, options, _args|
|
70
|
+
puts JSON.dump($client.usergroups_users(options))
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# This file was auto-generated by lib/slack/web/api/tasks/generate.rake
|
2
|
+
|
3
|
+
desc 'Get info on members of your Slack team.'
|
4
|
+
command 'users' do |g|
|
5
|
+
g.desc "This method lets you find out information about a user's presence."
|
6
|
+
g.long_desc %( This method lets you find out information about a user's presence. Consult the presence documentation for more details. )
|
7
|
+
g.command 'getPresence' do |c|
|
8
|
+
c.flag 'user', desc: 'User to get presence info on. Defaults to the authed user.'
|
9
|
+
c.action do |_global_options, options, _args|
|
10
|
+
puts JSON.dump($client.users_getPresence(options))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
g.desc 'This method returns information about a team member.'
|
15
|
+
g.long_desc %( This method returns information about a team member. )
|
16
|
+
g.command 'info' do |c|
|
17
|
+
c.flag 'user', desc: 'User to get info on.'
|
18
|
+
c.action do |_global_options, options, _args|
|
19
|
+
puts JSON.dump($client.users_info(options))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
g.desc 'This method returns a list of all users in the team. This includes deleted/deactivated users.'
|
24
|
+
g.long_desc %( This method returns a list of all users in the team. This includes deleted/deactivated users. )
|
25
|
+
g.command 'list' do |c|
|
26
|
+
c.flag 'presence', desc: 'Whether to include presence data in the output.'
|
27
|
+
c.action do |_global_options, options, _args|
|
28
|
+
puts JSON.dump($client.users_list(options))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
g.desc 'This method lets the slack messaging server know that the authenticated user'
|
33
|
+
g.long_desc %( This method lets the slack messaging server know that the authenticated user is currently active. Consult the presence documentation for more details. )
|
34
|
+
g.command 'setActive' do |c|
|
35
|
+
c.action do |_global_options, options, _args|
|
36
|
+
puts JSON.dump($client.users_setActive(options))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
g.desc "This method lets you set the calling user's manual presence."
|
41
|
+
g.long_desc %( This method lets you set the calling user's manual presence. Consult the presence documentation for more details. )
|
42
|
+
g.command 'setPresence' do |c|
|
43
|
+
c.flag 'presence', desc: 'Either auto or away.'
|
44
|
+
c.action do |_global_options, options, _args|
|
45
|
+
puts JSON.dump($client.users_setPresence(options))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
g.desc 'This method returns the ID of a team user.'
|
50
|
+
g.long_desc %( This method returns the ID of a team user. )
|
51
|
+
g.command 'id' do |c|
|
52
|
+
c.flag 'user', desc: 'User to get ID for, prefixed with @.'
|
53
|
+
c.action do |_global_options, options, _args|
|
54
|
+
puts JSON.dump($client.users_id(options))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/bin/slack
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'gli'
|
4
|
+
require 'slack-ruby-client'
|
5
|
+
|
6
|
+
include GLI::App
|
7
|
+
|
8
|
+
program_desc 'Slack client.'
|
9
|
+
|
10
|
+
default_command :help
|
11
|
+
|
12
|
+
switch [:d, :debug], desc: 'Enable debug-level logging.', default_value: false
|
13
|
+
flag [:t, 'slack-api-token'], desc: 'Slack API token.', default_value: ENV['SLACK_API_TOKEN']
|
14
|
+
flag ['vcr-cassette-name'], desc: 'Offline VCR cassette.'
|
15
|
+
|
16
|
+
pre do |global_options, _command, options, _args|
|
17
|
+
# global Slack configuration
|
18
|
+
Slack.config.token = global_options['slack-api-token']
|
19
|
+
help_now! 'Set Slack API token via --slack-api-token or SLACK_API_TOKEN.' unless Slack.config.token && Slack.config.token.length > 0
|
20
|
+
|
21
|
+
if global_options['debug']
|
22
|
+
require 'logger'
|
23
|
+
logger = Logger.new(STDOUT)
|
24
|
+
logger.level = Logger::DEBUG
|
25
|
+
Slack::Web::Client.config.logger = logger
|
26
|
+
end
|
27
|
+
|
28
|
+
$client = Slack::Web::Client.new
|
29
|
+
|
30
|
+
# Offline VCR cassette
|
31
|
+
if global_options['vcr-cassette-name']
|
32
|
+
require 'vcr'
|
33
|
+
VCR.configure do |config|
|
34
|
+
config.cassette_library_dir = 'spec/fixtures/slack'
|
35
|
+
config.hook_into :webmock
|
36
|
+
config.default_cassette_options = { record: :new_episodes }
|
37
|
+
end
|
38
|
+
VCR.insert_cassette global_options['vcr-cassette-name']
|
39
|
+
end
|
40
|
+
|
41
|
+
# remove any nil values from options
|
42
|
+
options.select! { |_k, v| v }
|
43
|
+
|
44
|
+
true
|
45
|
+
end
|
46
|
+
|
47
|
+
$LOAD_PATH.push File.expand_path('..', __FILE__)
|
48
|
+
require 'commands'
|
49
|
+
|
50
|
+
exit run(ARGV)
|
Binary file
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'slack-ruby-client'
|
2
|
+
|
3
|
+
Slack.configure do |config|
|
4
|
+
config.token = ENV['SLACK_API_TOKEN']
|
5
|
+
fail 'Missing ENV[SLACK_API_TOKEN]!' unless config.token
|
6
|
+
end
|
7
|
+
|
8
|
+
client = Slack::RealTime::Client.new
|
9
|
+
|
10
|
+
client.on :hello do
|
11
|
+
puts "Successfully connected, welcome '#{client.self['name']}' to the '#{client.team['name']}' team at https://#{client.team['domain']}.slack.com."
|
12
|
+
end
|
13
|
+
|
14
|
+
client.on :message do |data|
|
15
|
+
puts data
|
16
|
+
|
17
|
+
client.typing channel: data['channel']
|
18
|
+
|
19
|
+
case data['text']
|
20
|
+
when 'bot hi' then
|
21
|
+
client.message channel: data['channel'], text: "Hi <@#{data['user']}>!"
|
22
|
+
when /^bot/ then
|
23
|
+
client.message channel: data['channel'], text: "Sorry <@#{data['user']}>, what?"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
client.on :close do |_data|
|
28
|
+
puts 'Connection closed, exiting.'
|
29
|
+
EM.stop
|
30
|
+
end
|
31
|
+
|
32
|
+
client.start!
|
Binary file
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'slack-ruby-client'
|
2
|
+
|
3
|
+
Slack.configure do |config|
|
4
|
+
config.token = ENV['SLACK_API_TOKEN']
|
5
|
+
fail 'Missing ENV[SLACK_API_TOKEN]!' unless config.token
|
6
|
+
end
|
7
|
+
|
8
|
+
client = Slack::RealTime::Client.new
|
9
|
+
|
10
|
+
client.on :hello do
|
11
|
+
puts "Successfully connected, welcome '#{client.self['name']}' to the '#{client.team['name']}' team at https://#{client.team['domain']}.slack.com."
|
12
|
+
end
|
13
|
+
|
14
|
+
client.on :message do |data|
|
15
|
+
puts data
|
16
|
+
case data['text']
|
17
|
+
when 'bot hi' then
|
18
|
+
client.web_client.chat_postMessage channel: data['channel'], text: "Hi <@#{data['user']}>!"
|
19
|
+
when /^bot/ then
|
20
|
+
client.web_client.chat_postMessage channel: data['channel'], text: "Sorry <@#{data['user']}>, what?"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
client.start!
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'slack-ruby-client'
|
2
|
+
|
3
|
+
Slack.configure do |config|
|
4
|
+
config.token = ENV['SLACK_API_TOKEN']
|
5
|
+
fail 'Missing ENV[SLACK_API_TOKEN]!' unless config.token
|
6
|
+
end
|
7
|
+
|
8
|
+
client = Slack::RealTime::Client.new
|
9
|
+
|
10
|
+
client.on :hello do
|
11
|
+
puts "Successfully connected, welcome '#{client.self['name']}' to the '#{client.team['name']}' team at https://#{client.team['domain']}.slack.com."
|
12
|
+
end
|
13
|
+
|
14
|
+
client.on :message do |data|
|
15
|
+
puts data
|
16
|
+
|
17
|
+
client.typing channel: data['channel']
|
18
|
+
|
19
|
+
case data['text']
|
20
|
+
when 'bot hi' then
|
21
|
+
client.message channel: data['channel'], text: "Hi <@#{data['user']}>!"
|
22
|
+
when /^bot/ then
|
23
|
+
client.message channel: data['channel'], text: "Sorry <@#{data['user']}>, what?"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
EM.run do
|
28
|
+
client.start_async
|
29
|
+
end
|
Binary file
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'slack-ruby-client'
|
2
|
+
|
3
|
+
Slack.configure do |config|
|
4
|
+
config.token = ENV['SLACK_API_TOKEN']
|
5
|
+
fail 'Missing ENV[SLACK_API_TOKEN]!' unless config.token
|
6
|
+
end
|
7
|
+
|
8
|
+
client = Slack::Web::Client.new
|
9
|
+
|
10
|
+
client.auth_test
|
11
|
+
|
12
|
+
client.chat_postMessage(channel: '#general', text: 'Hello World', as_user: true)
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'slack-ruby-client'
|
2
|
+
|
3
|
+
Slack.configure do |config|
|
4
|
+
config.token = ENV['SLACK_API_TOKEN']
|
5
|
+
fail 'Missing ENV[SLACK_API_TOKEN]!' unless config.token
|
6
|
+
end
|
7
|
+
|
8
|
+
client = Slack::Web::Client.new
|
9
|
+
|
10
|
+
client.auth_test
|
11
|
+
|
12
|
+
client.chat_postMessage(
|
13
|
+
channel: '#general',
|
14
|
+
as_user: true,
|
15
|
+
attachments: [
|
16
|
+
{
|
17
|
+
fallback: "Ticket #1943: Can't rest my password - https://groove.hq/path/to/ticket/1943",
|
18
|
+
pretext: 'New ticket from Andrea Lee',
|
19
|
+
title: "Ticket #1943: Can't reset my password",
|
20
|
+
title_link: 'https://groove.hq/path/to/ticket/1943',
|
21
|
+
text: 'Help! I tried to reset my password but nothing happened!',
|
22
|
+
color: '#7CD197'
|
23
|
+
}
|
24
|
+
]
|
25
|
+
)
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'slack/version'
|
2
|
+
require 'slack/config'
|
3
|
+
|
4
|
+
# Messages
|
5
|
+
require 'slack/messages/formatting'
|
6
|
+
|
7
|
+
# Web API
|
8
|
+
require 'faraday'
|
9
|
+
require 'faraday_middleware'
|
10
|
+
require 'json'
|
11
|
+
require 'logger'
|
12
|
+
require 'slack/web/config'
|
13
|
+
require 'slack/web/api/error'
|
14
|
+
require 'slack/web/faraday/response/raise_error'
|
15
|
+
require 'slack/web/faraday/connection'
|
16
|
+
require 'slack/web/faraday/request'
|
17
|
+
require 'slack/web/api/mixins'
|
18
|
+
require 'slack/web/api/endpoints'
|
19
|
+
require 'slack/web/client'
|
20
|
+
|
21
|
+
# RealTime API
|
22
|
+
require 'slack/real_time/concurrency'
|
23
|
+
require 'slack/real_time/socket'
|
24
|
+
require 'slack/real_time/api/message_id'
|
25
|
+
require 'slack/real_time/api/ping'
|
26
|
+
require 'slack/real_time/api/message'
|
27
|
+
require 'slack/real_time/api/typing'
|
28
|
+
require 'slack/real_time/config'
|
29
|
+
require 'slack/real_time/client'
|
data/lib/slack.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'slack-ruby-client'
|
data/lib/slack/config.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Slack
|
2
|
+
module Config
|
3
|
+
extend self
|
4
|
+
|
5
|
+
attr_accessor :token
|
6
|
+
|
7
|
+
def reset
|
8
|
+
self.token = nil
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def configure
|
14
|
+
block_given? ? yield(Config) : Config
|
15
|
+
end
|
16
|
+
|
17
|
+
def config
|
18
|
+
Config
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Slack
|
3
|
+
module Messages
|
4
|
+
module Formatting
|
5
|
+
class << self
|
6
|
+
#
|
7
|
+
# Unescape a message.
|
8
|
+
# @see https://api.slack.com/docs/formatting
|
9
|
+
#
|
10
|
+
def unescape(message)
|
11
|
+
CGI.unescapeHTML(message.gsub(/[“”]/, '"')
|
12
|
+
.gsub(/[‘’]/, "'")
|
13
|
+
.gsub(/<(?<sign>[?@#!]?)(?<dt>.*?)>/) do |match|
|
14
|
+
sign = $~[:sign]
|
15
|
+
dt = $~[:dt]
|
16
|
+
rhs = dt.split('|', 2).last
|
17
|
+
case sign
|
18
|
+
when '@', '!'
|
19
|
+
"@#{rhs}"
|
20
|
+
when '#'
|
21
|
+
"##{rhs}"
|
22
|
+
else
|
23
|
+
rhs
|
24
|
+
end
|
25
|
+
end)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|