Skip to content

Commit

Permalink
First Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Luciano Adonis committed Mar 27, 2019
1 parent 0b6b621 commit 5a508ce
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 2 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
# Slack-Ruby-Examples
Other methods of the Slack API using the slack-ruby-client.
# Slack Ruby Examples
Examples of methods that you will find useful sooner or later of the [Slack API](https://api.slack.com/methods) using the [slack-ruby-client](https://github.com/slack-ruby/slack-ruby-client).

## Methods:

- [emoji.list](https://api.slack.com/methods/emoji.list): i would say the only possible use for this is spam, but can probe useful is you want something like the URL.
- [reactions.add](https://api.slack.com/methods/reactions.add): reacting like there's no tomorrow, but you need the timestamp of the message.
- [search.files](https://api.slack.com/methods/search.files): for using this method you need to use an user token.
- [users.list](https://api.slack.com/methods/users.list): you can get all the user info that is accessible.

## More info:

- [Enseñandole a un bot a ser como tú](https://medium.com/devschile/un-bot-como-tu-3868bb90a627): i explain how to get your user token and how methods work but in spanish.
20 changes: 20 additions & 0 deletions emoji_list/example.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'slack-ruby-client'

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

rclient = Slack::RealTime::Client.new
wclient = Slack::Web::Client.new

message = ''
wclient.emoji_list.emoji.each do |c|
# "icon": "https:\/\/my.slack.com\/emoji\/icon\/icon_name.png"
message += ":#{c[0]}:"
end



rclient.web_client.chat_postMessage channel: '#yourchannel',
text: message
10 changes: 10 additions & 0 deletions reactions_add/example.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'slack-ruby-client'

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

client = Slack::Web::Client.new

client.reactions_add(channel: '#yourchannel', name: 'joy', timestamp: '1123581321.345589')
10 changes: 10 additions & 0 deletions search_files/example.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'slack-ruby-client'

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

client = Slack::Web::Client.new

p client.search_files(query: 'energon')
17 changes: 17 additions & 0 deletions users_list/example.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'slack-ruby-client'

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

client = Slack::Web::Client.new

client.users_list.members.each do |c|
p "Name: #{c.name}, Email: #{c.profile.email}"
# You can also check if the users are available with something like this:
#
# if c.deleted == false
# "Name: #{c.name}, Email: #{c.profile.email}"
# end
end

0 comments on commit 5a508ce

Please sign in to comment.