diff --git a/README.md b/README.md index d4d6aa2..cbbba83 100644 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file diff --git a/emoji_list/example.rb b/emoji_list/example.rb new file mode 100644 index 0000000..1626fa6 --- /dev/null +++ b/emoji_list/example.rb @@ -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 diff --git a/reactions_add/example.rb b/reactions_add/example.rb new file mode 100644 index 0000000..ff960de --- /dev/null +++ b/reactions_add/example.rb @@ -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') \ No newline at end of file diff --git a/search_files/example.rb b/search_files/example.rb new file mode 100644 index 0000000..3be07d4 --- /dev/null +++ b/search_files/example.rb @@ -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') \ No newline at end of file diff --git a/users_list/example.rb b/users_list/example.rb new file mode 100644 index 0000000..8897fc5 --- /dev/null +++ b/users_list/example.rb @@ -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