slack-ruby-bot-server 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +2 -0
  5. data/.rubocop_todo.yml +45 -0
  6. data/.travis.yml +9 -0
  7. data/CHANGELOG.md +16 -0
  8. data/CONTRIBUTING.md +125 -0
  9. data/DEBUGGING.md +25 -0
  10. data/Gemfile +3 -0
  11. data/Guardfile +8 -0
  12. data/LICENSE +21 -0
  13. data/README.md +49 -0
  14. data/RELEASING.md +69 -0
  15. data/Rakefile +16 -0
  16. data/app.json +9 -0
  17. data/config/initializers/bson/object_id.rb +12 -0
  18. data/config/initializers/grape/sort_extension.rb +8 -0
  19. data/config/initializers/slack-ruby-bot/client.rb +17 -0
  20. data/config/initializers/slack-ruby-bot/commands/base.rb +21 -0
  21. data/images/new.png +0 -0
  22. data/images/slackbotserver.gif +0 -0
  23. data/images/slackbutton.gif +0 -0
  24. data/lib/slack-ruby-bot-server.rb +17 -0
  25. data/lib/slack-ruby-bot-server/api.rb +8 -0
  26. data/lib/slack-ruby-bot-server/api/endpoints.rb +3 -0
  27. data/lib/slack-ruby-bot-server/api/endpoints/root_endpoint.rb +22 -0
  28. data/lib/slack-ruby-bot-server/api/endpoints/status_endpoint.rb +16 -0
  29. data/lib/slack-ruby-bot-server/api/endpoints/teams_endpoint.rb +70 -0
  30. data/lib/slack-ruby-bot-server/api/helpers.rb +4 -0
  31. data/lib/slack-ruby-bot-server/api/helpers/cursor_helpers.rb +37 -0
  32. data/lib/slack-ruby-bot-server/api/helpers/error_helpers.rb +52 -0
  33. data/lib/slack-ruby-bot-server/api/helpers/pagination_parameters.rb +19 -0
  34. data/lib/slack-ruby-bot-server/api/helpers/sort_helpers.rb +53 -0
  35. data/lib/slack-ruby-bot-server/api/middleware.rb +44 -0
  36. data/lib/slack-ruby-bot-server/api/presenters.rb +9 -0
  37. data/lib/slack-ruby-bot-server/api/presenters/paginated_presenter.rb +38 -0
  38. data/lib/slack-ruby-bot-server/api/presenters/root_presenter.rb +44 -0
  39. data/lib/slack-ruby-bot-server/api/presenters/status_presenter.rb +40 -0
  40. data/lib/slack-ruby-bot-server/api/presenters/team_presenter.rb +24 -0
  41. data/lib/slack-ruby-bot-server/api/presenters/teams_presenter.rb +14 -0
  42. data/lib/slack-ruby-bot-server/app.rb +85 -0
  43. data/lib/slack-ruby-bot-server/info.rb +11 -0
  44. data/lib/slack-ruby-bot-server/models.rb +1 -0
  45. data/lib/slack-ruby-bot-server/models/team.rb +66 -0
  46. data/lib/slack-ruby-bot-server/rspec.rb +5 -0
  47. data/lib/slack-ruby-bot-server/rspec/fabricators/team.rb +5 -0
  48. data/lib/slack-ruby-bot-server/server.rb +21 -0
  49. data/lib/slack-ruby-bot-server/service.rb +81 -0
  50. data/lib/slack-ruby-bot-server/version.rb +3 -0
  51. data/public/favicon.ico +0 -0
  52. data/public/img/slack.png +0 -0
  53. data/public/index.html.erb +28 -0
  54. data/public/robots.txt +2 -0
  55. data/public/scripts/jquery-1.7.1.min.js +4 -0
  56. data/public/scripts/register.js +50 -0
  57. data/public/scripts/stats.js +14 -0
  58. data/public/scripts/url.min.js +1 -0
  59. data/sample_app/.rspec +3 -0
  60. data/sample_app/Gemfile +14 -0
  61. data/sample_app/Procfile +1 -0
  62. data/sample_app/Rakefile +10 -0
  63. data/sample_app/commands.rb +2 -0
  64. data/sample_app/commands/help.rb +19 -0
  65. data/sample_app/commands/whoami.rb +6 -0
  66. data/sample_app/config.ru +20 -0
  67. data/sample_app/config/mongoid.yml +27 -0
  68. data/sample_app/config/newrelic.yml +217 -0
  69. data/sample_app/spec/commands/help_spec.rb +14 -0
  70. data/sample_app/spec/commands/whoami_spec.rb +14 -0
  71. data/sample_app/spec/spec_helper.rb +25 -0
  72. data/script/console +9 -0
  73. data/slack-ruby-bot-server.gemspec +48 -0
  74. data/tasks/db.rake +44 -0
  75. metadata +523 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 52146ba5ac001bb30aab89a2b3d954f9618dabf4
4
+ data.tar.gz: de8a3515657c2c89f04e72752562020da77073c2
5
+ SHA512:
6
+ metadata.gz: 893a31c1826f733d2e8f02ed26d6b48ada8c71919b98778cc3b2c89502be774039014469307fb5e88539e53108f50b641cf00cd7ed910adc171522305486e347
7
+ data.tar.gz: d9df13508a1b9b1e18b1eb55cee4f0338eeda5a13b0a0b5048245681537a368a09329ab1a35c4ca7bf3fb1aae0c3bef7ac8fe52d5724937e08627fc7b000b227
@@ -0,0 +1,10 @@
1
+ .DS_Store
2
+ .rvmrc
3
+ .irbrc
4
+ .bundle
5
+ log
6
+ .env
7
+ *.swp
8
+ Gemfile.lock
9
+ .ruby-version
10
+ pkg
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format=documentation
3
+
@@ -0,0 +1,2 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
@@ -0,0 +1,45 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2016-06-01 15:51:05 -0400 using RuboCop version 0.35.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ Lint/RescueException:
11
+ Exclude:
12
+ - 'lib/slack-ruby-bot-server/app.rb'
13
+
14
+ # Offense count: 7
15
+ Metrics/AbcSize:
16
+ Max: 32
17
+
18
+ # Offense count: 2
19
+ Metrics/CyclomaticComplexity:
20
+ Max: 11
21
+
22
+ # Offense count: 67
23
+ # Configuration parameters: AllowURI, URISchemes.
24
+ Metrics/LineLength:
25
+ Max: 163
26
+
27
+ # Offense count: 5
28
+ # Configuration parameters: CountComments.
29
+ Metrics/MethodLength:
30
+ Max: 23
31
+
32
+ # Offense count: 2
33
+ Metrics/PerceivedComplexity:
34
+ Max: 11
35
+
36
+ # Offense count: 25
37
+ # Configuration parameters: Exclude.
38
+ Style/Documentation:
39
+ Enabled: false
40
+
41
+ # Offense count: 1
42
+ # Configuration parameters: Exclude.
43
+ Style/FileName:
44
+ Exclude:
45
+ - 'lib/slack-ruby-bot-server.rb'
@@ -0,0 +1,9 @@
1
+ rvm:
2
+ - 2.2.4
3
+ language: ruby
4
+ cache: bundler
5
+ services:
6
+ - mongodb
7
+ before_install:
8
+ - "export DISPLAY=:99.0"
9
+ - "sh -e /etc/init.d/xvfb start"
@@ -0,0 +1,16 @@
1
+ ### Changelog
2
+
3
+ #### 0.1.0 (1/6/2016)
4
+
5
+ * Initial public release - [@dblock](https://github.com/dblock).
6
+ * 2016/6/1: Renamed slack-bot-server to slack-ruby-bot-server - [@dblock](https://github.com/dblock).
7
+ * 2016/5/30: [#11](https://github.com/dblock/slack-ruby-bot-server/pull/11) Turn project into gem - [@tmsrjs](https://github.com/tmsrjs).
8
+ * 2016/5/5: Use `celluloid-io` instead of `faye-websocket`, upgrade to slack-ruby-bot 0.8.0 - [@dblock](https://github.com/dblock).
9
+ * 2016/4/18: Fixed `SlackRubyBotServer#reset` - [@dblock](https://github.com/dblock).
10
+ * 2016/4/18: Use Grape 0.15.x - [@dblock](https://github.com/dblock).
11
+ * 2016/4/18: Removed OOB GC - [@dblock](https://github.com/dblock).
12
+ * 2016/2/11: Use Unicorn instead of Puma - [@dblock](https://github.com/dblock).
13
+ * 2016/2/11: Fix: wait for EventMachine reactor to start - [@dblock](https://github.com/dblock).
14
+ * 2016/2/11: Use an OOB GC - [@dblock](https://github.com/dblock).
15
+ * 2016/2/9: Defer start, much faster - [@dblock](https://github.com/dblock).
16
+ * 2016/1/10: Backported changes from slack-metabot and slack-shellbot - [@dblock](https://github.com/dblock).
@@ -0,0 +1,125 @@
1
+ # Contributing to SlackRubyBotServer
2
+
3
+ This project is work of [many contributors](https://github.com/dblock/slack-ruby-bot-server/graphs/contributors).
4
+
5
+ You're encouraged to submit [pull requests](https://github.com/dblock/slack-ruby-bot-server/pulls), [propose features and discuss issues](https://github.com/dblock/slack-ruby-bot-server/issues).
6
+
7
+ In the examples below, substitute your Github username for `contributor` in URLs.
8
+
9
+ ## Fork the Project
10
+
11
+ Fork the [project on Github](https://github.com/dblock/slack-ruby-bot-server) and check out your copy.
12
+
13
+ ```
14
+ git clone https://github.com/contributor/slack-ruby-bot-server.git
15
+ cd slack-ruby-bot-server
16
+ git remote add upstream https://github.com/dblock/slack-ruby-bot-server.git
17
+ ```
18
+
19
+ ## Create a Topic Branch
20
+
21
+ Make sure your fork is up-to-date and create a topic branch for your feature or bug fix.
22
+
23
+ ```
24
+ git checkout master
25
+ git pull upstream master
26
+ git checkout -b my-feature-branch
27
+ ```
28
+
29
+ ## Bundle Install and Test
30
+
31
+ Ensure that you can build the project and run tests.
32
+
33
+ ```
34
+ bundle install
35
+ bundle exec rake
36
+ ```
37
+
38
+ ## Write Tests
39
+
40
+ Try to write a test that reproduces the problem you're trying to fix or describes a feature that you want to build.
41
+ Add to [spec](spec).
42
+
43
+ We definitely appreciate pull requests that highlight or reproduce a problem, even without a fix.
44
+
45
+ ## Write Code
46
+
47
+ Implement your feature or bug fix.
48
+
49
+ Ruby style is enforced with [Rubocop](https://github.com/bbatsov/rubocop).
50
+ Run `bundle exec rubocop` and fix any style issues highlighted.
51
+
52
+ Make sure that `bundle exec rake` completes without errors.
53
+
54
+ ## Write Documentation
55
+
56
+ Document any external behavior in the [README](README.md).
57
+
58
+ ## Update Changelog
59
+
60
+ Add a line to [CHANGELOG](CHANGELOG.md) under *Next Release*.
61
+ Make it look like every other line, including your name and link to your Github account.
62
+
63
+ ## Commit Changes
64
+
65
+ Make sure git knows your name and email address:
66
+
67
+ ```
68
+ git config --global user.name "Your Name"
69
+ git config --global user.email "contributor@example.com"
70
+ ```
71
+
72
+ Writing good commit logs is important. A commit log should describe what changed and why.
73
+
74
+ ```
75
+ git add ...
76
+ git commit
77
+ ```
78
+
79
+ ## Push
80
+
81
+ ```
82
+ git push origin my-feature-branch
83
+ ```
84
+
85
+ ## Make a Pull Request
86
+
87
+ Go to https://github.com/contributor/slack-ruby-bot-server and select your feature branch.
88
+ Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days.
89
+
90
+ ## Rebase
91
+
92
+ If you've been working on a change for a while, rebase with upstream/master.
93
+
94
+ ```
95
+ git fetch upstream
96
+ git rebase upstream/master
97
+ git push origin my-feature-branch -f
98
+ ```
99
+
100
+ ## Update CHANGELOG Again
101
+
102
+ Update the [CHANGELOG](CHANGELOG.md) with the pull request number. A typical entry looks as follows.
103
+
104
+ ```
105
+ * [#123](https://github.com/dblock/slack-ruby-bot-server/pull/123): Reticulated splines - [@contributor](https://github.com/contributor).
106
+ ```
107
+
108
+ Amend your previous commit and force push the changes.
109
+
110
+ ```
111
+ git commit --amend
112
+ git push origin my-feature-branch -f
113
+ ```
114
+
115
+ ## Check on Your Pull Request
116
+
117
+ Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above.
118
+
119
+ ## Be Patient
120
+
121
+ It's likely that your change will not be merged and that the nitpicky maintainers will ask you to do more, or fix seemingly benign problems. Hang on there!
122
+
123
+ ## Thank You
124
+
125
+ Please do know that we really appreciate and value your time and work. We love you, really.
@@ -0,0 +1,25 @@
1
+ ## Debugging
2
+
3
+ ### Locally
4
+
5
+ You can debug your instance of slack-ruby-bot-server with a built-in `script/console`.
6
+
7
+ ### Silence Mongoid Logger
8
+
9
+ If Mongoid logging is annoying you.
10
+
11
+ ```ruby
12
+ Mongoid.logger.level = Logger::INFO
13
+ Mongo::Logger.logger.level = Logger::INFO
14
+ ```
15
+
16
+ ### Heroku
17
+
18
+ ```
19
+ heroku run script/console --app=...
20
+
21
+ Running `script/console` attached to terminal... up, run.7593
22
+
23
+ 2.2.1 > Team.count
24
+ => 3
25
+ ```
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,8 @@
1
+ guard 'bundler' do
2
+ watch('Gemfile')
3
+ end
4
+
5
+ guard 'rack' do
6
+ watch('Gemfile.lock')
7
+ watch(%r{^(config|app|api)/.*})
8
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015-2016 Daniel Doubrovkine
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,49 @@
1
+ Slack Ruby Bot Server
2
+ =====================
3
+
4
+ [![Build Status](https://travis-ci.org/dblock/slack-ruby-bot-server.svg?branch=master)](https://travis-ci.org/dblock/slack-ruby-bot-server)
5
+ [![Code Climate](https://codeclimate.com/github/dblock/slack-ruby-bot-server.svg)](https://codeclimate.com/github/dblock/slack-ruby-bot-server)
6
+
7
+ An opinionated boilerplate and demo for a complete Slack bot service with Slack button integration, in Ruby. If you are not familiar with Slack bots or Slack API concepts, you might want to watch [this video](http://code.dblock.org/2016/03/11/your-first-slack-bot-service-video.html). A good demo of a service built on top of this is [playplay.io](http://playplay.io).
8
+
9
+ ### Try Me
10
+
11
+ A demo version of this app is running on Heroku at [slack-ruby-bot-server.herokuapp.com](https://slack-ruby-bot-server.herokuapp.com). Use the _Add to Slack_ button. The bot will join your team as _@slackbotserver_.
12
+
13
+ ![](images/slackbutton.gif)
14
+
15
+ Once a bot is registered, you can invite to a channel with `/invite @slackbotserver` interact with it. DM "hi" to it, or say "@slackbotserver hi".
16
+
17
+ ![](images/slackbotserver.gif)
18
+
19
+ ### What is this?
20
+
21
+ A [Grape](http://github.com/ruby-grape/grape) API serving a [Slack Ruby Bot](https://github.com/dblock/slack-ruby-bot) to multiple teams. This gem combines a web server, a RESTful API and multiple instances of [slack-ruby-bot](https://github.com/dblock/slack-ruby-bot). It integrates with the [Slack Platform API](https://medium.com/slack-developer-blog/launch-platform-114754258b91#.od3y71dyo).
22
+ Your customers can use a Slack button to install the bot.
23
+
24
+ ### Run Your Own
25
+
26
+ You can use the [sample application](sample_app) to bootstrap your project and start adding slack command handlers on top of this code.
27
+
28
+ Install [MongoDB](https://www.mongodb.org/downloads), required to store teams.
29
+
30
+ [Create a New Application](https://api.slack.com/applications/new) on Slack.
31
+
32
+ ![](images/new.png)
33
+
34
+ Follow the instructions, note the app's client ID and secret, give the bot a default name, etc. The redirect URL should be the location of your app, for testing purposes use `http://localhost:9292`. Edit your `.env` file and add `SLACK_CLIENT_ID=...` and `SLACK_CLIENT_SECRET=...` in it. Run `bundle install` and `foreman start`. Navigate to [localhost:9292](http://localhost:9292). Register using the Slack button.
35
+
36
+ If you deploy to Heroku set `SLACK_CLIENT_ID` and `SLACK_CLIENT_SECRET` via `heroku config:add SLACK_CLIENT_ID=... SLACK_CLIENT_SECRET=...`.
37
+
38
+ ### Examples Using Slack Ruby Bot Server
39
+
40
+ * [slack-gamebot](https://github.com/dblock/slack-gamebot), free service at [playplay.io](http://playplay.io)
41
+ * [slack-shellbot](https://github.com/dblock/slack-shellbot), free service at [shell.playplay.io](http://shell.playplay.io)
42
+ * [api-explorer](https://github.com/dblock/slack-api-explorer), free service at [api-explorer.playplay.io](http://api-explorer.playplay.io)
43
+ * [slack-market](https://github.com/dblock/slack-market), free service at [market.playplay.io](http://market.playplay.io)
44
+
45
+ ### Copyright & License
46
+
47
+ Copyright [Daniel Doubrovkine](http://code.dblock.org), 2015-2016
48
+
49
+ [MIT License](LICENSE)
@@ -0,0 +1,69 @@
1
+ # Releasing Slack-Ruby-Bot-Server
2
+
3
+ There're no hard rules about when to release slack-ruby-bot-server. Release bug fixes frequenty, features not so frequently and breaking API changes rarely.
4
+
5
+ ### Release
6
+
7
+ Run tests, check that all tests succeed locally.
8
+
9
+ ```
10
+ bundle install
11
+ rake
12
+ ```
13
+
14
+ Check that the last build succeeded in [Travis CI](https://travis-ci.org/dblock/slack-ruby-bot-server) for all supported platforms.
15
+
16
+ Increment the version, modify [lib/slack-ruby-bot-server/version.rb](lib/slack-ruby-bot-server/version.rb).
17
+
18
+ * Increment the third number if the release has bug fixes and/or very minor features, only (eg. change `0.2.1` to `0.2.2`).
19
+ * Increment the second number if the release contains major features or breaking API changes (eg. change `0.2.1` to `0.3.0`).
20
+
21
+ Change "Next Release" in [CHANGELOG.md](CHANGELOG.md) to the new version.
22
+
23
+ ```
24
+ ### 0.2.2 (7/10/2015)
25
+ ```
26
+
27
+ Remove the line with "Your contribution here.", since there will be no more contributions to this release.
28
+
29
+ Remove the "Stable Release" section in README that warns users that they are reading the documentation for an unreleased version.
30
+
31
+ Commit your changes.
32
+
33
+ ```
34
+ git add README.md CHANGELOG.md lib/slack-ruby-bot-server/version.rb
35
+ git commit -m "Preparing for release, 0.2.2."
36
+ git push origin master
37
+ ```
38
+
39
+ Release.
40
+
41
+ ```
42
+ $ rake release
43
+
44
+ slack-ruby-bot-server 0.2.2 built to pkg/slack-ruby-bot-server-0.2.2.gem.
45
+ Tagged v0.2.2.
46
+ Pushed git commits and tags.
47
+ Pushed slack-ruby-bot-server 0.2.2 to rubygems.org.
48
+ ```
49
+
50
+ ### Prepare for the Next Version
51
+
52
+ Add the next release to [CHANGELOG.md](CHANGELOG.md).
53
+
54
+ ```
55
+ Next Release
56
+ ============
57
+
58
+ * Your contribution here.
59
+ ```
60
+
61
+ Increment the third version number in [lib/slack-ruby-bot-server/version.rb](lib/slack-ruby-bot-server/version.rb).
62
+
63
+ Comit your changes.
64
+
65
+ ```
66
+ git add CHANGELOG.md lib/slack-ruby-bot-server/version.rb
67
+ git commit -m "Preparing for next development iteration, 0.2.3."
68
+ git push origin master
69
+ ```
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'bundler/gem_tasks'
3
+
4
+ require 'rspec/core'
5
+ require 'rspec/core/rake_task'
6
+
7
+ RSpec::Core::RakeTask.new(:spec) do |spec|
8
+ spec.pattern = FileList['spec/**/*_spec.rb']
9
+ end
10
+
11
+ require 'rubocop/rake_task'
12
+ RuboCop::RakeTask.new
13
+
14
+ task default: [:rubocop, :spec]
15
+
16
+ import 'tasks/db.rake'
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "Slack Bot Server",
3
+ "description": "A Slack bot server.",
4
+ "respository": "https://github.com/dblock/slack-ruby-bot-server",
5
+ "keywords": ["slack", "bots"],
6
+ "addons": [
7
+ "mongolab"
8
+ ]
9
+ }
@@ -0,0 +1,12 @@
1
+ # see https://groups.google.com/forum/#!msg/mongoid/MaXFVw7D_4s/T3sl6Flg428J
2
+ module BSON
3
+ class ObjectId
4
+ def as_json(_options = {})
5
+ to_s
6
+ end
7
+
8
+ def to_bson_key(encoded = ''.force_encoding(BINARY))
9
+ to_s.to_bson_key(encoded)
10
+ end
11
+ end
12
+ end