From e8a7c89a3395f85dece680014ff281eaa852494a Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Tue, 21 Mar 2017 12:54:57 +0300 Subject: [PATCH 001/110] Add 12factor for heroku --- .ruby-gemset | 1 + .ruby-version | 1 + Gemfile | 8 +++++++- 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .ruby-gemset create mode 100644 .ruby-version diff --git a/.ruby-gemset b/.ruby-gemset new file mode 100644 index 0000000..69d2a6a --- /dev/null +++ b/.ruby-gemset @@ -0,0 +1 @@ +basecamp3-rails-chatbot diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..c1026d2 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +ruby-2.3.1 diff --git a/Gemfile b/Gemfile index 1d715cb..c6622a6 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,6 @@ source 'https://rubygems.org' ruby '2.3.1' gem 'rails', '~> 5.0.0', '>= 5.0.0.1' -gem 'sqlite3' # Use Puma as the app server gem 'puma', '~> 3.0' @@ -15,6 +14,7 @@ gem 'coffee-rails', '~> 4.2' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platform: :mri + gem 'sqlite3' end group :development do @@ -25,3 +25,9 @@ group :development do gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' end + +group :production do + # Call 'byebug' anywhere in the code to stop execution and get a debugger console + gem 'pg' + gem 'rails_12factor' +end \ No newline at end of file From 88e0620b26f4cc66131b443d562b1e64d4bee460 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Tue, 21 Mar 2017 13:01:05 +0300 Subject: [PATCH 002/110] Add 12factor and pg for heroku --- Gemfile.lock | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index e0bb13f..89f7f9c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -75,6 +75,7 @@ GEM nio4r (1.2.1) nokogiri (1.6.8.1) mini_portile2 (~> 2.1.0) + pg (0.20.0) puma (3.6.1) rack (2.0.1) rack-test (0.6.3) @@ -96,6 +97,11 @@ GEM nokogiri (~> 1.6.0) rails-html-sanitizer (1.0.3) loofah (~> 2.0) + rails_12factor (0.0.3) + rails_serve_static_assets + rails_stdout_logging + rails_serve_static_assets (0.0.5) + rails_stdout_logging (0.0.5) railties (5.0.0.1) actionpack (= 5.0.0.1) activesupport (= 5.0.0.1) @@ -150,8 +156,10 @@ DEPENDENCIES coffee-rails (~> 4.2) httparty listen (~> 3.0.5) + pg puma (~> 3.0) rails (~> 5.0.0, >= 5.0.0.1) + rails_12factor sass-rails (~> 5.0) spring spring-watcher-listen (~> 2.0.0) @@ -163,4 +171,4 @@ RUBY VERSION ruby 2.3.1p112 BUNDLED WITH - 1.12.5 + 1.14.6 From b725dc680b47ec2b92c323fa1daf023bcdb62331 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Tue, 21 Mar 2017 13:06:47 +0300 Subject: [PATCH 003/110] Add some gems for heroku --- Gemfile | 4 ++++ Gemfile.lock | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/Gemfile b/Gemfile index c6622a6..814a600 100644 --- a/Gemfile +++ b/Gemfile @@ -11,6 +11,10 @@ gem 'sass-rails', '~> 5.0' gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.2' +gem 'jquery-rails' +gem 'turbolinks', '~> 5' +gem 'jbuilder', '~> 2.5' + group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platform: :mri diff --git a/Gemfile.lock b/Gemfile.lock index 89f7f9c..ba5b943 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -58,6 +58,13 @@ GEM httparty (0.14.0) multi_xml (>= 0.5.2) i18n (0.7.0) + jbuilder (2.6.3) + activesupport (>= 3.0.0, < 5.2) + multi_json (~> 1.2) + jquery-rails (4.2.2) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) listen (3.0.8) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -71,6 +78,7 @@ GEM mime-types-data (3.2016.0521) mini_portile2 (2.1.0) minitest (5.9.1) + multi_json (1.12.1) multi_xml (0.5.5) nio4r (1.2.1) nokogiri (1.6.8.1) @@ -135,6 +143,9 @@ GEM thor (0.19.1) thread_safe (0.3.5) tilt (2.0.5) + turbolinks (5.0.1) + turbolinks-source (~> 5) + turbolinks-source (5.0.0) tzinfo (1.2.2) thread_safe (~> 0.1) uglifier (3.0.3) @@ -155,6 +166,8 @@ DEPENDENCIES byebug coffee-rails (~> 4.2) httparty + jbuilder (~> 2.5) + jquery-rails listen (~> 3.0.5) pg puma (~> 3.0) @@ -164,6 +177,7 @@ DEPENDENCIES spring spring-watcher-listen (~> 2.0.0) sqlite3 + turbolinks (~> 5) uglifier (>= 1.3.0) web-console From 93ed327b0d174ef0e6257c537b2f0a0a5b9316f7 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Tue, 21 Mar 2017 22:47:51 +0300 Subject: [PATCH 004/110] Edit readme.md file --- Gemfile | 11 +-- Gemfile.lock | 134 ++++++++++++----------------- README.md | 29 +++++-- config/environments/development.rb | 3 + config/service.yml | 4 +- 5 files changed, 84 insertions(+), 97 deletions(-) diff --git a/Gemfile b/Gemfile index 814a600..8884e59 100644 --- a/Gemfile +++ b/Gemfile @@ -3,6 +3,7 @@ source 'https://rubygems.org' ruby '2.3.1' gem 'rails', '~> 5.0.0', '>= 5.0.0.1' +gem 'sqlite3' # Use Puma as the app server gem 'puma', '~> 3.0' @@ -11,14 +12,10 @@ gem 'sass-rails', '~> 5.0' gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.2' -gem 'jquery-rails' -gem 'turbolinks', '~> 5' -gem 'jbuilder', '~> 2.5' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platform: :mri - gem 'sqlite3' end group :development do @@ -29,9 +26,3 @@ group :development do gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' end - -group :production do - # Call 'byebug' anywhere in the code to stop execution and get a debugger console - gem 'pg' - gem 'rails_12factor' -end \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index ba5b943..749f1a3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,45 +1,45 @@ GEM remote: https://rubygems.org/ specs: - actioncable (5.0.0.1) - actionpack (= 5.0.0.1) - nio4r (~> 1.2) + actioncable (5.0.2) + actionpack (= 5.0.2) + nio4r (>= 1.2, < 3.0) websocket-driver (~> 0.6.1) - actionmailer (5.0.0.1) - actionpack (= 5.0.0.1) - actionview (= 5.0.0.1) - activejob (= 5.0.0.1) + actionmailer (5.0.2) + actionpack (= 5.0.2) + actionview (= 5.0.2) + activejob (= 5.0.2) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.0.0.1) - actionview (= 5.0.0.1) - activesupport (= 5.0.0.1) + actionpack (5.0.2) + actionview (= 5.0.2) + activesupport (= 5.0.2) rack (~> 2.0) rack-test (~> 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.0.0.1) - activesupport (= 5.0.0.1) + actionview (5.0.2) + activesupport (= 5.0.2) builder (~> 3.1) erubis (~> 2.7.0) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - activejob (5.0.0.1) - activesupport (= 5.0.0.1) + rails-html-sanitizer (~> 1.0, >= 1.0.3) + activejob (5.0.2) + activesupport (= 5.0.2) globalid (>= 0.3.6) - activemodel (5.0.0.1) - activesupport (= 5.0.0.1) - activerecord (5.0.0.1) - activemodel (= 5.0.0.1) - activesupport (= 5.0.0.1) + activemodel (5.0.2) + activesupport (= 5.0.2) + activerecord (5.0.2) + activemodel (= 5.0.2) + activesupport (= 5.0.2) arel (~> 7.0) - activesupport (5.0.0.1) + activesupport (5.0.2) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (~> 0.7) minitest (~> 5.1) tzinfo (~> 1.1) arel (7.1.4) - builder (3.2.2) + builder (3.2.3) byebug (9.0.6) coffee-rails (4.2.1) coffee-script (>= 2.2.0) @@ -47,24 +47,17 @@ GEM coffee-script (2.4.1) coffee-script-source execjs - coffee-script-source (1.10.0) - concurrent-ruby (1.0.2) + coffee-script-source (1.12.2) + concurrent-ruby (1.0.5) debug_inspector (0.0.2) erubis (2.7.0) execjs (2.7.0) - ffi (1.9.14) + ffi (1.9.18) globalid (0.3.7) activesupport (>= 4.1.0) httparty (0.14.0) multi_xml (>= 0.5.2) - i18n (0.7.0) - jbuilder (2.6.3) - activesupport (>= 3.0.0, < 5.2) - multi_json (~> 1.2) - jquery-rails (4.2.2) - rails-dom-testing (>= 1, < 3) - railties (>= 4.2.0) - thor (>= 0.14, < 2.0) + i18n (0.8.1) listen (3.0.8) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -77,62 +70,55 @@ GEM mime-types-data (~> 3.2015) mime-types-data (3.2016.0521) mini_portile2 (2.1.0) - minitest (5.9.1) - multi_json (1.12.1) - multi_xml (0.5.5) - nio4r (1.2.1) - nokogiri (1.6.8.1) + minitest (5.10.1) + multi_xml (0.6.0) + nio4r (2.0.0) + nokogiri (1.7.1) mini_portile2 (~> 2.1.0) - pg (0.20.0) - puma (3.6.1) + puma (3.8.2) rack (2.0.1) rack-test (0.6.3) rack (>= 1.0) - rails (5.0.0.1) - actioncable (= 5.0.0.1) - actionmailer (= 5.0.0.1) - actionpack (= 5.0.0.1) - actionview (= 5.0.0.1) - activejob (= 5.0.0.1) - activemodel (= 5.0.0.1) - activerecord (= 5.0.0.1) - activesupport (= 5.0.0.1) + rails (5.0.2) + actioncable (= 5.0.2) + actionmailer (= 5.0.2) + actionpack (= 5.0.2) + actionview (= 5.0.2) + activejob (= 5.0.2) + activemodel (= 5.0.2) + activerecord (= 5.0.2) + activesupport (= 5.0.2) bundler (>= 1.3.0, < 2.0) - railties (= 5.0.0.1) + railties (= 5.0.2) sprockets-rails (>= 2.0.0) - rails-dom-testing (2.0.1) + rails-dom-testing (2.0.2) activesupport (>= 4.2.0, < 6.0) - nokogiri (~> 1.6.0) + nokogiri (~> 1.6) rails-html-sanitizer (1.0.3) loofah (~> 2.0) - rails_12factor (0.0.3) - rails_serve_static_assets - rails_stdout_logging - rails_serve_static_assets (0.0.5) - rails_stdout_logging (0.0.5) - railties (5.0.0.1) - actionpack (= 5.0.0.1) - activesupport (= 5.0.0.1) + railties (5.0.2) + actionpack (= 5.0.2) + activesupport (= 5.0.2) method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (11.3.0) + rake (12.0.0) rb-fsevent (0.9.8) - rb-inotify (0.9.7) + rb-inotify (0.9.8) ffi (>= 0.5.0) - sass (3.4.22) + sass (3.4.23) sass-rails (5.0.6) railties (>= 4.0.0, < 6) sass (~> 3.1) sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) - spring (2.0.0) + spring (2.0.1) activesupport (>= 4.2) spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) spring (>= 1.2, < 3.0) - sprockets (3.7.0) + sprockets (3.7.1) concurrent-ruby (~> 1.0) rack (> 1, < 3) sprockets-rails (3.2.0) @@ -140,22 +126,19 @@ GEM activesupport (>= 4.0) sprockets (>= 3.0.0) sqlite3 (1.3.12) - thor (0.19.1) - thread_safe (0.3.5) - tilt (2.0.5) - turbolinks (5.0.1) - turbolinks-source (~> 5) - turbolinks-source (5.0.0) + thor (0.19.4) + thread_safe (0.3.6) + tilt (2.0.7) tzinfo (1.2.2) thread_safe (~> 0.1) - uglifier (3.0.3) + uglifier (3.1.9) execjs (>= 0.3.0, < 3) web-console (3.4.0) actionview (>= 5.0) activemodel (>= 5.0) debug_inspector railties (>= 5.0) - websocket-driver (0.6.4) + websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.2) @@ -166,18 +149,13 @@ DEPENDENCIES byebug coffee-rails (~> 4.2) httparty - jbuilder (~> 2.5) - jquery-rails listen (~> 3.0.5) - pg puma (~> 3.0) rails (~> 5.0.0, >= 5.0.0.1) - rails_12factor sass-rails (~> 5.0) spring spring-watcher-listen (~> 2.0.0) sqlite3 - turbolinks (~> 5) uglifier (>= 1.3.0) web-console diff --git a/README.md b/README.md index 6054d6c..42f6a90 100644 --- a/README.md +++ b/README.md @@ -7,15 +7,30 @@ Rails application to transfer messages to your basecamp3 HQ. ## Usage -1. Register AWS and [create SNS topic](http://docs.aws.amazon.com/sns/latest/dg/CreateTopic.html). Remember Topic ARN! +1. Register AWS and [create SNS topic](http://docs.aws.amazon.com/sns/latest/dg/CreateTopic.html). Remember Topic ARN! It looks like this: +`arn:aws:sns:us-east-6:23730808936387:topick_name` 2. Register Basecamp and [create bot](https://m.signalvnoise.com/new-in-basecamp-3-chatbots-8526618c0c7d#.kabo3hgs1). There -you need a bot long link. Like this: `https://3.basecamp.com/195539477/integrations/2uH9aHLEVhhaXKPaqrj8yw8P/buckets/2085958501/chats/9007199254741775/lines` -3. Clone this repo && bundle install && rails db:migrate +you need a bot long link. Like this: +`https://3.basecamp.com/195539477/integrations/2uH9aHLEVhhaXKPaqrj8yw8P/buckets/2085958501/chats/9007199254741775/lines` +3. Clone this repo from GitHub. + 3.1 Run __`bundle install`__ in your project directory. + 3.2 Create a ```secrets.yml``` file in your config folder as described [here](http://guides.rubyonrails.org/upgrading_ruby_on_rails.html#config-secrets-yml). 4. Write your SNS **Topic ARN** and Basecamp **bot url** to /config/service.yml -5. rails s -6. [Create subscription](http://docs.aws.amazon.com/sns/latest/dg/SubscribeTopic.html). Use HTTP **Protocol** and -`http://your-external-host/api/v1/messages` as **Endpoint** -7. At first time SNS send confirmation request. After subscription you can +5. Start rails server by typing `rails s` command. +6. [Create subscription](http://docs.aws.amazon.com/sns/latest/dg/SubscribeTopic.html). Use HTTP **Protocol** and `http://your-external-host/api/v1/messages` as **Endpoint** +7. You’ll probably want to try running your app locally to test it and make sure it’s working as expected. To do that you will need a service that allows you to expose a web server running on your local machine to the Internet. We recommend to try [Ngrok](http://ngrok.com). + 7.1 If you see this message on rails console: + ``Cannot render console from XXX.XXX.XXX.XXX! Allowed networks: 127.0.0.1,...`` + You need to whitelist the XXX.XXX.XXX.XXX network space in the Web console config. + Open ``config/environments/development.rb`` and type your local IP address from the Internet Service Provider: + + ``` config.web_console.whitelisted_ips = 'XXX.XXX.XXX.XXX' ``` + + Read more about IP's whitelisting [here](https://github.com/rails/web-console#configweb_consolewhitelisted_ips). + + + +8. At first time SNS send confirmation request. After subscription you can [publish messages to a topic](http://docs.aws.amazon.com/sns/latest/dg/PublishTopic.html) ## References diff --git a/config/environments/development.rb b/config/environments/development.rb index a8d210f..ea0d5c6 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -43,4 +43,7 @@ # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. config.file_watcher = ActiveSupport::EventedFileUpdateChecker + + config.web_console.whitelisted_ips = '54.240.230.0/16' + end diff --git a/config/service.yml b/config/service.yml index ae11439..b63db25 100644 --- a/config/service.yml +++ b/config/service.yml @@ -1,6 +1,6 @@ default: &default - basecampbot_url: https://3.basecamp.com/3601306/integrations/6Mc7Rhug2NkpDY53Qu2x7TGn/buckets/1925463/chats/294329172/lines - snstopic_arn: arn:aws:sns:eu-central-1:798348585423:basecamp-bot + basecampbot_url: https://3.basecamp.com/3700178/integrations/3gtJyBKVQHvrQN2h7FitRJSK/buckets/3097353/chats/437772399/lines + snstopic_arn: arn:aws:sns:us-west-2:230306836787:magick_kick development: <<: *default From 0ee1f47f91a7535e3ed7b49a6f7ad1f42a94c6f9 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Tue, 21 Mar 2017 23:52:54 +0400 Subject: [PATCH 005/110] Delete .ruby-gemset --- .ruby-gemset | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .ruby-gemset diff --git a/.ruby-gemset b/.ruby-gemset deleted file mode 100644 index 69d2a6a..0000000 --- a/.ruby-gemset +++ /dev/null @@ -1 +0,0 @@ -basecamp3-rails-chatbot From 0df2d57675bf69702290fbcc7615a02772d9aa5f Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Tue, 21 Mar 2017 23:53:10 +0400 Subject: [PATCH 006/110] Delete .ruby-version --- .ruby-version | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .ruby-version diff --git a/.ruby-version b/.ruby-version deleted file mode 100644 index c1026d2..0000000 --- a/.ruby-version +++ /dev/null @@ -1 +0,0 @@ -ruby-2.3.1 From 598a081ecba574be16151c39a5f158c2cefbdcea Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Tue, 21 Mar 2017 23:08:34 +0300 Subject: [PATCH 007/110] Edit readme.md file --- README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 42f6a90..c6202eb 100644 --- a/README.md +++ b/README.md @@ -13,13 +13,13 @@ Rails application to transfer messages to your basecamp3 HQ. you need a bot long link. Like this: `https://3.basecamp.com/195539477/integrations/2uH9aHLEVhhaXKPaqrj8yw8P/buckets/2085958501/chats/9007199254741775/lines` 3. Clone this repo from GitHub. - 3.1 Run __`bundle install`__ in your project directory. - 3.2 Create a ```secrets.yml``` file in your config folder as described [here](http://guides.rubyonrails.org/upgrading_ruby_on_rails.html#config-secrets-yml). +3.1 Run __`bundle install`__ in your project directory. +3.2 Create a ```secrets.yml``` file in your config folder as described [here](http://guides.rubyonrails.org/upgrading_ruby_on_rails.html#config-secrets-yml). 4. Write your SNS **Topic ARN** and Basecamp **bot url** to /config/service.yml 5. Start rails server by typing `rails s` command. 6. [Create subscription](http://docs.aws.amazon.com/sns/latest/dg/SubscribeTopic.html). Use HTTP **Protocol** and `http://your-external-host/api/v1/messages` as **Endpoint** 7. You’ll probably want to try running your app locally to test it and make sure it’s working as expected. To do that you will need a service that allows you to expose a web server running on your local machine to the Internet. We recommend to try [Ngrok](http://ngrok.com). - 7.1 If you see this message on rails console: +7.1 If you see this message on rails console: ``Cannot render console from XXX.XXX.XXX.XXX! Allowed networks: 127.0.0.1,...`` You need to whitelist the XXX.XXX.XXX.XXX network space in the Web console config. Open ``config/environments/development.rb`` and type your local IP address from the Internet Service Provider: @@ -28,8 +28,6 @@ you need a bot long link. Like this: Read more about IP's whitelisting [here](https://github.com/rails/web-console#configweb_consolewhitelisted_ips). - - 8. At first time SNS send confirmation request. After subscription you can [publish messages to a topic](http://docs.aws.amazon.com/sns/latest/dg/PublishTopic.html) From 686fa997cb0b14e4d32ad130ceebb62f33474bdf Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Tue, 21 Mar 2017 23:11:52 +0300 Subject: [PATCH 008/110] Edit readme.md file --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 1f771fe..07b276e 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,7 @@ # Ignore Byebug command history file. .byebug_history + +# Ignore RVM files. +/.ruby-gemset +/.ruby-version \ No newline at end of file From eca5d4bb775179a3ad6d51af9160824c4de2df83 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Tue, 21 Mar 2017 23:14:56 +0300 Subject: [PATCH 009/110] Edit readme.md file --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c6202eb..8967913 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ you need a bot long link. Like this: 4. Write your SNS **Topic ARN** and Basecamp **bot url** to /config/service.yml 5. Start rails server by typing `rails s` command. 6. [Create subscription](http://docs.aws.amazon.com/sns/latest/dg/SubscribeTopic.html). Use HTTP **Protocol** and `http://your-external-host/api/v1/messages` as **Endpoint** -7. You’ll probably want to try running your app locally to test it and make sure it’s working as expected. To do that you will need a service that allows you to expose a web server running on your local machine to the Internet. We recommend to try [Ngrok](http://ngrok.com). +7. You will probably want to try running your app locally to test it and make sure it’s working as expected. To do that you will need a service that allows you to expose a web server running on your local machine to the Internet. We recommend to try [Ngrok](http://ngrok.com). 7.1 If you see this message on rails console: ``Cannot render console from XXX.XXX.XXX.XXX! Allowed networks: 127.0.0.1,...`` You need to whitelist the XXX.XXX.XXX.XXX network space in the Web console config. From d4103604d89eb62e8caa1c42a1325c5dc6804fd0 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Tue, 21 Mar 2017 23:19:15 +0300 Subject: [PATCH 010/110] Edit readme.md file --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8967913..61a479b 100644 --- a/README.md +++ b/README.md @@ -13,16 +13,16 @@ Rails application to transfer messages to your basecamp3 HQ. you need a bot long link. Like this: `https://3.basecamp.com/195539477/integrations/2uH9aHLEVhhaXKPaqrj8yw8P/buckets/2085958501/chats/9007199254741775/lines` 3. Clone this repo from GitHub. -3.1 Run __`bundle install`__ in your project directory. -3.2 Create a ```secrets.yml``` file in your config folder as described [here](http://guides.rubyonrails.org/upgrading_ruby_on_rails.html#config-secrets-yml). + 3.1. Run __`bundle install`__ in your project directory. + 3.2. Create a ```secrets.yml``` file in your config folder as described [here](http://guides.rubyonrails.org/upgrading_ruby_on_rails.html#config-secrets-yml). 4. Write your SNS **Topic ARN** and Basecamp **bot url** to /config/service.yml 5. Start rails server by typing `rails s` command. 6. [Create subscription](http://docs.aws.amazon.com/sns/latest/dg/SubscribeTopic.html). Use HTTP **Protocol** and `http://your-external-host/api/v1/messages` as **Endpoint** 7. You will probably want to try running your app locally to test it and make sure it’s working as expected. To do that you will need a service that allows you to expose a web server running on your local machine to the Internet. We recommend to try [Ngrok](http://ngrok.com). -7.1 If you see this message on rails console: - ``Cannot render console from XXX.XXX.XXX.XXX! Allowed networks: 127.0.0.1,...`` - You need to whitelist the XXX.XXX.XXX.XXX network space in the Web console config. - Open ``config/environments/development.rb`` and type your local IP address from the Internet Service Provider: + 7.1. If you see this message on rails console: + ``Cannot render console from XXX.XXX.XXX.XXX! Allowed networks: 127.0.0.1,...`` + You need to whitelist the XXX.XXX.XXX.XXX network space in the Web console config. + Open ``config/environments/development.rb`` and type your local IP address from the Internet Service Provider: ``` config.web_console.whitelisted_ips = 'XXX.XXX.XXX.XXX' ``` From 5ddbf6459cbbb7422abaf22fc58765a1be220101 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Tue, 21 Mar 2017 23:21:20 +0300 Subject: [PATCH 011/110] Edit readme.md file --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 61a479b..1aeb2b7 100644 --- a/README.md +++ b/README.md @@ -13,13 +13,13 @@ Rails application to transfer messages to your basecamp3 HQ. you need a bot long link. Like this: `https://3.basecamp.com/195539477/integrations/2uH9aHLEVhhaXKPaqrj8yw8P/buckets/2085958501/chats/9007199254741775/lines` 3. Clone this repo from GitHub. - 3.1. Run __`bundle install`__ in your project directory. - 3.2. Create a ```secrets.yml``` file in your config folder as described [here](http://guides.rubyonrails.org/upgrading_ruby_on_rails.html#config-secrets-yml). + 1. Run __`bundle install`__ in your project directory. + 2. Create a ```secrets.yml``` file in your config folder as described [here](http://guides.rubyonrails.org/upgrading_ruby_on_rails.html#config-secrets-yml). 4. Write your SNS **Topic ARN** and Basecamp **bot url** to /config/service.yml 5. Start rails server by typing `rails s` command. 6. [Create subscription](http://docs.aws.amazon.com/sns/latest/dg/SubscribeTopic.html). Use HTTP **Protocol** and `http://your-external-host/api/v1/messages` as **Endpoint** 7. You will probably want to try running your app locally to test it and make sure it’s working as expected. To do that you will need a service that allows you to expose a web server running on your local machine to the Internet. We recommend to try [Ngrok](http://ngrok.com). - 7.1. If you see this message on rails console: + 1. If you see this message on rails console: ``Cannot render console from XXX.XXX.XXX.XXX! Allowed networks: 127.0.0.1,...`` You need to whitelist the XXX.XXX.XXX.XXX network space in the Web console config. Open ``config/environments/development.rb`` and type your local IP address from the Internet Service Provider: From ac90a22e0f69f641bb48b1903f8c1328669b0f0b Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Tue, 21 Mar 2017 23:25:51 +0300 Subject: [PATCH 012/110] Edit readme.md file --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1aeb2b7..9a666bf 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,10 @@ Rails application to transfer messages to your basecamp3 HQ. ## Usage 1. Register AWS and [create SNS topic](http://docs.aws.amazon.com/sns/latest/dg/CreateTopic.html). Remember Topic ARN! It looks like this: -`arn:aws:sns:us-east-6:23730808936387:topick_name` + `arn:aws:sns:us-east-6:23730808936387:topick_name` 2. Register Basecamp and [create bot](https://m.signalvnoise.com/new-in-basecamp-3-chatbots-8526618c0c7d#.kabo3hgs1). There you need a bot long link. Like this: -`https://3.basecamp.com/195539477/integrations/2uH9aHLEVhhaXKPaqrj8yw8P/buckets/2085958501/chats/9007199254741775/lines` + `https://3.basecamp.com/195539477/integrations/2uH9aHLEVhhaXKPaqrj8yw8P/buckets/2085958501/chats/9007199254741775/lines` 3. Clone this repo from GitHub. 1. Run __`bundle install`__ in your project directory. 2. Create a ```secrets.yml``` file in your config folder as described [here](http://guides.rubyonrails.org/upgrading_ruby_on_rails.html#config-secrets-yml). @@ -20,11 +20,11 @@ you need a bot long link. Like this: 6. [Create subscription](http://docs.aws.amazon.com/sns/latest/dg/SubscribeTopic.html). Use HTTP **Protocol** and `http://your-external-host/api/v1/messages` as **Endpoint** 7. You will probably want to try running your app locally to test it and make sure it’s working as expected. To do that you will need a service that allows you to expose a web server running on your local machine to the Internet. We recommend to try [Ngrok](http://ngrok.com). 1. If you see this message on rails console: - ``Cannot render console from XXX.XXX.XXX.XXX! Allowed networks: 127.0.0.1,...`` - You need to whitelist the XXX.XXX.XXX.XXX network space in the Web console config. - Open ``config/environments/development.rb`` and type your local IP address from the Internet Service Provider: + ``Cannot render console from XXX.XXX.XXX.XXX! Allowed networks: 127.0.0.1,...`` + You need to whitelist the XXX.XXX.XXX.XXX network space in the Web console config. + Open ``config/environments/development.rb`` and type your local IP address from the Internet Service Provider: - ``` config.web_console.whitelisted_ips = 'XXX.XXX.XXX.XXX' ``` + ``` config.web_console.whitelisted_ips = 'XXX.XXX.XXX.XXX' ``` Read more about IP's whitelisting [here](https://github.com/rails/web-console#configweb_consolewhitelisted_ips). From 9c5a0a1c3228506e1ff83d8bb2547753127c71ea Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Wed, 22 Mar 2017 13:17:38 +0300 Subject: [PATCH 013/110] Fixed development.rb - Removed extra empty string, - Added comment to Web Console config string. --- config/environments/development.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/config/environments/development.rb b/config/environments/development.rb index ea0d5c6..87a4163 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -44,6 +44,7 @@ # routes, locales, etc. This feature depends on the listen gem. config.file_watcher = ActiveSupport::EventedFileUpdateChecker + # Add your IP's to whitelist config.web_console.whitelisted_ips = '54.240.230.0/16' end From c26d3d631c98d16473359d85b50ebab9b397abc4 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Wed, 22 Mar 2017 15:03:38 +0300 Subject: [PATCH 014/110] Fix development.rb --- Gemfile | 3 ++- config/environments/development.rb | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 8884e59..e7f8627 100644 --- a/Gemfile +++ b/Gemfile @@ -11,7 +11,8 @@ gem 'httparty' gem 'sass-rails', '~> 5.0' gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.2' - +# Integrate Rollbar.com Dashboard. +gem 'rollbar' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console diff --git a/config/environments/development.rb b/config/environments/development.rb index ea0d5c6..68f8940 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -45,5 +45,4 @@ config.file_watcher = ActiveSupport::EventedFileUpdateChecker config.web_console.whitelisted_ips = '54.240.230.0/16' - -end +end \ No newline at end of file From 7633e61bf32af019f75d0c5ff5261383fbb681c1 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Thu, 23 Mar 2017 05:28:46 +0300 Subject: [PATCH 015/110] Add Rollbar controller --- Gemfile | 2 -- .../api/rollbar/messages_controller.rb | 30 +++++++++++++++++++ app/helpers/application_helper.rb | 15 +++++++++- config/environments/development.rb | 4 +-- config/routes.rb | 4 +++ 5 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 app/controllers/api/rollbar/messages_controller.rb diff --git a/Gemfile b/Gemfile index e7f8627..1d715cb 100644 --- a/Gemfile +++ b/Gemfile @@ -11,8 +11,6 @@ gem 'httparty' gem 'sass-rails', '~> 5.0' gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.2' -# Integrate Rollbar.com Dashboard. -gem 'rollbar' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb new file mode 100644 index 0000000..9047f7f --- /dev/null +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -0,0 +1,30 @@ +class Api::Rollbar::MessagesController < ApplicationController + skip_before_action :verify_authenticity_token + before_action :check_format, only: [:create] + + def create + # Get the parsed JSON string + payload = helpers.parse_webhook + + event = payload['event_name'] + data = payload['data'] + + # Prepare message for the campfire + message = "Subject: #{event}
Body: #{data}" + + # send message to basecamp + helpers.send_message(message) + + + # Prepare message for the campfire + # message = "Subject: #{request_body['Subject']}
#{request_body['Message']}" + # send message to basecamp + end + + private + + def check_format + return head :bad_request unless request.format.json? + end + +end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..1edd67f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,15 @@ module ApplicationHelper -end + require 'json' + require 'httparty' + + # Parse JSON request from remote calback server + def parse_webhook + JSON.parse request.body.read + end + + # Send message to Basecamp Campfire via ChatBot + def send_message(message) + basecampbot_url = Rails.configuration.service['basecampbot_url'] + HTTParty.post basecampbot_url, query: { content: message } + end +end \ No newline at end of file diff --git a/config/environments/development.rb b/config/environments/development.rb index 21170e7..7c16d8a 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -44,6 +44,6 @@ # routes, locales, etc. This feature depends on the listen gem. config.file_watcher = ActiveSupport::EventedFileUpdateChecker - # Add your IP's to whitelist - config.web_console.whitelisted_ips = '54.240.230.0/16' + # Add requesting server IP's to whitelist + config.web_console.whitelisted_ips = '184.173.71.217' end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 49427a4..b8d9d95 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,5 +5,9 @@ namespace :v1 do resources :messages, only: :create end + + namespace :rollbar do + resources :messages, only: :create + end end end From 5a3d70cdf72580f8dba6bc53074a82272c8948fc Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Thu, 23 Mar 2017 10:45:01 +0300 Subject: [PATCH 016/110] Add formar of request checking in the Rollbar controller --- app/controllers/api/rollbar/messages_controller.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index 9047f7f..11f0265 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -1,6 +1,6 @@ class Api::Rollbar::MessagesController < ApplicationController skip_before_action :verify_authenticity_token - before_action :check_format, only: [:create] + before_action :check_request_format, only: [:create] def create # Get the parsed JSON string @@ -15,15 +15,12 @@ def create # send message to basecamp helpers.send_message(message) - - # Prepare message for the campfire - # message = "Subject: #{request_body['Subject']}
#{request_body['Message']}" - # send message to basecamp + end private - def check_format + def check_request_format return head :bad_request unless request.format.json? end From 26accfa1bbba4234f3be4ff7ef1928b84fbc9dee Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 24 Mar 2017 00:58:11 +0300 Subject: [PATCH 017/110] Add handling of request and sending messages about failing request to chatbot --- README.md | 2 +- .../api/rollbar/messages_controller.rb | 23 +++++++++---------- app/helpers/application_helper.rb | 8 ++++++- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 9a666bf..a44aded 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ you need a bot long link. Like this: 1. If you see this message on rails console: ``Cannot render console from XXX.XXX.XXX.XXX! Allowed networks: 127.0.0.1,...`` You need to whitelist the XXX.XXX.XXX.XXX network space in the Web console config. - Open ``config/environments/development.rb`` and type your local IP address from the Internet Service Provider: + Open ``config/environments/development.rb`` and type IP address of the remote server: ``` config.web_console.whitelisted_ips = 'XXX.XXX.XXX.XXX' ``` diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index 11f0265..a8abf4c 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -1,27 +1,26 @@ class Api::Rollbar::MessagesController < ApplicationController skip_before_action :verify_authenticity_token - before_action :check_request_format, only: [:create] def create - # Get the parsed JSON string + + # Get the parsed JSON string payload = helpers.parse_webhook + # Get the failed JSON request message + request_error = payload[:error] + + # Store parsed dada from Rollerbar event = payload['event_name'] data = payload['data'] # Prepare message for the campfire - message = "Subject: #{event}
Body: #{data}" + if request_error + message = "Failed request: #{request_error}" + else + message = "Subject: #{event}
Body: #{data}" + end # send message to basecamp helpers.send_message(message) - - end - - private - - def check_request_format - return head :bad_request unless request.format.json? - end - end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1edd67f..bdb1bea 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -4,7 +4,13 @@ module ApplicationHelper # Parse JSON request from remote calback server def parse_webhook - JSON.parse request.body.read + + # Handle exceptions in case of failed request + begin + JSON.parse request.body.read + rescue JSON::ParserError => error + return { error: error.to_s } + end end # Send message to Basecamp Campfire via ChatBot From 6d98721d1bb5f2b7219bfe514b4e243e189ac72a Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 24 Mar 2017 10:13:11 +0300 Subject: [PATCH 018/110] Edit readm file --- README.md | 2 +- config/environments/development.rb | 3 --- config/service.yml | 4 ++-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a44aded..7577e88 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ you need a bot long link. Like this: 1. If you see this message on rails console: ``Cannot render console from XXX.XXX.XXX.XXX! Allowed networks: 127.0.0.1,...`` You need to whitelist the XXX.XXX.XXX.XXX network space in the Web console config. - Open ``config/environments/development.rb`` and type IP address of the remote server: + Open ``config/environments/development.rb`` and type IP address of remote server: ``` config.web_console.whitelisted_ips = 'XXX.XXX.XXX.XXX' ``` diff --git a/config/environments/development.rb b/config/environments/development.rb index 7c16d8a..472be33 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -43,7 +43,4 @@ # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. config.file_watcher = ActiveSupport::EventedFileUpdateChecker - - # Add requesting server IP's to whitelist - config.web_console.whitelisted_ips = '184.173.71.217' end \ No newline at end of file diff --git a/config/service.yml b/config/service.yml index b63db25..ae11439 100644 --- a/config/service.yml +++ b/config/service.yml @@ -1,6 +1,6 @@ default: &default - basecampbot_url: https://3.basecamp.com/3700178/integrations/3gtJyBKVQHvrQN2h7FitRJSK/buckets/3097353/chats/437772399/lines - snstopic_arn: arn:aws:sns:us-west-2:230306836787:magick_kick + basecampbot_url: https://3.basecamp.com/3601306/integrations/6Mc7Rhug2NkpDY53Qu2x7TGn/buckets/1925463/chats/294329172/lines + snstopic_arn: arn:aws:sns:eu-central-1:798348585423:basecamp-bot development: <<: *default From 6d5bd71362d2428cae06271056ce846eaab67469 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 24 Mar 2017 10:58:37 +0300 Subject: [PATCH 019/110] Update development.rb --- config/environments/development.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environments/development.rb b/config/environments/development.rb index 472be33..a8d210f 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -43,4 +43,4 @@ # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. config.file_watcher = ActiveSupport::EventedFileUpdateChecker -end \ No newline at end of file +end From da4dd7e99b0ca95db67683489f36237bffc16ad7 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 24 Mar 2017 11:13:58 +0300 Subject: [PATCH 020/110] Update application_helper.rb --- app/helpers/application_helper.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index bdb1bea..9817252 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -4,13 +4,10 @@ module ApplicationHelper # Parse JSON request from remote calback server def parse_webhook - # Handle exceptions in case of failed request - begin - JSON.parse request.body.read - rescue JSON::ParserError => error - return { error: error.to_s } - end + JSON.parse request.body.read + rescue JSON::ParserError => error + return { error: error.to_s } end # Send message to Basecamp Campfire via ChatBot @@ -18,4 +15,4 @@ def send_message(message) basecampbot_url = Rails.configuration.service['basecampbot_url'] HTTParty.post basecampbot_url, query: { content: message } end -end \ No newline at end of file +end From dfc3430f99ceaebc94507c8d18e5d477612e4dac Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 24 Mar 2017 11:17:20 +0300 Subject: [PATCH 021/110] Update messages_controller.rb --- app/controllers/api/rollbar/messages_controller.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index a8abf4c..21997f2 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -2,12 +2,11 @@ class Api::Rollbar::MessagesController < ApplicationController skip_before_action :verify_authenticity_token def create - # Get the parsed JSON string payload = helpers.parse_webhook # Get the failed JSON request message - request_error = payload[:error] + request_error = payload[ :error ] # Store parsed dada from Rollerbar event = payload['event_name'] @@ -23,4 +22,4 @@ def create # send message to basecamp helpers.send_message(message) end -end \ No newline at end of file +end From 04935320bd324f54e3ad34abc257004dfa87ec45 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 24 Mar 2017 11:43:46 +0300 Subject: [PATCH 022/110] Update messages_controller.rb --- app/controllers/api/rollbar/messages_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index 21997f2..e382d35 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -14,7 +14,7 @@ def create # Prepare message for the campfire if request_error - message = "Failed request: #{request_error}" + message = "Failed request: #{request_error}" else message = "Subject: #{event}
Body: #{data}" end From 55fab3b41951181608cea7d45ecb82782129e1e6 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 24 Mar 2017 11:44:45 +0300 Subject: [PATCH 023/110] Update application_helper.rb --- app/helpers/application_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 9817252..d2bf861 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -4,7 +4,7 @@ module ApplicationHelper # Parse JSON request from remote calback server def parse_webhook - # Handle exceptions in case of failed request + # Handle exceptions in case of failed request JSON.parse request.body.read rescue JSON::ParserError => error return { error: error.to_s } From 77e0c7968680a42868730a1bf8b0b8e46c20b685 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 24 Mar 2017 11:47:26 +0300 Subject: [PATCH 024/110] Update messages_controller.rb --- app/controllers/api/rollbar/messages_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index e382d35..0fe09bd 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -3,7 +3,7 @@ class Api::Rollbar::MessagesController < ApplicationController def create # Get the parsed JSON string - payload = helpers.parse_webhook + payload = helpers.parse_webhoook # Get the failed JSON request message request_error = payload[ :error ] From fbf2d1a20916f838a22ddc5002fa8be898a85515 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 24 Mar 2017 11:48:32 +0300 Subject: [PATCH 025/110] Update messages_controller.rb --- app/controllers/api/rollbar/messages_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index 0fe09bd..e382d35 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -3,7 +3,7 @@ class Api::Rollbar::MessagesController < ApplicationController def create # Get the parsed JSON string - payload = helpers.parse_webhoook + payload = helpers.parse_webhook # Get the failed JSON request message request_error = payload[ :error ] From 941834b951ce8b33de8da969e2531dbc2dd0ae65 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 24 Mar 2017 11:53:16 +0300 Subject: [PATCH 026/110] Update messages_controller.rb --- app/controllers/api/rollbar/messages_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index e382d35..98146ec 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -5,6 +5,7 @@ def create # Get the parsed JSON string payload = helpers.parse_webhook + # error: JSON:ParserError # Get the failed JSON request message request_error = payload[ :error ] From db60a02d42799b30478549776aca08455baa395a Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 24 Mar 2017 11:53:46 +0300 Subject: [PATCH 027/110] Update messages_controller.rb --- app/controllers/api/rollbar/messages_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index 98146ec..eac5655 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -24,3 +24,4 @@ def create helpers.send_message(message) end end + From f0d42da02133c3eb1159d31070cdeab6a64b1b90 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 24 Mar 2017 11:54:41 +0300 Subject: [PATCH 028/110] Update messages_controller.rb --- app/controllers/api/rollbar/messages_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index eac5655..98146ec 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -24,4 +24,3 @@ def create helpers.send_message(message) end end - From e9a10391cdcb54e43aed6a3298306fb70ea5e80b Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 24 Mar 2017 11:57:54 +0300 Subject: [PATCH 029/110] Update messages_controller.rb --- app/controllers/api/rollbar/messages_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index 98146ec..b8ab493 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -7,7 +7,7 @@ def create # error: JSON:ParserError # Get the failed JSON request message - request_error = payload[ :error ] + request_error = payload[:error] # Store parsed dada from Rollerbar event = payload['event_name'] @@ -23,4 +23,5 @@ def create # send message to basecamp helpers.send_message(message) end + end From 3d0ef1c4e3359e92c5031cb05b966069a0c71213 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 24 Mar 2017 12:01:07 +0300 Subject: [PATCH 030/110] Update messages_controller.rb --- app/controllers/api/rollbar/messages_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index b8ab493..7439133 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -23,5 +23,4 @@ def create # send message to basecamp helpers.send_message(message) end - end From f518d768a5ff66ac991f1af24ffa1bec4a675c00 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 24 Mar 2017 12:09:41 +0300 Subject: [PATCH 031/110] Update messages_controller.rb --- app/controllers/api/rollbar/messages_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index 7439133..c93bf8e 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -24,3 +24,4 @@ def create helpers.send_message(message) end end + From 917dc8ffc0fb6e12ca66bea5a4f21474d304b801 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 24 Mar 2017 12:10:52 +0300 Subject: [PATCH 032/110] Update messages_controller.rb --- app/controllers/api/rollbar/messages_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index c93bf8e..7439133 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -24,4 +24,3 @@ def create helpers.send_message(message) end end - From 3002fc4cf62ef9ac48b9af1a941106b62581b22c Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 24 Mar 2017 13:20:04 +0300 Subject: [PATCH 033/110] Update messages_controller.rb --- app/controllers/api/rollbar/messages_controller.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index 7439133..532ee7c 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -14,11 +14,12 @@ def create data = payload['data'] # Prepare message for the campfire - if request_error - message = "Failed request: #{request_error}" - else - message = "Subject: #{event}
Body: #{data}" - end + message = + if request_error + "Failed request: #{request_error}" + else + "Subject: #{event}
Body: #{data}" + end # send message to basecamp helpers.send_message(message) From 4dd08dc8d2a54f575c20758648695598d0d3a2e2 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 24 Mar 2017 13:34:25 +0300 Subject: [PATCH 034/110] Update messages_controller.rb --- app/controllers/api/rollbar/messages_controller.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index 532ee7c..df3f592 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -14,12 +14,11 @@ def create data = payload['data'] # Prepare message for the campfire - message = - if request_error - "Failed request: #{request_error}" - else - "Subject: #{event}
Body: #{data}" - end + message = if request_error + "Failed request: #{request_error}" + else + "Subject: #{event}
Body: #{data}" + end # send message to basecamp helpers.send_message(message) From dc09c8aaa34ab1508058e18d47b2fd0d5b6f2e31 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 24 Mar 2017 13:40:08 +0300 Subject: [PATCH 035/110] Update messages_controller.rb --- app/controllers/api/rollbar/messages_controller.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index df3f592..327d550 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -14,10 +14,14 @@ def create data = payload['data'] # Prepare message for the campfire - message = if request_error - "Failed request: #{request_error}" - else - "Subject: #{event}
Body: #{data}" + message = get_message + + def get_message + if request_error + "Failed request: #{request_error}" + else + "Subject: #{event}
Body: #{data}" + end end # send message to basecamp From 5c8d5e25b28513e4db740f087b889f1cb5b09753 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 24 Mar 2017 13:44:48 +0300 Subject: [PATCH 036/110] Update messages_controller.rb --- .../api/rollbar/messages_controller.rb | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index 327d550..7f1930d 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -14,17 +14,14 @@ def create data = payload['data'] # Prepare message for the campfire - message = get_message - - def get_message - if request_error - "Failed request: #{request_error}" - else - "Subject: #{event}
Body: #{data}" - end + if request_error + message = "Failed request: #{request_error}" + else + message = "Subject: #{event}
Body: #{data}" end - + # send message to basecamp helpers.send_message(message) end end + From 65b6e8de7b1f6361d638733074308e718fe870e7 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 24 Mar 2017 13:46:23 +0300 Subject: [PATCH 037/110] Update messages_controller.rb --- app/controllers/api/rollbar/messages_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index 7f1930d..a617b50 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -24,4 +24,3 @@ def create helpers.send_message(message) end end - From 90957fd0d30f7615d895562c07fc10e49221de66 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 24 Mar 2017 13:49:02 +0300 Subject: [PATCH 038/110] Update messages_controller.rb --- app/controllers/api/rollbar/messages_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index a617b50..7f1930d 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -24,3 +24,4 @@ def create helpers.send_message(message) end end + From 4d83de6a2dbc16038930ecce0bde6e9339436ba7 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 24 Mar 2017 13:50:55 +0300 Subject: [PATCH 039/110] Update messages_controller.rb --- app/controllers/api/rollbar/messages_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index 7f1930d..a617b50 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -24,4 +24,3 @@ def create helpers.send_message(message) end end - From 4658855c2faa38cf5ed7c40e62c1328507d42ea9 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 24 Mar 2017 13:53:56 +0300 Subject: [PATCH 040/110] Update messages_controller.rb --- app/controllers/api/rollbar/messages_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index a617b50..7439133 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -19,7 +19,7 @@ def create else message = "Subject: #{event}
Body: #{data}" end - + # send message to basecamp helpers.send_message(message) end From b73071e443b4fdfae8e07bc01a95aeba0b4ce6bf Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Sat, 25 Mar 2017 22:35:15 +0300 Subject: [PATCH 041/110] Add Rollbar report url generation --- .gitignore | 1 + .../api/rollbar/messages_controller.rb | 26 ++++++++++++------- app/helpers/application_helper.rb | 2 +- config/service.yml | 2 +- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 07b276e..c7e8693 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ /.idea /config/database.yml /config/secrets.yml +/config/service.yml # Ignore the default SQLite database. /db/*.sqlite3 diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index 7439133..60f6704 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -3,24 +3,32 @@ class Api::Rollbar::MessagesController < ApplicationController def create # Get the parsed JSON string - payload = helpers.parse_webhook - + @payload = helpers.parse_webhook + # error: JSON:ParserError # Get the failed JSON request message - request_error = payload[:error] - - # Store parsed dada from Rollerbar - event = payload['event_name'] - data = payload['data'] + request_error = @payload[:error] # Prepare message for the campfire if request_error message = "Failed request: #{request_error}" else - message = "Subject: #{event}
Body: #{data}" + build_message end # send message to basecamp - helpers.send_message(message) + helpers.send_message(build_message) + end + + private + + def build_message + # Store parsed dada from Rollbar + event = @payload['event_name'] + data = @payload['data']['item']['title'] + uuid = @payload['data']['occurrence']['uuid'] + event_url = "https://rollbar.com/instance/uuid?uuid=#{uuid}" + message = "Event: #{event}
Body: #{data}
+ Rollbar report: #{event_url}" end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d2bf861..0ca37f8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -6,7 +6,7 @@ module ApplicationHelper def parse_webhook # Handle exceptions in case of failed request JSON.parse request.body.read - rescue JSON::ParserError => error + rescue JSON::ParserError => error return { error: error.to_s } end diff --git a/config/service.yml b/config/service.yml index ae11439..0c81497 100644 --- a/config/service.yml +++ b/config/service.yml @@ -1,5 +1,5 @@ default: &default - basecampbot_url: https://3.basecamp.com/3601306/integrations/6Mc7Rhug2NkpDY53Qu2x7TGn/buckets/1925463/chats/294329172/lines + basecampbot_url: https://3.basecamp.com/3700178/integrations/3gtJyBKVQHvrQN2h7FitRJSK/buckets/3097353/chats/437772399/lines snstopic_arn: arn:aws:sns:eu-central-1:798348585423:basecamp-bot development: From 54084b18a2e84240877ed6f369567d0453096577 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Sat, 25 Mar 2017 22:46:01 +0300 Subject: [PATCH 042/110] fixed Rollbar report url generation --- app/controllers/api/rollbar/messages_controller.rb | 8 ++++---- app/helpers/application_helper.rb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index 60f6704..91be3bc 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -4,7 +4,7 @@ class Api::Rollbar::MessagesController < ApplicationController def create # Get the parsed JSON string @payload = helpers.parse_webhook - + # error: JSON:ParserError # Get the failed JSON request message request_error = @payload[:error] @@ -13,11 +13,11 @@ def create if request_error message = "Failed request: #{request_error}" else - build_message + message = build_message end # send message to basecamp - helpers.send_message(build_message) + helpers.send_message(message) end private @@ -28,7 +28,7 @@ def build_message data = @payload['data']['item']['title'] uuid = @payload['data']['occurrence']['uuid'] event_url = "https://rollbar.com/instance/uuid?uuid=#{uuid}" - message = "Event: #{event}
Body: #{data}
+ message = "Event: #{event}
Body: #{data}
Rollbar report: #{event_url}" end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0ca37f8..302323b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -7,7 +7,7 @@ def parse_webhook # Handle exceptions in case of failed request JSON.parse request.body.read rescue JSON::ParserError => error - return { error: error.to_s } + return { error: error.to_s } end # Send message to Basecamp Campfire via ChatBot From 78a06b85706a607894344fd66f10a826da404232 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Sat, 25 Mar 2017 22:54:06 +0300 Subject: [PATCH 043/110] Rollbar report url generation fixed config --- config/service.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/service.yml b/config/service.yml index 0c81497..ae11439 100644 --- a/config/service.yml +++ b/config/service.yml @@ -1,5 +1,5 @@ default: &default - basecampbot_url: https://3.basecamp.com/3700178/integrations/3gtJyBKVQHvrQN2h7FitRJSK/buckets/3097353/chats/437772399/lines + basecampbot_url: https://3.basecamp.com/3601306/integrations/6Mc7Rhug2NkpDY53Qu2x7TGn/buckets/1925463/chats/294329172/lines snstopic_arn: arn:aws:sns:eu-central-1:798348585423:basecamp-bot development: From 9638ad112717632909adcd0a88916792aa90d9f6 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Sat, 25 Mar 2017 23:10:14 +0300 Subject: [PATCH 044/110] Update messages_controller.rb --- app/controllers/api/rollbar/messages_controller.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index 91be3bc..0c7a651 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -10,11 +10,11 @@ def create request_error = @payload[:error] # Prepare message for the campfire - if request_error - message = "Failed request: #{request_error}" - else - message = build_message - end + message = if request_error + "Failed request: #{request_error}" + else + build_message + end # send message to basecamp helpers.send_message(message) From 00f79cfbf04d94855a1b0eda748bfd437e1561be Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Sat, 25 Mar 2017 23:11:28 +0300 Subject: [PATCH 045/110] Update messages_controller.rb --- app/controllers/api/rollbar/messages_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index 0c7a651..6e0ccd4 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -13,7 +13,7 @@ def create message = if request_error "Failed request: #{request_error}" else - build_message + build_message end # send message to basecamp From f8d2fec2ba48e636b1b3405605e4b4e532030dae Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Sat, 25 Mar 2017 23:17:59 +0300 Subject: [PATCH 046/110] Update messages_controller.rb --- app/controllers/api/rollbar/messages_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index 6e0ccd4..93a598e 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -10,7 +10,7 @@ def create request_error = @payload[:error] # Prepare message for the campfire - message = if request_error + message = if request_error "Failed request: #{request_error}" else build_message From e27683d9f4e4047454004e3d244a86de35b6768a Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Sat, 25 Mar 2017 23:19:29 +0300 Subject: [PATCH 047/110] Update messages_controller.rb --- app/controllers/api/rollbar/messages_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index 93a598e..b294b32 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -11,10 +11,10 @@ def create # Prepare message for the campfire message = if request_error - "Failed request: #{request_error}" - else - build_message - end + "Failed request: #{request_error}" + else + build_message + end # send message to basecamp helpers.send_message(message) From b713e9c61c6d8cb627f51f3270b0859a35478c38 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Sat, 25 Mar 2017 23:21:54 +0300 Subject: [PATCH 048/110] Update messages_controller.rb --- app/controllers/api/rollbar/messages_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index b294b32..43bae7b 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -9,7 +9,7 @@ def create # Get the failed JSON request message request_error = @payload[:error] - # Prepare message for the campfire + # Prepare message for the campfire message = if request_error "Failed request: #{request_error}" else From 45365fed8f5a2f80cc87b2b21ee975077871c027 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Sat, 25 Mar 2017 23:23:24 +0300 Subject: [PATCH 049/110] Update messages_controller.rb --- app/controllers/api/rollbar/messages_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index 43bae7b..b294b32 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -9,7 +9,7 @@ def create # Get the failed JSON request message request_error = @payload[:error] - # Prepare message for the campfire + # Prepare message for the campfire message = if request_error "Failed request: #{request_error}" else From 35adb283b406f47b1d197d93434786e4cf5010f8 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Sun, 26 Mar 2017 12:48:06 +0300 Subject: [PATCH 050/110] Add Rollbar instructions and fix controller --- README.html | 1069 +++++++++++++++++ README.md | 34 +- .../api/rollbar/messages_controller.rb | 5 +- config/service.yml | 2 +- 4 files changed, 1096 insertions(+), 14 deletions(-) create mode 100644 README.html diff --git a/README.html b/README.html new file mode 100644 index 0000000..cb65b08 --- /dev/null +++ b/README.html @@ -0,0 +1,1069 @@ +README

basecamp3-rails-chatbot

+

Rails application to transfer messages to your basecamp3 HQ.

+

Supported services

+
    +
  1. AWS SNS
  2. +
  3. Rollbar
  4. +
+

Instruction

+

Create a Chatbot

+
    +
  1. Register Basecamp and create bot. There
    +you need a bot long link. Like this:
    +https://3.basecamp.com/195539477/integrations/2uH9aHLEVhhaXKPaqrj8yw8P/buckets/2085958501/chats/9007199254741775/lines
  2. +
  3. Clone this repo from GitHub.
      +
    1. Run bundle install in your project directory.
    2. +
    3. Create a secrets.yml file in your config folder as described here.
    4. +
    +
  4. +
  5. Add your Basecamp bot url to /config/service.yml
  6. +
  7. +

    You will probably want to try running your app locally to test it and make sure it’s working as expected. To do that you will need a service that allows you to expose a web server running on your local machine to the Internet. We recommend to try Ngrok.

    +
      +
    1. +

      If you see this message on rails console:
      +Cannot render console from XXX.XXX.XXX.XXX! Allowed networks: 127.0.0.1,...
      + You need to whitelist the XXX.XXX.XXX.XXX network space in the Web console config.
      + Open config/environments/development.rb and type IP address of remote server:

      +

      config.web_console.whitelisted_ips = 'XXX.XXX.XXX.XXX'

      +
    2. +
    +

    Read more about IP’s whitelisting here.

    +
  8. +
+

AWS integration

+
    +
  1. Register AWS and create SNS topic. Remember Topic ARN! It looks like this:
    +arn:aws:sns:us-east-6:23730808936387:topick_name
  2. +
  3. Add your SNS Topic ARN to /config/service.yml
  4. +
  5. Start rails server by typing rails s command.
  6. +
  7. Create subscription. Use HTTP Protocol and http://your-external-host/api/v1/messages as Endpoint
  8. +
  9. At first time SNS send confirmation request. After subscription you can
    +publish messages to a topic
  10. +
+

Rollbar integration

+
    +
  1. Create Rollbar account and start the New project.
  2. +
  3. Navigate to the project, click ‘Settings’, then click ‘Notifications’ in the left menu.
  4. +
  5. Select the ‘Webhook’, enter the full URL where webhooks should be posted and enable the integration. Once set up, you can add, edit, or remove rules. For more instruction, please visit Rollbar docs and Ruby Integration
  6. +
+

References

+
\ No newline at end of file diff --git a/README.md b/README.md index 7577e88..58dcd38 100644 --- a/README.md +++ b/README.md @@ -2,23 +2,22 @@ Rails application to transfer messages to your basecamp3 HQ. -## Supported services +### Supported services 1. [AWS SNS](https://aws.amazon.com/sns/) +1. [Rollbar](https://rollbar.com) -## Usage +### Instruction -1. Register AWS and [create SNS topic](http://docs.aws.amazon.com/sns/latest/dg/CreateTopic.html). Remember Topic ARN! It looks like this: - `arn:aws:sns:us-east-6:23730808936387:topick_name` -2. Register Basecamp and [create bot](https://m.signalvnoise.com/new-in-basecamp-3-chatbots-8526618c0c7d#.kabo3hgs1). There +#### Create a Chatbot + +1. Register Basecamp and [create bot](https://m.signalvnoise.com/new-in-basecamp-3-chatbots-8526618c0c7d#.kabo3hgs1). There you need a bot long link. Like this: `https://3.basecamp.com/195539477/integrations/2uH9aHLEVhhaXKPaqrj8yw8P/buckets/2085958501/chats/9007199254741775/lines` -3. Clone this repo from GitHub. +2. Clone this repo from GitHub. 1. Run __`bundle install`__ in your project directory. 2. Create a ```secrets.yml``` file in your config folder as described [here](http://guides.rubyonrails.org/upgrading_ruby_on_rails.html#config-secrets-yml). -4. Write your SNS **Topic ARN** and Basecamp **bot url** to /config/service.yml -5. Start rails server by typing `rails s` command. -6. [Create subscription](http://docs.aws.amazon.com/sns/latest/dg/SubscribeTopic.html). Use HTTP **Protocol** and `http://your-external-host/api/v1/messages` as **Endpoint** -7. You will probably want to try running your app locally to test it and make sure it’s working as expected. To do that you will need a service that allows you to expose a web server running on your local machine to the Internet. We recommend to try [Ngrok](http://ngrok.com). +3. Add your Basecamp __bot url__ to `/config/service.yml` +4. You will probably want to try running your app locally to test it and make sure it’s working as expected. To do that you will need a service that allows you to expose a web server running on your local machine to the Internet. We recommend to try [Ngrok](http://ngrok.com). 1. If you see this message on rails console: ``Cannot render console from XXX.XXX.XXX.XXX! Allowed networks: 127.0.0.1,...`` You need to whitelist the XXX.XXX.XXX.XXX network space in the Web console config. @@ -28,9 +27,22 @@ you need a bot long link. Like this: Read more about IP's whitelisting [here](https://github.com/rails/web-console#configweb_consolewhitelisted_ips). +#### AWS integration + +1. Register AWS and [create SNS topic](http://docs.aws.amazon.com/sns/latest/dg/CreateTopic.html). Remember Topic ARN! It looks like this: + `arn:aws:sns:us-east-6:23730808936387:topick_name` +2. Add your SNS __Topic ARN__ to `/config/service.yml` +3. Start rails server by typing `rails s` command. +4. [Create subscription](http://docs.aws.amazon.com/sns/latest/dg/SubscribeTopic.html). Use HTTP **Protocol** and `http://your-external-host/api/v1/messages` as __Endpoint__ 8. At first time SNS send confirmation request. After subscription you can [publish messages to a topic](http://docs.aws.amazon.com/sns/latest/dg/PublishTopic.html) -## References +#### Rollbar integration + +1. Create [Rollbar account](https://rollbar.com) and start the New project. +2. Navigate to the project, click 'Settings', then click 'Notifications' in the left menu. +3. Select the 'Webhook', enter the full URL where webhooks should be posted and enable the integration. Once set up, you can add, edit, or remove rules. For more instruction, please visit [Rollbar docs](https://rollbar.com/docs/webhooks) and [Ruby Integration](https://rollbar.com/docs/notifier/rollbar-gem) + +#### References * Most controller logic based on [Creating SNS subscription endpoints with Ruby on Rails](http://blog.eng.xogrp.com/post/79166302844/creating-sns-subscription-endpoints-with-ruby-on#disqus_thread) \ No newline at end of file diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index b294b32..2224882 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -11,7 +11,7 @@ def create # Prepare message for the campfire message = if request_error - "Failed request: #{request_error}" + "Failed request: #{request_error}" else build_message end @@ -28,7 +28,8 @@ def build_message data = @payload['data']['item']['title'] uuid = @payload['data']['occurrence']['uuid'] event_url = "https://rollbar.com/instance/uuid?uuid=#{uuid}" - message = "Event: #{event}
Body: #{data}
+ message = "Event: #{event}
+ Body: #{data}
Rollbar report: #{event_url}" end end diff --git a/config/service.yml b/config/service.yml index ae11439..0c81497 100644 --- a/config/service.yml +++ b/config/service.yml @@ -1,5 +1,5 @@ default: &default - basecampbot_url: https://3.basecamp.com/3601306/integrations/6Mc7Rhug2NkpDY53Qu2x7TGn/buckets/1925463/chats/294329172/lines + basecampbot_url: https://3.basecamp.com/3700178/integrations/3gtJyBKVQHvrQN2h7FitRJSK/buckets/3097353/chats/437772399/lines snstopic_arn: arn:aws:sns:eu-central-1:798348585423:basecamp-bot development: From 5df736748aa6a0592d40daf0afaa410da7cca9db Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Sun, 26 Mar 2017 12:52:29 +0300 Subject: [PATCH 051/110] Add Rollbar instructions and fix controller --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 58dcd38..7315bcf 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,8 @@ you need a bot long link. Like this: 1. Create [Rollbar account](https://rollbar.com) and start the New project. 2. Navigate to the project, click 'Settings', then click 'Notifications' in the left menu. -3. Select the 'Webhook', enter the full URL where webhooks should be posted and enable the integration. Once set up, you can add, edit, or remove rules. For more instruction, please visit [Rollbar docs](https://rollbar.com/docs/webhooks) and [Ruby Integration](https://rollbar.com/docs/notifier/rollbar-gem) +3. Select the 'Webhook', enter the full URL where webhooks should be posted (this App server IP) and enable the integration. +4. Once set up, you can add, edit, or remove rules. For more instruction, please visit [Rollbar docs](https://rollbar.com/docs/webhooks) and [Ruby Integration](https://rollbar.com/docs/notifier/rollbar-gem) #### References From dc61e47e530e5fbf27417ecbcc43df2c0d0eb4ba Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Sun, 26 Mar 2017 12:56:42 +0300 Subject: [PATCH 052/110] Add Rollbar instructions and fix controller --- app/controllers/api/rollbar/messages_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index 2224882..b1977fc 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -28,7 +28,7 @@ def build_message data = @payload['data']['item']['title'] uuid = @payload['data']['occurrence']['uuid'] event_url = "https://rollbar.com/instance/uuid?uuid=#{uuid}" - message = "Event: #{event}
+ message = "Event: #{event}
Body: #{data}
Rollbar report: #{event_url}" end From 5c44fd31a5e8ed6368b5065c379e5a4d5bbb370d Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Sun, 26 Mar 2017 13:01:06 +0300 Subject: [PATCH 053/110] Add Rollbar instructions and fix controller --- app/controllers/api/rollbar/messages_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index b1977fc..7c26591 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -29,7 +29,7 @@ def build_message uuid = @payload['data']['occurrence']['uuid'] event_url = "https://rollbar.com/instance/uuid?uuid=#{uuid}" message = "Event: #{event}
- Body: #{data}
- Rollbar report: #{event_url}" + Body: #{data}
+ Rollbar report: #{event_url}" end end From 7340997f0339c5081212bb2ac8564c5e41466483 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Sun, 26 Mar 2017 13:06:03 +0300 Subject: [PATCH 054/110] Add Rollbar instructions and fix controller --- .gitignore | 1 + README.html | 1069 --------------------------------------------------- 2 files changed, 1 insertion(+), 1069 deletions(-) delete mode 100644 README.html diff --git a/.gitignore b/.gitignore index c7e8693..ce70225 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ /tmp/* !/log/.keep !/tmp/.keep +/README.html # Ignore Byebug command history file. .byebug_history diff --git a/README.html b/README.html deleted file mode 100644 index cb65b08..0000000 --- a/README.html +++ /dev/null @@ -1,1069 +0,0 @@ -README

basecamp3-rails-chatbot

-

Rails application to transfer messages to your basecamp3 HQ.

-

Supported services

-
    -
  1. AWS SNS
  2. -
  3. Rollbar
  4. -
-

Instruction

-

Create a Chatbot

-
    -
  1. Register Basecamp and create bot. There
    -you need a bot long link. Like this:
    -https://3.basecamp.com/195539477/integrations/2uH9aHLEVhhaXKPaqrj8yw8P/buckets/2085958501/chats/9007199254741775/lines
  2. -
  3. Clone this repo from GitHub.
      -
    1. Run bundle install in your project directory.
    2. -
    3. Create a secrets.yml file in your config folder as described here.
    4. -
    -
  4. -
  5. Add your Basecamp bot url to /config/service.yml
  6. -
  7. -

    You will probably want to try running your app locally to test it and make sure it’s working as expected. To do that you will need a service that allows you to expose a web server running on your local machine to the Internet. We recommend to try Ngrok.

    -
      -
    1. -

      If you see this message on rails console:
      -Cannot render console from XXX.XXX.XXX.XXX! Allowed networks: 127.0.0.1,...
      - You need to whitelist the XXX.XXX.XXX.XXX network space in the Web console config.
      - Open config/environments/development.rb and type IP address of remote server:

      -

      config.web_console.whitelisted_ips = 'XXX.XXX.XXX.XXX'

      -
    2. -
    -

    Read more about IP’s whitelisting here.

    -
  8. -
-

AWS integration

-
    -
  1. Register AWS and create SNS topic. Remember Topic ARN! It looks like this:
    -arn:aws:sns:us-east-6:23730808936387:topick_name
  2. -
  3. Add your SNS Topic ARN to /config/service.yml
  4. -
  5. Start rails server by typing rails s command.
  6. -
  7. Create subscription. Use HTTP Protocol and http://your-external-host/api/v1/messages as Endpoint
  8. -
  9. At first time SNS send confirmation request. After subscription you can
    -publish messages to a topic
  10. -
-

Rollbar integration

-
    -
  1. Create Rollbar account and start the New project.
  2. -
  3. Navigate to the project, click ‘Settings’, then click ‘Notifications’ in the left menu.
  4. -
  5. Select the ‘Webhook’, enter the full URL where webhooks should be posted and enable the integration. Once set up, you can add, edit, or remove rules. For more instruction, please visit Rollbar docs and Ruby Integration
  6. -
-

References

-
\ No newline at end of file From 813f3c778cd5264b7af432e8506a9d46b85a606a Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Sun, 26 Mar 2017 13:09:34 +0300 Subject: [PATCH 055/110] Add Rollbar instructions and fix controller --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ce70225..e6aec53 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,4 @@ # Ignore RVM files. /.ruby-gemset -/.ruby-version \ No newline at end of file +/.ruby-version From bf66a722a1a2d7062a363c7b696b5408602c4f60 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Sun, 26 Mar 2017 13:15:17 +0300 Subject: [PATCH 056/110] Update service.yml --- config/service.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/service.yml b/config/service.yml index 0c81497..1c21434 100644 --- a/config/service.yml +++ b/config/service.yml @@ -1,5 +1,5 @@ default: &default - basecampbot_url: https://3.basecamp.com/3700178/integrations/3gtJyBKVQHvrQN2h7FitRJSK/buckets/3097353/chats/437772399/lines + basecampbot_url: https://3.basecamp.com/3601306/integrations/6Mc7Rhug2NkpDY53Qu2x7TGn/buckets/1925463/chats/294329172/lines snstopic_arn: arn:aws:sns:eu-central-1:798348585423:basecamp-bot development: @@ -9,4 +9,4 @@ test: <<: *default production: - <<: *default \ No newline at end of file + <<: *default From a409125079d82777f1bdf822b655a4503fa31b86 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Sun, 26 Mar 2017 13:17:51 +0300 Subject: [PATCH 057/110] Update service.yml From e2b2c59c836a60df25a4e1904c1e1325ff3e9c10 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Sun, 26 Mar 2017 13:20:03 +0300 Subject: [PATCH 058/110] Add Rollbar instructions and fix controller --- config/service.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/service.yml b/config/service.yml index 0c81497..ae11439 100644 --- a/config/service.yml +++ b/config/service.yml @@ -1,5 +1,5 @@ default: &default - basecampbot_url: https://3.basecamp.com/3700178/integrations/3gtJyBKVQHvrQN2h7FitRJSK/buckets/3097353/chats/437772399/lines + basecampbot_url: https://3.basecamp.com/3601306/integrations/6Mc7Rhug2NkpDY53Qu2x7TGn/buckets/1925463/chats/294329172/lines snstopic_arn: arn:aws:sns:eu-central-1:798348585423:basecamp-bot development: From 7a97e23f77639191f8ef6f99152c56d999e4ca09 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Sun, 26 Mar 2017 13:23:03 +0300 Subject: [PATCH 059/110] Add Rollbar instructions and fix controller --- config/service.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/service.yml b/config/service.yml index 1c21434..ae11439 100644 --- a/config/service.yml +++ b/config/service.yml @@ -9,4 +9,4 @@ test: <<: *default production: - <<: *default + <<: *default \ No newline at end of file From d95463e12e30240fca3c4f03aedab4d84dcf9da0 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Sun, 26 Mar 2017 18:41:45 +0300 Subject: [PATCH 060/110] Edit Rollbar instructions --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7315bcf..c4f7728 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,11 @@ Rails application to transfer messages to your basecamp3 HQ. ### Instruction +* [Create a Chatbot](#create-chatbot ) +* [AWS integration](#aws-integration) +* [Rollbar integration](#rollbar-integration) +* [References](#references) + #### Create a Chatbot 1. Register Basecamp and [create bot](https://m.signalvnoise.com/new-in-basecamp-3-chatbots-8526618c0c7d#.kabo3hgs1). There @@ -41,7 +46,7 @@ you need a bot long link. Like this: 1. Create [Rollbar account](https://rollbar.com) and start the New project. 2. Navigate to the project, click 'Settings', then click 'Notifications' in the left menu. -3. Select the 'Webhook', enter the full URL where webhooks should be posted (this App server IP) and enable the integration. +3. Select the 'Webhook', enter the full URL where webhooks should be posted (this App server) and enable the integration. 4. Once set up, you can add, edit, or remove rules. For more instruction, please visit [Rollbar docs](https://rollbar.com/docs/webhooks) and [Ruby Integration](https://rollbar.com/docs/notifier/rollbar-gem) #### References From 68640649a43d5fcdd3ad8b448ba1c9c1d99e7a35 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Tue, 28 Mar 2017 04:32:16 +0300 Subject: [PATCH 061/110] begin Bugsnag integration --- .../api/bugsnag/messages_controller.rb | 34 +++++++++++++++++++ config/routes.rb | 4 +++ config/service.yml | 2 +- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 app/controllers/api/bugsnag/messages_controller.rb diff --git a/app/controllers/api/bugsnag/messages_controller.rb b/app/controllers/api/bugsnag/messages_controller.rb new file mode 100644 index 0000000..3abc154 --- /dev/null +++ b/app/controllers/api/bugsnag/messages_controller.rb @@ -0,0 +1,34 @@ +class Api::Bugsnag::MessagesController < ApplicationController + skip_before_action :verify_authenticity_token + + def create + # Get the parsed JSON string + @payload = helpers.parse_webhook + + # error: JSON:ParserError + # Get the failed JSON request message + request_error = @payload[:error] + + # Prepare message for the campfire + message = if request_error + "Failed request: #{request_error}" + else + build_message + end + + # send message to basecamp + helpers.send_message(message) + end + + private + + def build_message + # Store parsed dada from Rollbar + event = @payload['error']['exceptionClass'] + error_message = @payload['error']['message'] + event_url = @payload['error']['url'] + message = "Event: #{event}
+ Body: #{error_message}
+ Rollbar report: #{event_url}" + end +end diff --git a/config/routes.rb b/config/routes.rb index b8d9d95..872baf4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,5 +9,9 @@ namespace :rollbar do resources :messages, only: :create end + + namespace :bugsnag do + resources :messages, only: :create + end end end diff --git a/config/service.yml b/config/service.yml index ae11439..0c81497 100644 --- a/config/service.yml +++ b/config/service.yml @@ -1,5 +1,5 @@ default: &default - basecampbot_url: https://3.basecamp.com/3601306/integrations/6Mc7Rhug2NkpDY53Qu2x7TGn/buckets/1925463/chats/294329172/lines + basecampbot_url: https://3.basecamp.com/3700178/integrations/3gtJyBKVQHvrQN2h7FitRJSK/buckets/3097353/chats/437772399/lines snstopic_arn: arn:aws:sns:eu-central-1:798348585423:basecamp-bot development: From a63d077e3097644c98d74b2bebb97b33fcf8e456 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Wed, 29 Mar 2017 02:59:49 +0300 Subject: [PATCH 062/110] add some Gitlab integration --- .../api/gitlab/messages_controller.rb | 34 +++++++++++++++++++ config/routes.rb | 10 ++++-- 2 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 app/controllers/api/gitlab/messages_controller.rb diff --git a/app/controllers/api/gitlab/messages_controller.rb b/app/controllers/api/gitlab/messages_controller.rb new file mode 100644 index 0000000..60ec0c8 --- /dev/null +++ b/app/controllers/api/gitlab/messages_controller.rb @@ -0,0 +1,34 @@ +class Api::Gitlab::MessagesController < ApplicationController + skip_before_action :verify_authenticity_token + + def create + # Get the parsed JSON string + @payload = helpers.parse_webhook + + # error: JSON:ParserError + # Get the failed JSON request message + request_error = @payload[:error] + + # Prepare message for the campfire + message = if request_error + "Failed request: #{request_error}" + else + build_message + end + + # send message to basecamp + helpers.send_message(message) + end + + private + + def build_message + # Store parsed dada from Rollbar + progect_name = @payload['project']['name'] + event = @payload['object_kind'] + project_url = @payload['project']['web_url'] + message = "Project: #{progect_name}
+ Event: #{event}
+ Project url: #{project_url}" + end +end diff --git a/config/routes.rb b/config/routes.rb index 872baf4..c40d06b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,7 +2,11 @@ # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html namespace :api, defaults: {format: :json} do - namespace :v1 do + namespace :bugsnag do + resources :messages, only: :create + end + + namespace :gitlab do resources :messages, only: :create end @@ -10,8 +14,8 @@ resources :messages, only: :create end - namespace :bugsnag do + namespace :v1 do resources :messages, only: :create end end -end +end \ No newline at end of file From a2cbe7e0e3a10d4ba8ab472e6f6e3dcffc4d3b2c Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Thu, 30 Mar 2017 02:38:28 +0300 Subject: [PATCH 063/110] Add wrong JSON field validation --- app/controllers/api/gitlab/messages_controller.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/gitlab/messages_controller.rb b/app/controllers/api/gitlab/messages_controller.rb index 60ec0c8..51fdaad 100644 --- a/app/controllers/api/gitlab/messages_controller.rb +++ b/app/controllers/api/gitlab/messages_controller.rb @@ -11,7 +11,7 @@ def create # Prepare message for the campfire message = if request_error - "Failed request: #{request_error}" + "Failed request: #{request_error}" else build_message end @@ -24,11 +24,13 @@ def create def build_message # Store parsed dada from Rollbar - progect_name = @payload['project']['name'] + project_name = @payload['project']['name'] event = @payload['object_kind'] project_url = @payload['project']['web_url'] - message = "Project: #{progect_name}
- Event: #{event}
- Project url: #{project_url}" + return "Project: #{project_name}
+ Event: #{event}
+ Project url: #{project_url}" + rescue NoMethodError => error + return "Error parsing GitLab issue: #{error}" end end From be04b3be653b57f6c9ae6fdb74712b56c757ac4b Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Thu, 30 Mar 2017 03:41:30 +0300 Subject: [PATCH 064/110] Add wrong JSON field validation --- app/controllers/api/rollbar/messages_controller.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index 7c26591..20b04ff 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -28,8 +28,10 @@ def build_message data = @payload['data']['item']['title'] uuid = @payload['data']['occurrence']['uuid'] event_url = "https://rollbar.com/instance/uuid?uuid=#{uuid}" - message = "Event: #{event}
- Body: #{data}
- Rollbar report: #{event_url}" + return "Event: #{event}
+ Body: #{data}
+ Rollbar report: #{event_url}" + rescue NoMethodError => error + return "Error parsing Rollbar issue: #{error}" end end From acde3e9c94276c12cb10ebb817660e29b7ea9d1f Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Thu, 30 Mar 2017 11:07:02 +0300 Subject: [PATCH 065/110] Add Rollbar JSON exception --- config/service.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/service.yml b/config/service.yml index ae11439..0c81497 100644 --- a/config/service.yml +++ b/config/service.yml @@ -1,5 +1,5 @@ default: &default - basecampbot_url: https://3.basecamp.com/3601306/integrations/6Mc7Rhug2NkpDY53Qu2x7TGn/buckets/1925463/chats/294329172/lines + basecampbot_url: https://3.basecamp.com/3700178/integrations/3gtJyBKVQHvrQN2h7FitRJSK/buckets/3097353/chats/437772399/lines snstopic_arn: arn:aws:sns:eu-central-1:798348585423:basecamp-bot development: From 0935e1e941d54c0ab3d8c4512d5b771e85cc3e78 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Sun, 2 Apr 2017 01:44:00 +0300 Subject: [PATCH 066/110] Rewrite Aws sns controller --- Gemfile | 2 ++ Gemfile.lock | 10 ++++++ .../api/bugsnag/messages_controller.rb | 26 ++++++++------- .../api/giphy/messages_controller.rb | 19 +++++++++++ .../api/gitlab/messages_controller.rb | 24 +++++++------- .../api/rollbar/messages_controller.rb | 24 +++++++------- .../api/sns/messages_controller.rb | 33 +++++++++++++++++++ app/helpers/application_helper.rb | 21 +++++++++--- config/routes.rb | 6 +++- config/service.yml | 7 +++- ...s_controller.rb => messages_controller.bak | 0 11 files changed, 130 insertions(+), 42 deletions(-) create mode 100644 app/controllers/api/giphy/messages_controller.rb create mode 100644 app/controllers/api/sns/messages_controller.rb rename app/controllers/api/v1/messages_controller.rb => messages_controller.bak (100%) diff --git a/Gemfile b/Gemfile index 1d715cb..83015ea 100644 --- a/Gemfile +++ b/Gemfile @@ -11,6 +11,8 @@ gem 'httparty' gem 'sass-rails', '~> 5.0' gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.2' +gem 'aws-sdk', '~> 2' + group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console diff --git a/Gemfile.lock b/Gemfile.lock index 749f1a3..86d1cc6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -39,6 +39,14 @@ GEM minitest (~> 5.1) tzinfo (~> 1.1) arel (7.1.4) + aws-sdk (2.9.0) + aws-sdk-resources (= 2.9.0) + aws-sdk-core (2.9.0) + aws-sigv4 (~> 1.0) + jmespath (~> 1.0) + aws-sdk-resources (2.9.0) + aws-sdk-core (= 2.9.0) + aws-sigv4 (1.0.0) builder (3.2.3) byebug (9.0.6) coffee-rails (4.2.1) @@ -58,6 +66,7 @@ GEM httparty (0.14.0) multi_xml (>= 0.5.2) i18n (0.8.1) + jmespath (1.3.1) listen (3.0.8) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -146,6 +155,7 @@ PLATFORMS ruby DEPENDENCIES + aws-sdk (~> 2) byebug coffee-rails (~> 4.2) httparty diff --git a/app/controllers/api/bugsnag/messages_controller.rb b/app/controllers/api/bugsnag/messages_controller.rb index 3abc154..8e8d47c 100644 --- a/app/controllers/api/bugsnag/messages_controller.rb +++ b/app/controllers/api/bugsnag/messages_controller.rb @@ -3,17 +3,17 @@ class Api::Bugsnag::MessagesController < ApplicationController def create # Get the parsed JSON string - @payload = helpers.parse_webhook + bugsnag_parsed = helpers.parse_webhook # error: JSON:ParserError # Get the failed JSON request message - request_error = @payload[:error] + request_error = bugsnag_parsed[:error] # Prepare message for the campfire message = if request_error - "Failed request: #{request_error}" + "Failed or 'non JSON' request: #{request_error}" else - build_message + build_message_text bugsnag_parsed end # send message to basecamp @@ -22,13 +22,15 @@ def create private - def build_message - # Store parsed dada from Rollbar - event = @payload['error']['exceptionClass'] - error_message = @payload['error']['message'] - event_url = @payload['error']['url'] - message = "Event: #{event}
- Body: #{error_message}
- Rollbar report: #{event_url}" + def build_message_text(bugsnag_parsed) + # Store parsed dada from Bugsnag + event = bugsnag_parsed['error']['exceptionClass'] + error_message = bugsnag_parsed['error']['message'] + event_url = bugsnag_parsed['error']['url'] + return "Event: #{event}
+ Message: #{error_message}
+ Bugsnag report: #{event_url}" + rescue NoMethodError => error # remove exception handlidg to see errors in the Dev. console + return "Bugsnag parsing error: #{error}" end end diff --git a/app/controllers/api/giphy/messages_controller.rb b/app/controllers/api/giphy/messages_controller.rb new file mode 100644 index 0000000..ae975fd --- /dev/null +++ b/app/controllers/api/giphy/messages_controller.rb @@ -0,0 +1,19 @@ +class Api::Giphy::MessagesController < ApplicationController + skip_before_action :verify_authenticity_token + + def create + giphy_url = Rails.configuration.service['giphy_url'] + giphy_parsed = JSON.parse HTTParty.get(giphy_url).body + giphy_response_status = giphy_parsed['meta']['status'] + + if giphy_response_status == 200 + message = giphy_parsed['data']['fixed_width_downsampled_url'] + else + message = "There's a problem with Gliphy API: response status = #{giphy_response_status}" + end + + # send message to basecamp + helpers.send_message(message) + + end +end diff --git a/app/controllers/api/gitlab/messages_controller.rb b/app/controllers/api/gitlab/messages_controller.rb index 51fdaad..6648159 100644 --- a/app/controllers/api/gitlab/messages_controller.rb +++ b/app/controllers/api/gitlab/messages_controller.rb @@ -3,17 +3,17 @@ class Api::Gitlab::MessagesController < ApplicationController def create # Get the parsed JSON string - @payload = helpers.parse_webhook + gitlab_parsed = helpers.parse_webhook # error: JSON:ParserError # Get the failed JSON request message - request_error = @payload[:error] + request_error = gitlab_parsed[:error] # Prepare message for the campfire message = if request_error - "Failed request: #{request_error}" + "Failed or 'non JSON' request: #{request_error}" else - build_message + build_message_text gitlab_parsed end # send message to basecamp @@ -22,15 +22,15 @@ def create private - def build_message - # Store parsed dada from Rollbar - project_name = @payload['project']['name'] - event = @payload['object_kind'] - project_url = @payload['project']['web_url'] - return "Project: #{project_name}
+ def build_message_text(gitlab_parsed) + # Store parsed dada from GitLab + project_name = gitlab_parsed['project']['name'] + event = gitlab_parsed['object_kind'] + project_url = gitlab_parsed['project']['web_url'] + return "Gitlab project: #{project_name}
Event: #{event}
Project url: #{project_url}" - rescue NoMethodError => error - return "Error parsing GitLab issue: #{error}" + rescue NoMethodError => error # remove exception handlidg to see errors in the Dev. console + return "GitLab parsing error: #{error}" end end diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index 7c26591..61b181a 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -3,17 +3,17 @@ class Api::Rollbar::MessagesController < ApplicationController def create # Get the parsed JSON string - @payload = helpers.parse_webhook + rollbar_parsed = helpers.parse_webhook # error: JSON:ParserError # Get the failed JSON request message - request_error = @payload[:error] + request_error = rollbar_parsed[:error] # Prepare message for the campfire message = if request_error - "Failed request: #{request_error}" + "Failed or 'non JSON' request: #{request_error}" else - build_message + build_message_text rollbar_parsed end # send message to basecamp @@ -22,14 +22,16 @@ def create private - def build_message + def build_message_text(rollbar_parsed) # Store parsed dada from Rollbar - event = @payload['event_name'] - data = @payload['data']['item']['title'] - uuid = @payload['data']['occurrence']['uuid'] + event = rollbar_parsed['event_name'] + data = rollbar_parsed['data']['item']['title'] + uuid = rollbar_parsed['data']['occurrence']['uuid'] event_url = "https://rollbar.com/instance/uuid?uuid=#{uuid}" - message = "Event: #{event}
- Body: #{data}
- Rollbar report: #{event_url}" + return "Event: #{event}
+ Body: #{data}
+ Rollbar report: #{event_url}" + rescue NoMethodError => error # remove exception handlidg to see errors in the Dev. console + return "Rollbar parsing error: #{error}" end end diff --git a/app/controllers/api/sns/messages_controller.rb b/app/controllers/api/sns/messages_controller.rb new file mode 100644 index 0000000..a74821f --- /dev/null +++ b/app/controllers/api/sns/messages_controller.rb @@ -0,0 +1,33 @@ +class Api::Sns::MessagesController < ApplicationController + skip_before_action :verify_authenticity_token + + def create + amazon_sns_request = helpers.parse_webhook + snstopic_arn = Rails.configuration.service['snstopic_arn'] + client = helpers.aws_config + + if amazon_sns_request['Type'].to_s.downcase == "subscriptionconfirmation" + resp = client.confirm_subscription({ + topic_arn: snstopic_arn, + token: amazon_sns_request['Token'], + }) + elsif amazon_sns_request['Type'].to_s.downcase == "notification" + message = build_message_text(amazon_sns_request) + end + + # send message to basecamp + helpers.send_message(message) + end + + private + + def build_message_text(amazon_sns_request) + # Store parsed dada from amazon SNS + subject = amazon_sns_request['Subject'] + body = amazon_sns_request['Message'] + return "Subject: #{subject}
+ Body: #{body}
" + rescue NoMethodError => error # remove exception handlidg to see errors in the Dev. console + return "Amazon SNS parsing error: #{error}" + end +end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 302323b..10ab4fe 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,17 +1,28 @@ module ApplicationHelper - require 'json' - require 'httparty' + def aws_config + snstopic_arn = Rails.configuration.service['snstopic_arn'] + aws_secret_file = Rails.configuration.service['aws_secret_file'] + creds = JSON.load(File.read aws_secret_file) + + # Configure and create an AWS_SNS client + Aws.config.update({ + region: creds['aws_region'], + credentials: Aws::Credentials.new(creds['aws_access_key'], creds['aws_secret_key']) + }) + + client = Aws::SNS::Client.new + end - # Parse JSON request from remote calback server def parse_webhook - # Handle exceptions in case of failed request + # Parse JSON request from remote calback server JSON.parse request.body.read + # Handle exceptions in case of failed request rescue JSON::ParserError => error return { error: error.to_s } end - # Send message to Basecamp Campfire via ChatBot def send_message(message) + # Send message to Basecamp Campfire via ChatBot basecampbot_url = Rails.configuration.service['basecampbot_url'] HTTParty.post basecampbot_url, query: { content: message } end diff --git a/config/routes.rb b/config/routes.rb index c40d06b..2f488da 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,11 +10,15 @@ resources :messages, only: :create end + namespace :giphy do + resources :messages, only: :create + end + namespace :rollbar do resources :messages, only: :create end - namespace :v1 do + namespace :sns do resources :messages, only: :create end end diff --git a/config/service.yml b/config/service.yml index 0c81497..01c58d9 100644 --- a/config/service.yml +++ b/config/service.yml @@ -1,6 +1,11 @@ +# Add this file to .gitignore right now !!! default: &default basecampbot_url: https://3.basecamp.com/3700178/integrations/3gtJyBKVQHvrQN2h7FitRJSK/buckets/3097353/chats/437772399/lines - snstopic_arn: arn:aws:sns:eu-central-1:798348585423:basecamp-bot + snstopic_arn: arn:aws:sns:us-west-2:230306836787:magick_kick + # Path to the .json file that contain contains 'aws_access_key' and 'aws_secret_key' + aws_secret_file: /home/klim/secrets.json + # Giphy API url + public API key + giphy_url: http://api.giphy.com/v1/gifs/random?api_key=dc6zaTOxFJmzC development: <<: *default diff --git a/app/controllers/api/v1/messages_controller.rb b/messages_controller.bak similarity index 100% rename from app/controllers/api/v1/messages_controller.rb rename to messages_controller.bak From df2698fd9986e2d5c7bf22ebe869067a2c009f01 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Sun, 2 Apr 2017 02:58:11 +0300 Subject: [PATCH 067/110] Add Gitlab and Bugsnag controller --- .../messages_controller_BACKUP_3454.rb | 42 ------------------- .../rollbar/messages_controller_BASE_3454.rb | 35 ---------------- .../rollbar/messages_controller_LOCAL_3454.rb | 37 ---------------- .../messages_controller_REMOTE_3454.rb | 37 ---------------- config/service.yml | 3 -- 5 files changed, 154 deletions(-) delete mode 100644 app/controllers/api/rollbar/messages_controller_BACKUP_3454.rb delete mode 100644 app/controllers/api/rollbar/messages_controller_BASE_3454.rb delete mode 100644 app/controllers/api/rollbar/messages_controller_LOCAL_3454.rb delete mode 100644 app/controllers/api/rollbar/messages_controller_REMOTE_3454.rb diff --git a/app/controllers/api/rollbar/messages_controller_BACKUP_3454.rb b/app/controllers/api/rollbar/messages_controller_BACKUP_3454.rb deleted file mode 100644 index 5262c33..0000000 --- a/app/controllers/api/rollbar/messages_controller_BACKUP_3454.rb +++ /dev/null @@ -1,42 +0,0 @@ -class Api::Rollbar::MessagesController < ApplicationController - skip_before_action :verify_authenticity_token - - def create - # Get the parsed JSON string - rollbar_parsed = helpers.parse_webhook - - # error: JSON:ParserError - # Get the failed JSON request message - request_error = rollbar_parsed[:error] - - # Prepare message for the campfire - message = if request_error - "Failed or 'non JSON' request: #{request_error}" - else - build_message_text rollbar_parsed - end - - # send message to basecamp - helpers.send_message(message) - end - - private - - def build_message_text(rollbar_parsed) - # Store parsed dada from Rollbar - event = rollbar_parsed['event_name'] - data = rollbar_parsed['data']['item']['title'] - uuid = rollbar_parsed['data']['occurrence']['uuid'] - event_url = "https://rollbar.com/instance/uuid?uuid=#{uuid}" - return "Event: #{event}
- Body: #{data}
- Rollbar report: #{event_url}" -<<<<<<< HEAD - rescue NoMethodError => error - return "Error parsing Rollbar issue: #{error}" -======= - rescue NoMethodError => error # remove exception handlidg to see errors in the Dev. console - return "Rollbar parsing error: #{error}" ->>>>>>> bugsnag - end -end diff --git a/app/controllers/api/rollbar/messages_controller_BASE_3454.rb b/app/controllers/api/rollbar/messages_controller_BASE_3454.rb deleted file mode 100644 index 7c26591..0000000 --- a/app/controllers/api/rollbar/messages_controller_BASE_3454.rb +++ /dev/null @@ -1,35 +0,0 @@ -class Api::Rollbar::MessagesController < ApplicationController - skip_before_action :verify_authenticity_token - - def create - # Get the parsed JSON string - @payload = helpers.parse_webhook - - # error: JSON:ParserError - # Get the failed JSON request message - request_error = @payload[:error] - - # Prepare message for the campfire - message = if request_error - "Failed request: #{request_error}" - else - build_message - end - - # send message to basecamp - helpers.send_message(message) - end - - private - - def build_message - # Store parsed dada from Rollbar - event = @payload['event_name'] - data = @payload['data']['item']['title'] - uuid = @payload['data']['occurrence']['uuid'] - event_url = "https://rollbar.com/instance/uuid?uuid=#{uuid}" - message = "Event: #{event}
- Body: #{data}
- Rollbar report: #{event_url}" - end -end diff --git a/app/controllers/api/rollbar/messages_controller_LOCAL_3454.rb b/app/controllers/api/rollbar/messages_controller_LOCAL_3454.rb deleted file mode 100644 index 20b04ff..0000000 --- a/app/controllers/api/rollbar/messages_controller_LOCAL_3454.rb +++ /dev/null @@ -1,37 +0,0 @@ -class Api::Rollbar::MessagesController < ApplicationController - skip_before_action :verify_authenticity_token - - def create - # Get the parsed JSON string - @payload = helpers.parse_webhook - - # error: JSON:ParserError - # Get the failed JSON request message - request_error = @payload[:error] - - # Prepare message for the campfire - message = if request_error - "Failed request: #{request_error}" - else - build_message - end - - # send message to basecamp - helpers.send_message(message) - end - - private - - def build_message - # Store parsed dada from Rollbar - event = @payload['event_name'] - data = @payload['data']['item']['title'] - uuid = @payload['data']['occurrence']['uuid'] - event_url = "https://rollbar.com/instance/uuid?uuid=#{uuid}" - return "Event: #{event}
- Body: #{data}
- Rollbar report: #{event_url}" - rescue NoMethodError => error - return "Error parsing Rollbar issue: #{error}" - end -end diff --git a/app/controllers/api/rollbar/messages_controller_REMOTE_3454.rb b/app/controllers/api/rollbar/messages_controller_REMOTE_3454.rb deleted file mode 100644 index 61b181a..0000000 --- a/app/controllers/api/rollbar/messages_controller_REMOTE_3454.rb +++ /dev/null @@ -1,37 +0,0 @@ -class Api::Rollbar::MessagesController < ApplicationController - skip_before_action :verify_authenticity_token - - def create - # Get the parsed JSON string - rollbar_parsed = helpers.parse_webhook - - # error: JSON:ParserError - # Get the failed JSON request message - request_error = rollbar_parsed[:error] - - # Prepare message for the campfire - message = if request_error - "Failed or 'non JSON' request: #{request_error}" - else - build_message_text rollbar_parsed - end - - # send message to basecamp - helpers.send_message(message) - end - - private - - def build_message_text(rollbar_parsed) - # Store parsed dada from Rollbar - event = rollbar_parsed['event_name'] - data = rollbar_parsed['data']['item']['title'] - uuid = rollbar_parsed['data']['occurrence']['uuid'] - event_url = "https://rollbar.com/instance/uuid?uuid=#{uuid}" - return "Event: #{event}
- Body: #{data}
- Rollbar report: #{event_url}" - rescue NoMethodError => error # remove exception handlidg to see errors in the Dev. console - return "Rollbar parsing error: #{error}" - end -end diff --git a/config/service.yml b/config/service.yml index abc80d8..6d43540 100644 --- a/config/service.yml +++ b/config/service.yml @@ -1,15 +1,12 @@ # Add this file to .gitignore right now !!! default: &default basecampbot_url: https://3.basecamp.com/3700178/integrations/3gtJyBKVQHvrQN2h7FitRJSK/buckets/3097353/chats/437772399/lines -<<<<<<< HEAD snstopic_arn: arn:aws:sns:eu-central-1:798348585423:basecamp-bot -======= snstopic_arn: arn:aws:sns:us-west-2:230306836787:magick_kick # Path to the .json file that contain contains 'aws_access_key' and 'aws_secret_key' aws_secret_file: /home/klim/secrets.json # Giphy API url + public API key giphy_url: http://api.giphy.com/v1/gifs/random?api_key=dc6zaTOxFJmzC ->>>>>>> bugsnag development: <<: *default From f750b1c218fb539d2556057cef577f647e8b6ffe Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Sun, 2 Apr 2017 16:12:48 +0300 Subject: [PATCH 068/110] Fix Giphy controller --- app/controllers/api/giphy/messages_controller.rb | 5 ++--- app/controllers/api/rollbar/messages_controller.rb | 2 +- app/controllers/api/sns/messages_controller.rb | 2 +- config/service.yml | 1 - 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/giphy/messages_controller.rb b/app/controllers/api/giphy/messages_controller.rb index ae975fd..66e1ba5 100644 --- a/app/controllers/api/giphy/messages_controller.rb +++ b/app/controllers/api/giphy/messages_controller.rb @@ -4,9 +4,9 @@ class Api::Giphy::MessagesController < ApplicationController def create giphy_url = Rails.configuration.service['giphy_url'] giphy_parsed = JSON.parse HTTParty.get(giphy_url).body - giphy_response_status = giphy_parsed['meta']['status'] + giphy_response_status = giphy_parsed['meta']['msg'] - if giphy_response_status == 200 + if giphy_response_status == 'OK' message = giphy_parsed['data']['fixed_width_downsampled_url'] else message = "There's a problem with Gliphy API: response status = #{giphy_response_status}" @@ -14,6 +14,5 @@ def create # send message to basecamp helpers.send_message(message) - end end diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index e39a85a..61b181a 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -34,4 +34,4 @@ def build_message_text(rollbar_parsed) rescue NoMethodError => error # remove exception handlidg to see errors in the Dev. console return "Rollbar parsing error: #{error}" end -end \ No newline at end of file +end diff --git a/app/controllers/api/sns/messages_controller.rb b/app/controllers/api/sns/messages_controller.rb index a74821f..990729d 100644 --- a/app/controllers/api/sns/messages_controller.rb +++ b/app/controllers/api/sns/messages_controller.rb @@ -30,4 +30,4 @@ def build_message_text(amazon_sns_request) rescue NoMethodError => error # remove exception handlidg to see errors in the Dev. console return "Amazon SNS parsing error: #{error}" end -end \ No newline at end of file +end diff --git a/config/service.yml b/config/service.yml index 6d43540..01c58d9 100644 --- a/config/service.yml +++ b/config/service.yml @@ -1,7 +1,6 @@ # Add this file to .gitignore right now !!! default: &default basecampbot_url: https://3.basecamp.com/3700178/integrations/3gtJyBKVQHvrQN2h7FitRJSK/buckets/3097353/chats/437772399/lines - snstopic_arn: arn:aws:sns:eu-central-1:798348585423:basecamp-bot snstopic_arn: arn:aws:sns:us-west-2:230306836787:magick_kick # Path to the .json file that contain contains 'aws_access_key' and 'aws_secret_key' aws_secret_file: /home/klim/secrets.json From 2f386a9e2562b351775ea9fea2d60a5399090448 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Sun, 2 Apr 2017 19:57:16 +0300 Subject: [PATCH 069/110] Add instructions to README --- .gitignore | 1 - README.md | 41 +++++++++++++++---- .../api/sns/messages_controller.rb | 2 +- config/service.yml | 8 ++-- 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index e6aec53..b759a63 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,6 @@ /.idea /config/database.yml /config/secrets.yml -/config/service.yml # Ignore the default SQLite database. /db/*.sqlite3 diff --git a/README.md b/README.md index c4f7728..083f2fa 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,19 @@ Rails application to transfer messages to your basecamp3 HQ. ### Supported services 1. [AWS SNS](https://aws.amazon.com/sns/) -1. [Rollbar](https://rollbar.com) +2. [Bugsnag](https://www.bugsnag.com/) +3. [GitLab](https://gitlab.com) +4. [Rollbar](https://rollbar.com) +5. [Giphy](https://giphy.com) ### Instruction * [Create a Chatbot](#create-chatbot ) * [AWS integration](#aws-integration) +* [Bugsnag integration](#bugsnag-integration) +* [Gitlab integration](#gitlab-integration) * [Rollbar integration](#rollbar-integration) +* [Giphy integration](#giphy-integration) * [References](#references) #### Create a Chatbot @@ -37,18 +43,39 @@ you need a bot long link. Like this: 1. Register AWS and [create SNS topic](http://docs.aws.amazon.com/sns/latest/dg/CreateTopic.html). Remember Topic ARN! It looks like this: `arn:aws:sns:us-east-6:23730808936387:topick_name` 2. Add your SNS __Topic ARN__ to `/config/service.yml` -3. Start rails server by typing `rails s` command. -4. [Create subscription](http://docs.aws.amazon.com/sns/latest/dg/SubscribeTopic.html). Use HTTP **Protocol** and `http://your-external-host/api/v1/messages` as __Endpoint__ -8. At first time SNS send confirmation request. After subscription you can -[publish messages to a topic](http://docs.aws.amazon.com/sns/latest/dg/PublishTopic.html) +3. [Aws-sdk gem](https://github.com/aws/aws-sdk-ruby), which used in this App, needs 'aws_access_key' and 'aws_secret_key' to work. To find them navigate to "My Security Credentials" category in your asw.amazon account. Always load your credentials from outside your application! Look at `/config/service.yml` for example. Avoid configuring credentials statically and never commit them to source control! +4. Start rails server by typing `rails s` command. +5. [Create subscription](http://docs.aws.amazon.com/sns/latest/dg/SubscribeTopic.html). Use HTTP **Protocol** and `http://your-external-host/api/sns/messages` as __Endpoint__ +6. At first time SNS send confirmation request which will be automatically accepted. After subscription you can [publish messages to the topic](http://docs.aws.amazon.com/sns/latest/dg/PublishTopic.html) + +#### Bugsnag integration + +1. Create [Bugsnag account](https://www.bugsnag.com/) and create new project. +2. Navigate to 'Integrations' menu. +3. Select the 'Webhook', enter the full URL where webhooks should be posted (http://your-external-host/api/bugsnag/messages`), choice notification events and enable the integration. +4. For more instructions, please visit [Bugsnag docs](https://docs.bugsnag.com/api/) and [Ruby on Rails integration](https://docs.bugsnag.com/platforms/ruby/rails/) + +#### Gitlab integration + +1. Create [Gitlab account](https://gitlab.com) and start the New project. +2. Navigate to the project's 'Settings/Integrations' menu. +3. Select the 'Webhook', enter the full URL where webhooks should be posted (http://your-external-host/api/gitlab/messages`). Mark event checkboxes and click the 'Add Webhook' button. +4. For more instructions, please visit [GitLab Webhooks docs](https://gitlab.com/help/user/project/integrations/webhooks). #### Rollbar integration 1. Create [Rollbar account](https://rollbar.com) and start the New project. 2. Navigate to the project, click 'Settings', then click 'Notifications' in the left menu. 3. Select the 'Webhook', enter the full URL where webhooks should be posted (this App server) and enable the integration. -4. Once set up, you can add, edit, or remove rules. For more instruction, please visit [Rollbar docs](https://rollbar.com/docs/webhooks) and [Ruby Integration](https://rollbar.com/docs/notifier/rollbar-gem) +4. Once set up, you can add, edit, or remove rules. For more instructions, please visit [Rollbar docs](https://rollbar.com/docs/webhooks) and [Ruby Integration](https://rollbar.com/docs/notifier/rollbar-gem) + +#### Giphy integration + +1. Add Gipy API 'search query' to `/config/service.yml`. Look at `/config/service.yml` for example. +2. If you'll send some POST request to `http://your-external-host/api/giphy/messages` Chatbot will post to your Basecamp chat a random funny gif from [Giphy](http://giphy.com/). +3. Just for fun! #### References -* Most controller logic based on [Creating SNS subscription endpoints with Ruby on Rails](http://blog.eng.xogrp.com/post/79166302844/creating-sns-subscription-endpoints-with-ruby-on#disqus_thread) \ No newline at end of file +* AWS-SDK [documentation](http://docs.aws.amazon.com/sdkforruby/api/Aws/SNS/Client.html) +* Giphy [Api docs](https://github.com/Giphy/GiphyAPI) \ No newline at end of file diff --git a/app/controllers/api/sns/messages_controller.rb b/app/controllers/api/sns/messages_controller.rb index 990729d..c32d622 100644 --- a/app/controllers/api/sns/messages_controller.rb +++ b/app/controllers/api/sns/messages_controller.rb @@ -12,7 +12,7 @@ def create token: amazon_sns_request['Token'], }) elsif amazon_sns_request['Type'].to_s.downcase == "notification" - message = build_message_text(amazon_sns_request) + message = build_message_text amazon_sns_request end # send message to basecamp diff --git a/config/service.yml b/config/service.yml index 01c58d9..75a5e4e 100644 --- a/config/service.yml +++ b/config/service.yml @@ -1,9 +1,9 @@ # Add this file to .gitignore right now !!! default: &default - basecampbot_url: https://3.basecamp.com/3700178/integrations/3gtJyBKVQHvrQN2h7FitRJSK/buckets/3097353/chats/437772399/lines - snstopic_arn: arn:aws:sns:us-west-2:230306836787:magick_kick - # Path to the .json file that contain contains 'aws_access_key' and 'aws_secret_key' - aws_secret_file: /home/klim/secrets.json + basecampbot_url: https://3.basecamp.com/3999996/integrations/8gtJyBKVQHvrQN2h4FitRJSK/buckets/3797353/chats/434442399/lines + snstopic_arn: arn:aws:sns:us-west-5:670306886787:magick_kick + # Path to the .json file that contains 'aws_access_key' and 'aws_secret_key' + aws_secret_file: /home/user/secrets.json # Giphy API url + public API key giphy_url: http://api.giphy.com/v1/gifs/random?api_key=dc6zaTOxFJmzC From c1ed872d26c26b3e58bf3e9bbec8605e0222728f Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Sun, 2 Apr 2017 20:58:21 +0300 Subject: [PATCH 070/110] Fixed amazon config --- app/controllers/api/sns/messages_controller.rb | 13 +++++-------- app/helpers/application_helper.rb | 12 ++++-------- config/routes.rb | 2 +- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/app/controllers/api/sns/messages_controller.rb b/app/controllers/api/sns/messages_controller.rb index c32d622..cbad552 100644 --- a/app/controllers/api/sns/messages_controller.rb +++ b/app/controllers/api/sns/messages_controller.rb @@ -6,12 +6,9 @@ def create snstopic_arn = Rails.configuration.service['snstopic_arn'] client = helpers.aws_config - if amazon_sns_request['Type'].to_s.downcase == "subscriptionconfirmation" - resp = client.confirm_subscription({ - topic_arn: snstopic_arn, - token: amazon_sns_request['Token'], - }) - elsif amazon_sns_request['Type'].to_s.downcase == "notification" + if amazon_sns_request['Type'].to_s.casecmp('SubscriptionConfirmation') >= 0 + client.confirm_subscription( topic_arn: snstopic_arn, token: amazon_sns_request['Token']) + elsif amazon_sns_request['Type'].to_s.casecmp('Notification') >= 0 message = build_message_text amazon_sns_request end @@ -27,7 +24,7 @@ def build_message_text(amazon_sns_request) body = amazon_sns_request['Message'] return "Subject: #{subject}
Body: #{body}
" - rescue NoMethodError => error # remove exception handlidg to see errors in the Dev. console - return "Amazon SNS parsing error: #{error}" + rescue NoMethodError => e # del. exception handlidg to see errors in console + return "Amazon SNS parsing error: #{e}" end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 10ab4fe..4cf05b7 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,16 +1,12 @@ module ApplicationHelper def aws_config - snstopic_arn = Rails.configuration.service['snstopic_arn'] aws_secret_file = Rails.configuration.service['aws_secret_file'] - creds = JSON.load(File.read aws_secret_file) + creds = JSON.parse(File.read(aws_secret_file)) + aws_creds = Aws::Credentials.new(creds['aws_access_key'], creds['aws_secret_key']) # Configure and create an AWS_SNS client - Aws.config.update({ - region: creds['aws_region'], - credentials: Aws::Credentials.new(creds['aws_access_key'], creds['aws_secret_key']) - }) - - client = Aws::SNS::Client.new + Aws.config.update(region: creds['aws_region'], credentials: aws_creds) + return Aws::SNS::Client.new end def parse_webhook diff --git a/config/routes.rb b/config/routes.rb index 2f488da..7987c97 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -22,4 +22,4 @@ resources :messages, only: :create end end -end \ No newline at end of file +end From d12ba753f4c89f3ee2d253584beb73af02f5bf85 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Sun, 2 Apr 2017 21:18:05 +0300 Subject: [PATCH 071/110] Fixed Giphy controller style --- app/controllers/api/giphy/messages_controller.rb | 7 ++++--- app/controllers/api/gitlab/messages_controller.rb | 6 +++--- app/controllers/api/rollbar/messages_controller.rb | 6 +++--- app/controllers/api/sns/messages_controller.rb | 7 +++++-- app/helpers/application_helper.rb | 5 +++-- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/app/controllers/api/giphy/messages_controller.rb b/app/controllers/api/giphy/messages_controller.rb index 66e1ba5..b9df6c3 100644 --- a/app/controllers/api/giphy/messages_controller.rb +++ b/app/controllers/api/giphy/messages_controller.rb @@ -5,11 +5,12 @@ def create giphy_url = Rails.configuration.service['giphy_url'] giphy_parsed = JSON.parse HTTParty.get(giphy_url).body giphy_response_status = giphy_parsed['meta']['msg'] - + if giphy_response_status == 'OK' - message = giphy_parsed['data']['fixed_width_downsampled_url'] + message = giphy_parsed['data']['fixed_width_downsampled_url'] else - message = "There's a problem with Gliphy API: response status = #{giphy_response_status}" + message = "There's a problem with Gliphy API: + response status = #{giphy_response_status}" end # send message to basecamp diff --git a/app/controllers/api/gitlab/messages_controller.rb b/app/controllers/api/gitlab/messages_controller.rb index 6648159..ccaea14 100644 --- a/app/controllers/api/gitlab/messages_controller.rb +++ b/app/controllers/api/gitlab/messages_controller.rb @@ -11,7 +11,7 @@ def create # Prepare message for the campfire message = if request_error - "Failed or 'non JSON' request: #{request_error}" + "Failed or 'non JSON' request:#{request_error}" else build_message_text gitlab_parsed end @@ -30,7 +30,7 @@ def build_message_text(gitlab_parsed) return "Gitlab project: #{project_name}
Event: #{event}
Project url: #{project_url}" - rescue NoMethodError => error # remove exception handlidg to see errors in the Dev. console - return "GitLab parsing error: #{error}" + rescue NoMethodError => e # del. exception handlidg to see errors in console + return "GitLab parsing error: #{e}" end end diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index 61b181a..651bc1c 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -11,7 +11,7 @@ def create # Prepare message for the campfire message = if request_error - "Failed or 'non JSON' request: #{request_error}" + "Failed or 'non JSON' request: #{request_error}" else build_message_text rollbar_parsed end @@ -31,7 +31,7 @@ def build_message_text(rollbar_parsed) return "Event: #{event}
Body: #{data}
Rollbar report: #{event_url}" - rescue NoMethodError => error # remove exception handlidg to see errors in the Dev. console - return "Rollbar parsing error: #{error}" + rescue NoMethodError => e # del. exception handlidg to see errors in console + return "Rollbar parsing error: #{e}" end end diff --git a/app/controllers/api/sns/messages_controller.rb b/app/controllers/api/sns/messages_controller.rb index cbad552..3defb3d 100644 --- a/app/controllers/api/sns/messages_controller.rb +++ b/app/controllers/api/sns/messages_controller.rb @@ -5,9 +5,12 @@ def create amazon_sns_request = helpers.parse_webhook snstopic_arn = Rails.configuration.service['snstopic_arn'] client = helpers.aws_config - + if amazon_sns_request['Type'].to_s.casecmp('SubscriptionConfirmation') >= 0 - client.confirm_subscription( topic_arn: snstopic_arn, token: amazon_sns_request['Token']) + client.confirm_subscription( + topic_arn: snstopic_arn, + token: amazon_sns_request['Token'] + ) elsif amazon_sns_request['Type'].to_s.casecmp('Notification') >= 0 message = build_message_text amazon_sns_request end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4cf05b7..92eb930 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2,11 +2,12 @@ module ApplicationHelper def aws_config aws_secret_file = Rails.configuration.service['aws_secret_file'] creds = JSON.parse(File.read(aws_secret_file)) - aws_creds = Aws::Credentials.new(creds['aws_access_key'], creds['aws_secret_key']) + aws_creds = Aws::Credentials.new(creds['aws_access_key'], + creds['aws_secret_key']) # Configure and create an AWS_SNS client Aws.config.update(region: creds['aws_region'], credentials: aws_creds) - return Aws::SNS::Client.new + Aws::SNS::Client.new end def parse_webhook From bac4ce8a0f1cdf6fe3ede1adc943b5f3362bde6d Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Sun, 2 Apr 2017 21:50:20 +0300 Subject: [PATCH 072/110] Fixed Amazon controller --- app/controllers/api/bugsnag/messages_controller.rb | 6 +++--- app/controllers/api/giphy/messages_controller.rb | 4 ++-- app/controllers/api/gitlab/messages_controller.rb | 2 +- app/controllers/api/rollbar/messages_controller.rb | 2 +- app/controllers/api/sns/messages_controller.rb | 8 ++++---- app/helpers/application_helper.rb | 6 ++++-- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/app/controllers/api/bugsnag/messages_controller.rb b/app/controllers/api/bugsnag/messages_controller.rb index 8e8d47c..eb63afd 100644 --- a/app/controllers/api/bugsnag/messages_controller.rb +++ b/app/controllers/api/bugsnag/messages_controller.rb @@ -11,7 +11,7 @@ def create # Prepare message for the campfire message = if request_error - "Failed or 'non JSON' request: #{request_error}" + "Failed or non-JSON request: #{request_error}" else build_message_text bugsnag_parsed end @@ -30,7 +30,7 @@ def build_message_text(bugsnag_parsed) return "Event: #{event}
Message: #{error_message}
Bugsnag report: #{event_url}" - rescue NoMethodError => error # remove exception handlidg to see errors in the Dev. console - return "Bugsnag parsing error: #{error}" + rescue NoMethodError => e # del. exception handlidg to see errors in console + return "Rollbar parsing error: #{e}" end end diff --git a/app/controllers/api/giphy/messages_controller.rb b/app/controllers/api/giphy/messages_controller.rb index b9df6c3..e6b7df9 100644 --- a/app/controllers/api/giphy/messages_controller.rb +++ b/app/controllers/api/giphy/messages_controller.rb @@ -9,8 +9,8 @@ def create if giphy_response_status == 'OK' message = giphy_parsed['data']['fixed_width_downsampled_url'] else - message = "There's a problem with Gliphy API: - response status = #{giphy_response_status}" + message = "There's a problem with Gliphy API: + response status = #{giphy_response_status}" end # send message to basecamp diff --git a/app/controllers/api/gitlab/messages_controller.rb b/app/controllers/api/gitlab/messages_controller.rb index ccaea14..bdf001c 100644 --- a/app/controllers/api/gitlab/messages_controller.rb +++ b/app/controllers/api/gitlab/messages_controller.rb @@ -11,7 +11,7 @@ def create # Prepare message for the campfire message = if request_error - "Failed or 'non JSON' request:#{request_error}" + "Failed or non-JSON request:#{request_error}" else build_message_text gitlab_parsed end diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index 651bc1c..0f39cfb 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -11,7 +11,7 @@ def create # Prepare message for the campfire message = if request_error - "Failed or 'non JSON' request: #{request_error}" + "Failed or non-JSON request: #{request_error}" else build_message_text rollbar_parsed end diff --git a/app/controllers/api/sns/messages_controller.rb b/app/controllers/api/sns/messages_controller.rb index 3defb3d..f692374 100644 --- a/app/controllers/api/sns/messages_controller.rb +++ b/app/controllers/api/sns/messages_controller.rb @@ -7,10 +7,10 @@ def create client = helpers.aws_config if amazon_sns_request['Type'].to_s.casecmp('SubscriptionConfirmation') >= 0 - client.confirm_subscription( - topic_arn: snstopic_arn, - token: amazon_sns_request['Token'] - ) + client.confirm_subscription( + topic_arn: snstopic_arn, + token: amazon_sns_request['Token'] + ) elsif amazon_sns_request['Type'].to_s.casecmp('Notification') >= 0 message = build_message_text amazon_sns_request end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 92eb930..62eda43 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2,8 +2,10 @@ module ApplicationHelper def aws_config aws_secret_file = Rails.configuration.service['aws_secret_file'] creds = JSON.parse(File.read(aws_secret_file)) - aws_creds = Aws::Credentials.new(creds['aws_access_key'], - creds['aws_secret_key']) + aws_creds = Aws::Credentials.new( + creds['aws_access_key'], + creds['aws_secret_key'] + ) # Configure and create an AWS_SNS client Aws.config.update(region: creds['aws_region'], credentials: aws_creds) From 808b062e7d05baca47ee9e560e6f788af527ecbf Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Sun, 2 Apr 2017 21:53:52 +0300 Subject: [PATCH 073/110] Fixed Amazon controller --- app/helpers/application_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 62eda43..fa46352 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -3,8 +3,8 @@ def aws_config aws_secret_file = Rails.configuration.service['aws_secret_file'] creds = JSON.parse(File.read(aws_secret_file)) aws_creds = Aws::Credentials.new( - creds['aws_access_key'], - creds['aws_secret_key'] + creds['aws_access_key'], + creds['aws_secret_key'] ) # Configure and create an AWS_SNS client From 9d0d7a2f08881bf0ddaa53e1e601cf8bfe3e3334 Mon Sep 17 00:00:00 2001 From: Kirill Shirinkin Date: Mon, 3 Apr 2017 09:03:42 +0200 Subject: [PATCH 074/110] remove sqlite --- Gemfile | 2 -- config/service.yml | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 83015ea..27b015a 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,6 @@ source 'https://rubygems.org' ruby '2.3.1' gem 'rails', '~> 5.0.0', '>= 5.0.0.1' -gem 'sqlite3' # Use Puma as the app server gem 'puma', '~> 3.0' @@ -13,7 +12,6 @@ gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.2' gem 'aws-sdk', '~> 2' - group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platform: :mri diff --git a/config/service.yml b/config/service.yml index 75a5e4e..223154c 100644 --- a/config/service.yml +++ b/config/service.yml @@ -14,4 +14,5 @@ test: <<: *default production: - <<: *default \ No newline at end of file + basecampbot_url: <%= ENV["BASECAMPBOT_URL"] %> + giphy_url: <%= ENV["GIPHY_URL"] %> From 67d103f6a3d0cf584ce7bad3c352795e4f92079a Mon Sep 17 00:00:00 2001 From: Kirill Shirinkin Date: Mon, 3 Apr 2017 09:05:22 +0200 Subject: [PATCH 075/110] Minor refactorings and better Giphy implementation --- .gitignore | 1 - Gemfile | 1 + Gemfile.lock | 23 +++++++++++++++++-- app/assets/javascripts/application.js | 3 --- .../api/giphy/messages_controller.rb | 15 ++---------- app/controllers/application_controller.rb | 6 +++++ app/mailers/application_mailer.rb | 4 ---- app/models/application_record.rb | 3 --- app/models/concerns/.keep | 0 config/initializers/giphy.rb | 3 +++ config/secrets.yml | 2 ++ config/service.yml | 4 ++-- 12 files changed, 37 insertions(+), 28 deletions(-) delete mode 100644 app/mailers/application_mailer.rb delete mode 100644 app/models/application_record.rb delete mode 100644 app/models/concerns/.keep create mode 100644 config/initializers/giphy.rb create mode 100644 config/secrets.yml diff --git a/.gitignore b/.gitignore index b759a63..5a8e585 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,6 @@ /.bundle /.idea /config/database.yml -/config/secrets.yml # Ignore the default SQLite database. /db/*.sqlite3 diff --git a/Gemfile b/Gemfile index 27b015a..771107f 100644 --- a/Gemfile +++ b/Gemfile @@ -11,6 +11,7 @@ gem 'sass-rails', '~> 5.0' gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.2' gem 'aws-sdk', '~> 2' +gem 'giphy' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console diff --git a/Gemfile.lock b/Gemfile.lock index 86d1cc6..393aeea 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -38,6 +38,8 @@ GEM i18n (~> 0.7) minitest (~> 5.1) tzinfo (~> 1.1) + addressable (2.5.1) + public_suffix (~> 2.0, >= 2.0.2) arel (7.1.4) aws-sdk (2.9.0) aws-sdk-resources (= 2.9.0) @@ -60,13 +62,28 @@ GEM debug_inspector (0.0.2) erubis (2.7.0) execjs (2.7.0) + faraday (0.12.0.1) + multipart-post (>= 1.2, < 3) + faraday_middleware (0.11.0.1) + faraday (>= 0.7.4, < 1.0) + faraday_middleware-parse_oj (0.3.1) + faraday (~> 0.9) + faraday_middleware (>= 0.9.1, < 1.0) + oj (~> 2.0) ffi (1.9.18) + giphy (3.0.0) + faraday (~> 0.9) + faraday_middleware (~> 0.9) + faraday_middleware-parse_oj (~> 0.3) + launchy (~> 2.4) globalid (0.3.7) activesupport (>= 4.1.0) httparty (0.14.0) multi_xml (>= 0.5.2) i18n (0.8.1) jmespath (1.3.1) + launchy (2.4.3) + addressable (~> 2.3) listen (3.0.8) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -81,9 +98,12 @@ GEM mini_portile2 (2.1.0) minitest (5.10.1) multi_xml (0.6.0) + multipart-post (2.0.0) nio4r (2.0.0) nokogiri (1.7.1) mini_portile2 (~> 2.1.0) + oj (2.18.5) + public_suffix (2.0.5) puma (3.8.2) rack (2.0.1) rack-test (0.6.3) @@ -134,7 +154,6 @@ GEM actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - sqlite3 (1.3.12) thor (0.19.4) thread_safe (0.3.6) tilt (2.0.7) @@ -158,6 +177,7 @@ DEPENDENCIES aws-sdk (~> 2) byebug coffee-rails (~> 4.2) + giphy httparty listen (~> 3.0.5) puma (~> 3.0) @@ -165,7 +185,6 @@ DEPENDENCIES sass-rails (~> 5.0) spring spring-watcher-listen (~> 2.0.0) - sqlite3 uglifier (>= 1.3.0) web-console diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index b12018d..e54c646 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -10,7 +10,4 @@ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details // about supported directives. // -//= require jquery -//= require jquery_ujs -//= require turbolinks //= require_tree . diff --git a/app/controllers/api/giphy/messages_controller.rb b/app/controllers/api/giphy/messages_controller.rb index e6b7df9..f948a7f 100644 --- a/app/controllers/api/giphy/messages_controller.rb +++ b/app/controllers/api/giphy/messages_controller.rb @@ -2,18 +2,7 @@ class Api::Giphy::MessagesController < ApplicationController skip_before_action :verify_authenticity_token def create - giphy_url = Rails.configuration.service['giphy_url'] - giphy_parsed = JSON.parse HTTParty.get(giphy_url).body - giphy_response_status = giphy_parsed['meta']['msg'] - - if giphy_response_status == 'OK' - message = giphy_parsed['data']['fixed_width_downsampled_url'] - else - message = "There's a problem with Gliphy API: - response status = #{giphy_response_status}" - end - - # send message to basecamp - helpers.send_message(message) + image = Giphy.random(command_params[:command]).image_original_url.to_s + helpers.send_message("") end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1c07694..1df6d8f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,3 +1,9 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception + + private + + def command_params + params.permit(:command) + end end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb deleted file mode 100644 index 286b223..0000000 --- a/app/mailers/application_mailer.rb +++ /dev/null @@ -1,4 +0,0 @@ -class ApplicationMailer < ActionMailer::Base - default from: 'from@example.com' - layout 'mailer' -end diff --git a/app/models/application_record.rb b/app/models/application_record.rb deleted file mode 100644 index 10a4cba..0000000 --- a/app/models/application_record.rb +++ /dev/null @@ -1,3 +0,0 @@ -class ApplicationRecord < ActiveRecord::Base - self.abstract_class = true -end diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/config/initializers/giphy.rb b/config/initializers/giphy.rb new file mode 100644 index 0000000..428500c --- /dev/null +++ b/config/initializers/giphy.rb @@ -0,0 +1,3 @@ +Giphy::Configuration.configure do |config| + config.api_key = Rails.configuration.service['giphy_api_key'] +end diff --git a/config/secrets.yml b/config/secrets.yml new file mode 100644 index 0000000..81b55d5 --- /dev/null +++ b/config/secrets.yml @@ -0,0 +1,2 @@ +production: + secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> diff --git a/config/service.yml b/config/service.yml index 223154c..beb858b 100644 --- a/config/service.yml +++ b/config/service.yml @@ -5,7 +5,7 @@ default: &default # Path to the .json file that contains 'aws_access_key' and 'aws_secret_key' aws_secret_file: /home/user/secrets.json # Giphy API url + public API key - giphy_url: http://api.giphy.com/v1/gifs/random?api_key=dc6zaTOxFJmzC + giphy_api_key: "dc6zaTOxFJmzC" development: <<: *default @@ -15,4 +15,4 @@ test: production: basecampbot_url: <%= ENV["BASECAMPBOT_URL"] %> - giphy_url: <%= ENV["GIPHY_URL"] %> + giphy_api_key: <%= ENV["GIPHY_API_KEY"] %> From 5b3271600565cf4fc29a14f43c382be5350c8a4d Mon Sep 17 00:00:00 2001 From: Kirill Shirinkin Date: Mon, 3 Apr 2017 09:38:42 +0200 Subject: [PATCH 076/110] Send gifs back to requester bot --- app/controllers/api/giphy/messages_controller.rb | 2 +- app/controllers/application_controller.rb | 2 +- app/helpers/application_helper.rb | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/giphy/messages_controller.rb b/app/controllers/api/giphy/messages_controller.rb index f948a7f..ad32f73 100644 --- a/app/controllers/api/giphy/messages_controller.rb +++ b/app/controllers/api/giphy/messages_controller.rb @@ -3,6 +3,6 @@ class Api::Giphy::MessagesController < ApplicationController def create image = Giphy.random(command_params[:command]).image_original_url.to_s - helpers.send_message("") + helpers.send_message(command_params[:callback_url], "") end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1df6d8f..6eacdbf 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,6 +4,6 @@ class ApplicationController < ActionController::Base private def command_params - params.permit(:command) + params.permit(:command, :callback_url) end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index fa46352..9e79f65 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -20,9 +20,8 @@ def parse_webhook return { error: error.to_s } end - def send_message(message) - # Send message to Basecamp Campfire via ChatBot - basecampbot_url = Rails.configuration.service['basecampbot_url'] + def send_message(basecampbot_url, message) + basecampbot_url ||= Rails.configuration.service['basecampbot_url'] HTTParty.post basecampbot_url, query: { content: message } end end From 49fab5ad4b7be8b01b1ab31f27f2fa7eaaac352f Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Wed, 5 Apr 2017 14:26:48 +0300 Subject: [PATCH 077/110] Fix Aws controller. Moved Aws config to /initializers. Changed helpers.send_message --- .gitignore | 1 + .../api/bugsnag/messages_controller.rb | 4 +- .../api/gitlab/messages_controller.rb | 2 +- .../api/rollbar/messages_controller.rb | 2 +- .../api/sns/messages_controller.rb | 2 +- app/helpers/application_helper.rb | 9 ---- config/initializers/aws_sdk.rb | 8 ++++ config/secrets.yml | 10 +++- config/service.yml | 12 +++-- messages_controller.bak | 46 ------------------- 10 files changed, 30 insertions(+), 66 deletions(-) create mode 100644 config/initializers/aws_sdk.rb delete mode 100644 messages_controller.bak diff --git a/.gitignore b/.gitignore index 5a8e585..44d13f3 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ /.bundle /.idea /config/database.yml +/config/service.yml # Ignore the default SQLite database. /db/*.sqlite3 diff --git a/app/controllers/api/bugsnag/messages_controller.rb b/app/controllers/api/bugsnag/messages_controller.rb index eb63afd..714b3c5 100644 --- a/app/controllers/api/bugsnag/messages_controller.rb +++ b/app/controllers/api/bugsnag/messages_controller.rb @@ -17,7 +17,7 @@ def create end # send message to basecamp - helpers.send_message(message) + helpers.send_message(command_params[:callback_url], message) end private @@ -31,6 +31,6 @@ def build_message_text(bugsnag_parsed) Message: #{error_message}
Bugsnag report: #{event_url}" rescue NoMethodError => e # del. exception handlidg to see errors in console - return "Rollbar parsing error: #{e}" + return "Bugsnag parsing error: #{e}" end end diff --git a/app/controllers/api/gitlab/messages_controller.rb b/app/controllers/api/gitlab/messages_controller.rb index bdf001c..b17f8d9 100644 --- a/app/controllers/api/gitlab/messages_controller.rb +++ b/app/controllers/api/gitlab/messages_controller.rb @@ -17,7 +17,7 @@ def create end # send message to basecamp - helpers.send_message(message) + helpers.send_message(command_params[:callback_url], message) end private diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index 0f39cfb..6cc92fb 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -17,7 +17,7 @@ def create end # send message to basecamp - helpers.send_message(message) + helpers.send_message(command_params[:callback_url], message) end private diff --git a/app/controllers/api/sns/messages_controller.rb b/app/controllers/api/sns/messages_controller.rb index f692374..9ceb23a 100644 --- a/app/controllers/api/sns/messages_controller.rb +++ b/app/controllers/api/sns/messages_controller.rb @@ -16,7 +16,7 @@ def create end # send message to basecamp - helpers.send_message(message) + helpers.send_message(command_params[:callback_url], message) end private diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 9e79f65..ed59fc9 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,14 +1,5 @@ module ApplicationHelper def aws_config - aws_secret_file = Rails.configuration.service['aws_secret_file'] - creds = JSON.parse(File.read(aws_secret_file)) - aws_creds = Aws::Credentials.new( - creds['aws_access_key'], - creds['aws_secret_key'] - ) - - # Configure and create an AWS_SNS client - Aws.config.update(region: creds['aws_region'], credentials: aws_creds) Aws::SNS::Client.new end diff --git a/config/initializers/aws_sdk.rb b/config/initializers/aws_sdk.rb new file mode 100644 index 0000000..a83ac20 --- /dev/null +++ b/config/initializers/aws_sdk.rb @@ -0,0 +1,8 @@ +aws_secret_file = Rails.configuration.service['aws_secret_file'] +creds = YAML.load(File.read(aws_secret_file)) + aws_creds = Aws::Credentials.new( + creds['aws_access_key'], + creds['aws_secret_key'] + ) + # Configure and create an AWS_SNS client +Aws.config.update(region: creds['aws_region'], credentials: aws_creds) \ No newline at end of file diff --git a/config/secrets.yml b/config/secrets.yml index 81b55d5..e96a23b 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -1,2 +1,10 @@ +development: + secret_key_base: c32dd50710233ac4673188552d83136e8a7ee50c718b8a52158bea0e76a0afaa665d0f332b101e6c4024d7d3c2e976c4f856a5b5969b09937c7c408fad77d408 + +test: + secret_key_base: 8d42e7fede4ae5d5678250ed920ffbe92b316d73615d070609670e3ef19e72877e077df603c95d54391b2eb1f87ce8d917c6e5e376c22e94b213fa5cea408240 + +# Do not keep production secrets in the repository, +# instead read values from the environment. production: - secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> + secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> \ No newline at end of file diff --git a/config/service.yml b/config/service.yml index beb858b..3073dba 100644 --- a/config/service.yml +++ b/config/service.yml @@ -1,10 +1,10 @@ # Add this file to .gitignore right now !!! default: &default - basecampbot_url: https://3.basecamp.com/3999996/integrations/8gtJyBKVQHvrQN2h4FitRJSK/buckets/3797353/chats/434442399/lines - snstopic_arn: arn:aws:sns:us-west-5:670306886787:magick_kick - # Path to the .json file that contains 'aws_access_key' and 'aws_secret_key' - aws_secret_file: /home/user/secrets.json - # Giphy API url + public API key + basecampbot_url: https://3.basecamp.com/3700178/integrations/3gtJyBKVQHvrQN2h7FitRJSK/buckets/3097353/chats/437772399/lines + snstopic_arn: arn:aws:sns:us-west-2:230306836787:magick_kick + # Path to the .yml file that contains 'aws_access_key' and 'aws_secret_key' + aws_secret_file: /home/klim/aws.yml + # Giphy public API key giphy_api_key: "dc6zaTOxFJmzC" development: @@ -16,3 +16,5 @@ test: production: basecampbot_url: <%= ENV["BASECAMPBOT_URL"] %> giphy_api_key: <%= ENV["GIPHY_API_KEY"] %> + access_key_id: <%= ENV["AWS_ACCESS_KEY_ID"] %> + secret_access_key: <%= ENV["AWS_SECRET_KEY_ID"] %> diff --git a/messages_controller.bak b/messages_controller.bak deleted file mode 100644 index fb570d1..0000000 --- a/messages_controller.bak +++ /dev/null @@ -1,46 +0,0 @@ -require 'json' -require 'httparty' - -class Api::V1::MessagesController < ApplicationController - skip_before_action :verify_authenticity_token - - def create - basecampbot_url = Rails.configuration.service['basecampbot_url'] - snstopic_arn = Rails.configuration.service['snstopic_arn'] - - # get amazon message type and topic - amz_message_type = request.headers['x-amz-sns-message-type'] - amz_sns_topic = request.headers['x-amz-sns-topic-arn'] - - # sure you recieve messages from a right topic - return unless !amz_sns_topic.nil? && - amz_sns_topic.to_s.downcase == snstopic_arn - - request_body = JSON.parse request.body.read - - # if this is the first time confirmation of subscription, then confirm it - if amz_message_type.to_s.downcase == 'subscriptionconfirmation' - send_subscription_confirmation request_body - return - end - - if amz_message_type.to_s.downcase == 'notification' - # DO WORK HERE - message = "Subject: #{request_body['Subject']}
#{request_body['Message']}" - # send message to basecamp - HTTParty.post basecampbot_url, query: { content: message } - end - - head :ok - end - - private - - def send_subscription_confirmation(request_body) - subscribe_url = request_body['SubscribeURL'] - return nil unless !subscribe_url.to_s.empty? && !subscribe_url.nil? - subscribe_confirm = HTTParty.get subscribe_url - end - - -end From abfe42fdf239039d1ee27591ec1b0cafe76dacb7 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Wed, 5 Apr 2017 15:49:36 +0400 Subject: [PATCH 078/110] Update service.yml --- config/service.yml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/config/service.yml b/config/service.yml index 3073dba..beb858b 100644 --- a/config/service.yml +++ b/config/service.yml @@ -1,10 +1,10 @@ # Add this file to .gitignore right now !!! default: &default - basecampbot_url: https://3.basecamp.com/3700178/integrations/3gtJyBKVQHvrQN2h7FitRJSK/buckets/3097353/chats/437772399/lines - snstopic_arn: arn:aws:sns:us-west-2:230306836787:magick_kick - # Path to the .yml file that contains 'aws_access_key' and 'aws_secret_key' - aws_secret_file: /home/klim/aws.yml - # Giphy public API key + basecampbot_url: https://3.basecamp.com/3999996/integrations/8gtJyBKVQHvrQN2h4FitRJSK/buckets/3797353/chats/434442399/lines + snstopic_arn: arn:aws:sns:us-west-5:670306886787:magick_kick + # Path to the .json file that contains 'aws_access_key' and 'aws_secret_key' + aws_secret_file: /home/user/secrets.json + # Giphy API url + public API key giphy_api_key: "dc6zaTOxFJmzC" development: @@ -16,5 +16,3 @@ test: production: basecampbot_url: <%= ENV["BASECAMPBOT_URL"] %> giphy_api_key: <%= ENV["GIPHY_API_KEY"] %> - access_key_id: <%= ENV["AWS_ACCESS_KEY_ID"] %> - secret_access_key: <%= ENV["AWS_SECRET_KEY_ID"] %> From f8e0a3e30e1a8f98341f57a96982361ac8208f71 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Wed, 5 Apr 2017 15:51:16 +0400 Subject: [PATCH 079/110] Update secrets.yml --- config/secrets.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/config/secrets.yml b/config/secrets.yml index e96a23b..81b55d5 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -1,10 +1,2 @@ -development: - secret_key_base: c32dd50710233ac4673188552d83136e8a7ee50c718b8a52158bea0e76a0afaa665d0f332b101e6c4024d7d3c2e976c4f856a5b5969b09937c7c408fad77d408 - -test: - secret_key_base: 8d42e7fede4ae5d5678250ed920ffbe92b316d73615d070609670e3ef19e72877e077df603c95d54391b2eb1f87ce8d917c6e5e376c22e94b213fa5cea408240 - -# Do not keep production secrets in the repository, -# instead read values from the environment. production: - secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> \ No newline at end of file + secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> From 048c029479d1e8cf4e826e08f3e788322a8f49df Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Wed, 5 Apr 2017 15:01:17 +0300 Subject: [PATCH 080/110] Fix Aws initializer --- config/initializers/aws_sdk.rb | 13 +++++++------ config/service.yml | 12 +++++++----- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/config/initializers/aws_sdk.rb b/config/initializers/aws_sdk.rb index a83ac20..454d901 100644 --- a/config/initializers/aws_sdk.rb +++ b/config/initializers/aws_sdk.rb @@ -1,8 +1,9 @@ +# aws_secret_file - path to *.yml which contains with AWS_ACCESS_KEY_ID and AWS_SECRET_KEY_ID aws_secret_file = Rails.configuration.service['aws_secret_file'] creds = YAML.load(File.read(aws_secret_file)) - aws_creds = Aws::Credentials.new( - creds['aws_access_key'], - creds['aws_secret_key'] - ) - # Configure and create an AWS_SNS client -Aws.config.update(region: creds['aws_region'], credentials: aws_creds) \ No newline at end of file +aws_creds = Aws::Credentials.new( + creds['aws_access_key'], + creds['aws_secret_key'] +) +# Configure an AWS_SNS client +Aws.config.update(region: creds['aws_region'], credentials: aws_creds) diff --git a/config/service.yml b/config/service.yml index beb858b..1d5cb2b 100644 --- a/config/service.yml +++ b/config/service.yml @@ -1,10 +1,10 @@ # Add this file to .gitignore right now !!! default: &default - basecampbot_url: https://3.basecamp.com/3999996/integrations/8gtJyBKVQHvrQN2h4FitRJSK/buckets/3797353/chats/434442399/lines - snstopic_arn: arn:aws:sns:us-west-5:670306886787:magick_kick - # Path to the .json file that contains 'aws_access_key' and 'aws_secret_key' - aws_secret_file: /home/user/secrets.json - # Giphy API url + public API key + basecampbot_url: https://3.basecamp.com/3700178/integrations/3gtJyBKVQHvrQN2h7FitRJSK/buckets/3097353/chats/437772399/lines + snstopic_arn: arn:aws:sns:us-west-2:230306836787:magick_kick + # Path to the .yml file that contains 'aws_access_key' and 'aws_secret_key' + aws_secret_file: /home/klim/aws.yml + # Giphy public API key giphy_api_key: "dc6zaTOxFJmzC" development: @@ -16,3 +16,5 @@ test: production: basecampbot_url: <%= ENV["BASECAMPBOT_URL"] %> giphy_api_key: <%= ENV["GIPHY_API_KEY"] %> + access_key_id: <%= ENV["AWS_ACCESS_KEY_ID"] %> + secret_access_key: <%= ENV["AWS_SECRET_KEY_ID"] %> \ No newline at end of file From 93b92accda7053ac4de468b15dfcfc1dcb5985ad Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Wed, 5 Apr 2017 16:08:10 +0400 Subject: [PATCH 081/110] Update service.yml --- config/service.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/config/service.yml b/config/service.yml index 1d5cb2b..00cbed2 100644 --- a/config/service.yml +++ b/config/service.yml @@ -1,10 +1,11 @@ + # Add this file to .gitignore right now !!! default: &default - basecampbot_url: https://3.basecamp.com/3700178/integrations/3gtJyBKVQHvrQN2h7FitRJSK/buckets/3097353/chats/437772399/lines - snstopic_arn: arn:aws:sns:us-west-2:230306836787:magick_kick + basecampbot_url: https://3.basecamp.com/3999996/integrations/8gtJyBKVQHvrQN2h4FitRJSK/buckets/3797353/chats/434442399/lines + snstopic_arn: arn:aws:sns:us-west-5:670306886787:magick_kick # Path to the .yml file that contains 'aws_access_key' and 'aws_secret_key' - aws_secret_file: /home/klim/aws.yml - # Giphy public API key + aws_secret_file: /home/user/secrets.yml + # Giphy API url + public API key giphy_api_key: "dc6zaTOxFJmzC" development: @@ -15,6 +16,4 @@ test: production: basecampbot_url: <%= ENV["BASECAMPBOT_URL"] %> - giphy_api_key: <%= ENV["GIPHY_API_KEY"] %> - access_key_id: <%= ENV["AWS_ACCESS_KEY_ID"] %> - secret_access_key: <%= ENV["AWS_SECRET_KEY_ID"] %> \ No newline at end of file +giphy_api_key: <%= ENV["GIPHY_API_KEY"] %> From 952eb3c533f7794e9827ba429741eaae32c70d58 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Wed, 5 Apr 2017 15:14:17 +0300 Subject: [PATCH 082/110] Fix Aws initializer --- .gitignore | 2 ++ config/initializers/aws_sdk.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 44d13f3..2a9bae4 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,8 @@ /.idea /config/database.yml /config/service.yml +/config/secret.yml + # Ignore the default SQLite database. /db/*.sqlite3 diff --git a/config/initializers/aws_sdk.rb b/config/initializers/aws_sdk.rb index 454d901..12451a7 100644 --- a/config/initializers/aws_sdk.rb +++ b/config/initializers/aws_sdk.rb @@ -1,4 +1,4 @@ -# aws_secret_file - path to *.yml which contains with AWS_ACCESS_KEY_ID and AWS_SECRET_KEY_ID +# aws_secret_file: path to *.yml with AWS_ACCESS_KEY_ID and AWS_SECRET_KEY_ID aws_secret_file = Rails.configuration.service['aws_secret_file'] creds = YAML.load(File.read(aws_secret_file)) aws_creds = Aws::Credentials.new( From 796e41f24ff668b66b68cf5bbdf2c1fc09b5a401 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Mon, 10 Apr 2017 13:06:17 +0300 Subject: [PATCH 083/110] Amazon SNS subscription by using Instance profile --- .gitignore | 2 +- config/initializers/aws_sdk.rb | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 2a9bae4..66bb1d5 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,7 @@ /.bundle /.idea /config/database.yml -/config/service.yml +#/config/service.yml /config/secret.yml diff --git a/config/initializers/aws_sdk.rb b/config/initializers/aws_sdk.rb index 12451a7..b059c36 100644 --- a/config/initializers/aws_sdk.rb +++ b/config/initializers/aws_sdk.rb @@ -1,9 +1,18 @@ -# aws_secret_file: path to *.yml with AWS_ACCESS_KEY_ID and AWS_SECRET_KEY_ID +# aws_secret_file: path to *.yml file with AWS_ACCESS_KEY_ID and AWS_SECRET_KEY_ID if exist aws_secret_file = Rails.configuration.service['aws_secret_file'] -creds = YAML.load(File.read(aws_secret_file)) -aws_creds = Aws::Credentials.new( - creds['aws_access_key'], - creds['aws_secret_key'] -) -# Configure an AWS_SNS client -Aws.config.update(region: creds['aws_region'], credentials: aws_creds) +aws_region = Rails.configuration.service['aws_secret_file'] + +if aws_secret_file.nil? + credentials = Aws::InstanceProfileCredentials.new + Aws.config.update({ + region: aws_region, + credentials: credentials + }) +else + creds = YAML.load(File.read(aws_secret_file)) + aws_creds = Aws::Credentials.new( + creds['aws_access_key'], + creds['aws_secret_key'] + ) + Aws.config.update(region: creds['aws_region'], credentials: aws_creds) +end From 1afbbe2c6195c73561207f65a063548f4c87d8eb Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Mon, 10 Apr 2017 13:11:44 +0300 Subject: [PATCH 084/110] Amazon SNS subscription by using Instance profile --- config/service.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/service.yml b/config/service.yml index 00cbed2..2b7fe23 100644 --- a/config/service.yml +++ b/config/service.yml @@ -3,8 +3,9 @@ default: &default basecampbot_url: https://3.basecamp.com/3999996/integrations/8gtJyBKVQHvrQN2h4FitRJSK/buckets/3797353/chats/434442399/lines snstopic_arn: arn:aws:sns:us-west-5:670306886787:magick_kick - # Path to the .yml file that contains 'aws_access_key' and 'aws_secret_key' + # Path to the .yml file that contains 'aws_access_key' and 'aws_secret_key'. Attention!!! Delete it, if you are using Amazon EC2 hosting aws_secret_file: /home/user/secrets.yml + aws_region: 'us-west-2' # Giphy API url + public API key giphy_api_key: "dc6zaTOxFJmzC" From c39d76b43175494e6bc71ea6e209e63b81627bbb Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Mon, 10 Apr 2017 13:18:11 +0300 Subject: [PATCH 085/110] Amazon SNS subscription by using Instance profile --- config/initializers/aws_sdk.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/config/initializers/aws_sdk.rb b/config/initializers/aws_sdk.rb index b059c36..7371946 100644 --- a/config/initializers/aws_sdk.rb +++ b/config/initializers/aws_sdk.rb @@ -2,17 +2,17 @@ aws_secret_file = Rails.configuration.service['aws_secret_file'] aws_region = Rails.configuration.service['aws_secret_file'] -if aws_secret_file.nil? - credentials = Aws::InstanceProfileCredentials.new - Aws.config.update({ +if aws_secret_file.nil? + credentials = Aws::InstanceProfileCredentials.new + Aws.config.update( region: aws_region, credentials: credentials - }) + ) else - creds = YAML.load(File.read(aws_secret_file)) - aws_creds = Aws::Credentials.new( - creds['aws_access_key'], - creds['aws_secret_key'] - ) - Aws.config.update(region: creds['aws_region'], credentials: aws_creds) + creds = YAML.load(File.read(aws_secret_file)) + aws_creds = Aws::Credentials.new( + creds['aws_access_key'], + creds['aws_secret_key'] + ) + Aws.config.update(region: creds['aws_region'], credentials: aws_creds) end From 3ec325635ffa67ad9e1ab39e7cc51015fdbc3344 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Mon, 10 Apr 2017 13:20:44 +0300 Subject: [PATCH 086/110] Amazon SNS subscription by using Instance profile --- config/initializers/aws_sdk.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/config/initializers/aws_sdk.rb b/config/initializers/aws_sdk.rb index 7371946..1ac3992 100644 --- a/config/initializers/aws_sdk.rb +++ b/config/initializers/aws_sdk.rb @@ -4,10 +4,7 @@ if aws_secret_file.nil? credentials = Aws::InstanceProfileCredentials.new - Aws.config.update( - region: aws_region, - credentials: credentials - ) + Aws.config.update(region: aws_region, credentials: credentials) else creds = YAML.load(File.read(aws_secret_file)) aws_creds = Aws::Credentials.new( From 90038206675282136672916c8e272392e3114f05 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Mon, 10 Apr 2017 14:32:54 +0300 Subject: [PATCH 087/110] Amazon SNS subscription by using Instance profile --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 66bb1d5..2a9bae4 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,7 @@ /.bundle /.idea /config/database.yml -#/config/service.yml +/config/service.yml /config/secret.yml From 0c6b0b17b06168f97d654490619a8a9026f97984 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Wed, 12 Apr 2017 05:48:16 +0400 Subject: [PATCH 088/110] Update aws_sdk.rb --- config/initializers/aws_sdk.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/aws_sdk.rb b/config/initializers/aws_sdk.rb index 1ac3992..f87dbf9 100644 --- a/config/initializers/aws_sdk.rb +++ b/config/initializers/aws_sdk.rb @@ -1,6 +1,6 @@ # aws_secret_file: path to *.yml file with AWS_ACCESS_KEY_ID and AWS_SECRET_KEY_ID if exist aws_secret_file = Rails.configuration.service['aws_secret_file'] -aws_region = Rails.configuration.service['aws_secret_file'] +aws_region = Rails.configuration.service['aws_region'] if aws_secret_file.nil? credentials = Aws::InstanceProfileCredentials.new From 38b71f7d127ffe70b82bcf01ee05a6744d4d2818 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Wed, 12 Apr 2017 15:54:28 +0300 Subject: [PATCH 089/110] Add Aws IAM roles manual --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 083f2fa..0cac507 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,10 @@ you need a bot long link. Like this: `arn:aws:sns:us-east-6:23730808936387:topick_name` 2. Add your SNS __Topic ARN__ to `/config/service.yml` 3. [Aws-sdk gem](https://github.com/aws/aws-sdk-ruby), which used in this App, needs 'aws_access_key' and 'aws_secret_key' to work. To find them navigate to "My Security Credentials" category in your asw.amazon account. Always load your credentials from outside your application! Look at `/config/service.yml` for example. Avoid configuring credentials statically and never commit them to source control! + 1) If you're running on AWS EC2 you able to assign AWS keys dynamically with IAM roles. + 2. Create an IAM role. + 3. Define which AWS services can assume the role (AmazonSNSFullAccess etc.) + 4. Specify the role when you launch your instance, or attach the role to a running or stopped instance. 4. Start rails server by typing `rails s` command. 5. [Create subscription](http://docs.aws.amazon.com/sns/latest/dg/SubscribeTopic.html). Use HTTP **Protocol** and `http://your-external-host/api/sns/messages` as __Endpoint__ 6. At first time SNS send confirmation request which will be automatically accepted. After subscription you can [publish messages to the topic](http://docs.aws.amazon.com/sns/latest/dg/PublishTopic.html) From d01b1db0f9a8f4112277930d220e52dc365f798e Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Mon, 17 Apr 2017 13:34:01 +0300 Subject: [PATCH 090/110] Commands controller --- .../commands/commands_controller.rb | 36 +++++++++++++++++++ config/secrets.yml | 10 +++++- config/service.yml | 6 ++-- 3 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 app/controllers/commands/commands_controller.rb diff --git a/app/controllers/commands/commands_controller.rb b/app/controllers/commands/commands_controller.rb new file mode 100644 index 0000000..f485726 --- /dev/null +++ b/app/controllers/commands/commands_controller.rb @@ -0,0 +1,36 @@ +class Api::Bugsnag::MessagesController < ApplicationController + skip_before_action :verify_authenticity_token + + def create + # Get the parsed JSON string + bugsnag_parsed = helpers.parse_webhook + + # error: JSON:ParserError + # Get the failed JSON request message + request_error = bugsnag_parsed[:error] + + # Prepare message for the campfire + message = if request_error + "Failed or non-JSON request: #{request_error}" + else + build_message_text bugsnag_parsed + end + + # send message to basecamp + helpers.send_message(command_params[:callback_url], message) + end + + private + + def build_message_text(bugsnag_parsed) + # Store parsed dada from Bugsnag + event = bugsnag_parsed['error']['exceptionClass'] + error_message = bugsnag_parsed['error']['message'] + event_url = bugsnag_parsed['error']['url'] + return "Event: #{event}
+ Message: #{error_message}
+ Bugsnag report: #{event_url}" + rescue NoMethodError => e # del. exception handlidg to see errors in console + return "Bugsnag parsing error: #{e}" + end +end \ No newline at end of file diff --git a/config/secrets.yml b/config/secrets.yml index 81b55d5..e96a23b 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -1,2 +1,10 @@ +development: + secret_key_base: c32dd50710233ac4673188552d83136e8a7ee50c718b8a52158bea0e76a0afaa665d0f332b101e6c4024d7d3c2e976c4f856a5b5969b09937c7c408fad77d408 + +test: + secret_key_base: 8d42e7fede4ae5d5678250ed920ffbe92b316d73615d070609670e3ef19e72877e077df603c95d54391b2eb1f87ce8d917c6e5e376c22e94b213fa5cea408240 + +# Do not keep production secrets in the repository, +# instead read values from the environment. production: - secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> + secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> \ No newline at end of file diff --git a/config/service.yml b/config/service.yml index 2b7fe23..29cdc1d 100644 --- a/config/service.yml +++ b/config/service.yml @@ -1,10 +1,10 @@ # Add this file to .gitignore right now !!! default: &default - basecampbot_url: https://3.basecamp.com/3999996/integrations/8gtJyBKVQHvrQN2h4FitRJSK/buckets/3797353/chats/434442399/lines - snstopic_arn: arn:aws:sns:us-west-5:670306886787:magick_kick + basecampbot_url: https://3.basecamp.com/3700178/integrations/3gtJyBKVQHvrQN2h7FitRJSK/buckets/3097353/chats/437772399/lines + snstopic_arn: arn:aws:sns:us-west-2:230306836787:bascamp_chatbot # Path to the .yml file that contains 'aws_access_key' and 'aws_secret_key'. Attention!!! Delete it, if you are using Amazon EC2 hosting - aws_secret_file: /home/user/secrets.yml + aws_secret_file: /home/klim/aws.yml aws_region: 'us-west-2' # Giphy API url + public API key giphy_api_key: "dc6zaTOxFJmzC" From 963e9953e227f8ba49110b612e918d5d36471e97 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 21 Apr 2017 14:54:38 +0300 Subject: [PATCH 091/110] controller --- app/controllers/commands/commands_controller.rb | 10 +++++----- app/services/giphy.rb | 0 config/routes.rb | 3 +++ 3 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 app/services/giphy.rb diff --git a/app/controllers/commands/commands_controller.rb b/app/controllers/commands/commands_controller.rb index f485726..9330fc9 100644 --- a/app/controllers/commands/commands_controller.rb +++ b/app/controllers/commands/commands_controller.rb @@ -1,19 +1,19 @@ -class Api::Bugsnag::MessagesController < ApplicationController +class Commands::CommandsController < ApplicationController skip_before_action :verify_authenticity_token def create # Get the parsed JSON string - bugsnag_parsed = helpers.parse_webhook + command_parsed = helpers.parse_webhook # error: JSON:ParserError # Get the failed JSON request message - request_error = bugsnag_parsed[:error] + request_error = command_parsed[:error] # Prepare message for the campfire message = if request_error "Failed or non-JSON request: #{request_error}" else - build_message_text bugsnag_parsed + build_message_text command_parsed end # send message to basecamp @@ -22,7 +22,7 @@ def create private - def build_message_text(bugsnag_parsed) + def build_message_text(command_parsed) # Store parsed dada from Bugsnag event = bugsnag_parsed['error']['exceptionClass'] error_message = bugsnag_parsed['error']['message'] diff --git a/app/services/giphy.rb b/app/services/giphy.rb new file mode 100644 index 0000000..e69de29 diff --git a/config/routes.rb b/config/routes.rb index 7987c97..4997eff 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,9 @@ Rails.application.routes.draw do # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html + namespace :commands, defaults: {format: :json} do + end + namespace :api, defaults: {format: :json} do namespace :bugsnag do resources :messages, only: :create From 720acd5d2e3e8eeafccd09172bb7eb7b02ec340e Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 21 Apr 2017 16:11:58 +0300 Subject: [PATCH 092/110] AWS initializer fixed --- app/controllers/api/sns/messages_controller.rb | 3 ++- config/initializers/aws_sdk.rb | 5 +---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/sns/messages_controller.rb b/app/controllers/api/sns/messages_controller.rb index 9ceb23a..22cf60e 100644 --- a/app/controllers/api/sns/messages_controller.rb +++ b/app/controllers/api/sns/messages_controller.rb @@ -4,7 +4,8 @@ class Api::Sns::MessagesController < ApplicationController def create amazon_sns_request = helpers.parse_webhook snstopic_arn = Rails.configuration.service['snstopic_arn'] - client = helpers.aws_config + aws_region = Rails.configuration.service['aws_region'] + client = Aws::SNS::Client.new(region: aws_region) if amazon_sns_request['Type'].to_s.casecmp('SubscriptionConfirmation') >= 0 client.confirm_subscription( diff --git a/config/initializers/aws_sdk.rb b/config/initializers/aws_sdk.rb index f87dbf9..492552a 100644 --- a/config/initializers/aws_sdk.rb +++ b/config/initializers/aws_sdk.rb @@ -2,10 +2,7 @@ aws_secret_file = Rails.configuration.service['aws_secret_file'] aws_region = Rails.configuration.service['aws_region'] -if aws_secret_file.nil? - credentials = Aws::InstanceProfileCredentials.new - Aws.config.update(region: aws_region, credentials: credentials) -else +if aws_secret_file? creds = YAML.load(File.read(aws_secret_file)) aws_creds = Aws::Credentials.new( creds['aws_access_key'], From 432bb92bcd5fae66c58aecbf9cdb17ad84ae022a Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 21 Apr 2017 16:13:19 +0300 Subject: [PATCH 093/110] AWS initializer fixed --- app/helpers/application_helper.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ed59fc9..8ebd5bc 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,8 +1,4 @@ module ApplicationHelper - def aws_config - Aws::SNS::Client.new - end - def parse_webhook # Parse JSON request from remote calback server JSON.parse request.body.read From 2b6c4a4efad89cb19f9bc2da94b4838253731f18 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 21 Apr 2017 17:19:51 +0400 Subject: [PATCH 094/110] Update service.yml --- config/service.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/service.yml b/config/service.yml index 29cdc1d..c5fa90d 100644 --- a/config/service.yml +++ b/config/service.yml @@ -1,11 +1,11 @@ # Add this file to .gitignore right now !!! default: &default - basecampbot_url: https://3.basecamp.com/3700178/integrations/3gtJyBKVQHvrQN2h7FitRJSK/buckets/3097353/chats/437772399/lines + basecampbot_url: https://3.basecamp.com/3900178/integrations/3gtJyBKVQHvrQ90N2h7FitRJSK/buckets/3797353/chats/437542399/lines snstopic_arn: arn:aws:sns:us-west-2:230306836787:bascamp_chatbot # Path to the .yml file that contains 'aws_access_key' and 'aws_secret_key'. Attention!!! Delete it, if you are using Amazon EC2 hosting - aws_secret_file: /home/klim/aws.yml - aws_region: 'us-west-2' + aws_secret_file: /home/user/aws.yml + aws_region: 'us-west-6' # Giphy API url + public API key giphy_api_key: "dc6zaTOxFJmzC" From 0ded82ed31c0e3ac65c542a45dd216494dfe52ae Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 21 Apr 2017 17:20:50 +0400 Subject: [PATCH 095/110] Update routes.rb --- config/routes.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 4997eff..7987c97 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,9 +1,6 @@ Rails.application.routes.draw do # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html - namespace :commands, defaults: {format: :json} do - end - namespace :api, defaults: {format: :json} do namespace :bugsnag do resources :messages, only: :create From 743e1e0a0412b89e1b2d9d86e2e0d161239c6c6a Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 21 Apr 2017 17:23:16 +0400 Subject: [PATCH 096/110] Update aws_sdk.rb --- config/initializers/aws_sdk.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/config/initializers/aws_sdk.rb b/config/initializers/aws_sdk.rb index 492552a..a4f2525 100644 --- a/config/initializers/aws_sdk.rb +++ b/config/initializers/aws_sdk.rb @@ -1,6 +1,5 @@ # aws_secret_file: path to *.yml file with AWS_ACCESS_KEY_ID and AWS_SECRET_KEY_ID if exist aws_secret_file = Rails.configuration.service['aws_secret_file'] -aws_region = Rails.configuration.service['aws_region'] if aws_secret_file? creds = YAML.load(File.read(aws_secret_file)) From f4d11f00ac6668a9917eb56747f02c3490e3e5fa Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 21 Apr 2017 17:26:15 +0400 Subject: [PATCH 097/110] Delete commands_controller.rb --- .../commands/commands_controller.rb | 36 ------------------- 1 file changed, 36 deletions(-) delete mode 100644 app/controllers/commands/commands_controller.rb diff --git a/app/controllers/commands/commands_controller.rb b/app/controllers/commands/commands_controller.rb deleted file mode 100644 index 9330fc9..0000000 --- a/app/controllers/commands/commands_controller.rb +++ /dev/null @@ -1,36 +0,0 @@ -class Commands::CommandsController < ApplicationController - skip_before_action :verify_authenticity_token - - def create - # Get the parsed JSON string - command_parsed = helpers.parse_webhook - - # error: JSON:ParserError - # Get the failed JSON request message - request_error = command_parsed[:error] - - # Prepare message for the campfire - message = if request_error - "Failed or non-JSON request: #{request_error}" - else - build_message_text command_parsed - end - - # send message to basecamp - helpers.send_message(command_params[:callback_url], message) - end - - private - - def build_message_text(command_parsed) - # Store parsed dada from Bugsnag - event = bugsnag_parsed['error']['exceptionClass'] - error_message = bugsnag_parsed['error']['message'] - event_url = bugsnag_parsed['error']['url'] - return "Event: #{event}
- Message: #{error_message}
- Bugsnag report: #{event_url}" - rescue NoMethodError => e # del. exception handlidg to see errors in console - return "Bugsnag parsing error: #{e}" - end -end \ No newline at end of file From c38f7825a3d7b18ae6785b319180f036246a9603 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 21 Apr 2017 17:27:11 +0400 Subject: [PATCH 098/110] Delete giphy.rb --- app/services/giphy.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 app/services/giphy.rb diff --git a/app/services/giphy.rb b/app/services/giphy.rb deleted file mode 100644 index e69de29..0000000 From 149f2d77248ce37a5c6992be499d6094dbaba538 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 21 Apr 2017 19:06:09 +0400 Subject: [PATCH 099/110] Update aws_sdk.rb --- config/initializers/aws_sdk.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/aws_sdk.rb b/config/initializers/aws_sdk.rb index a4f2525..c5af2d9 100644 --- a/config/initializers/aws_sdk.rb +++ b/config/initializers/aws_sdk.rb @@ -6,6 +6,6 @@ aws_creds = Aws::Credentials.new( creds['aws_access_key'], creds['aws_secret_key'] - ) + ) Aws.config.update(region: creds['aws_region'], credentials: aws_creds) end From f9b63c7f695c43a72245af040905661701643107 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 28 Apr 2017 20:42:56 +0300 Subject: [PATCH 100/110] Add Chatbot model. DRY-ed some methods --- app/controllers/api/bugsnag/messages_controller.rb | 5 ++--- app/controllers/api/giphy/messages_controller.rb | 3 +-- app/controllers/api/gitlab/messages_controller.rb | 5 ++--- app/controllers/api/rollbar/messages_controller.rb | 5 ++--- app/controllers/api/sns/messages_controller.rb | 9 ++++----- app/controllers/application_controller.rb | 7 ++++++- app/helpers/application_helper.rb | 12 ------------ app/models/chatbot.rb | 14 ++++++++++++++ config/initializers/aws_sdk.rb | 8 ++++---- config/service.yml | 8 ++++---- 10 files changed, 39 insertions(+), 37 deletions(-) create mode 100644 app/models/chatbot.rb diff --git a/app/controllers/api/bugsnag/messages_controller.rb b/app/controllers/api/bugsnag/messages_controller.rb index 714b3c5..9fa2a66 100644 --- a/app/controllers/api/bugsnag/messages_controller.rb +++ b/app/controllers/api/bugsnag/messages_controller.rb @@ -1,9 +1,8 @@ class Api::Bugsnag::MessagesController < ApplicationController - skip_before_action :verify_authenticity_token def create # Get the parsed JSON string - bugsnag_parsed = helpers.parse_webhook + bugsnag_parsed = Chatbot.parse_webhook(request.body.read) # error: JSON:ParserError # Get the failed JSON request message @@ -17,7 +16,7 @@ def create end # send message to basecamp - helpers.send_message(command_params[:callback_url], message) + Chatbot.send_message(command_params[:callback_url], message) end private diff --git a/app/controllers/api/giphy/messages_controller.rb b/app/controllers/api/giphy/messages_controller.rb index ad32f73..4fa6386 100644 --- a/app/controllers/api/giphy/messages_controller.rb +++ b/app/controllers/api/giphy/messages_controller.rb @@ -1,8 +1,7 @@ class Api::Giphy::MessagesController < ApplicationController - skip_before_action :verify_authenticity_token def create image = Giphy.random(command_params[:command]).image_original_url.to_s - helpers.send_message(command_params[:callback_url], "") + Chatbot.send_message(command_params[:callback_url], "") end end diff --git a/app/controllers/api/gitlab/messages_controller.rb b/app/controllers/api/gitlab/messages_controller.rb index b17f8d9..47a6bc9 100644 --- a/app/controllers/api/gitlab/messages_controller.rb +++ b/app/controllers/api/gitlab/messages_controller.rb @@ -1,9 +1,8 @@ class Api::Gitlab::MessagesController < ApplicationController - skip_before_action :verify_authenticity_token def create # Get the parsed JSON string - gitlab_parsed = helpers.parse_webhook + gitlab_parsed = Chatbot.parse_webhook(request.body.read) # error: JSON:ParserError # Get the failed JSON request message @@ -17,7 +16,7 @@ def create end # send message to basecamp - helpers.send_message(command_params[:callback_url], message) + Chatbot.send_message(command_params[:callback_url], message) end private diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index 6cc92fb..117476f 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -1,9 +1,8 @@ class Api::Rollbar::MessagesController < ApplicationController - skip_before_action :verify_authenticity_token def create # Get the parsed JSON string - rollbar_parsed = helpers.parse_webhook + rollbar_parsed = Chatbot.parse_webhook(request.body.read) # error: JSON:ParserError # Get the failed JSON request message @@ -17,7 +16,7 @@ def create end # send message to basecamp - helpers.send_message(command_params[:callback_url], message) + Chatbot.send_message(command_params[:callback_url], message) end private diff --git a/app/controllers/api/sns/messages_controller.rb b/app/controllers/api/sns/messages_controller.rb index 22cf60e..1c8daf3 100644 --- a/app/controllers/api/sns/messages_controller.rb +++ b/app/controllers/api/sns/messages_controller.rb @@ -1,23 +1,22 @@ class Api::Sns::MessagesController < ApplicationController - skip_before_action :verify_authenticity_token def create - amazon_sns_request = helpers.parse_webhook + amazon_sns_request = Chatbot.parse_webhook(request.body.read) snstopic_arn = Rails.configuration.service['snstopic_arn'] aws_region = Rails.configuration.service['aws_region'] client = Aws::SNS::Client.new(region: aws_region) if amazon_sns_request['Type'].to_s.casecmp('SubscriptionConfirmation') >= 0 client.confirm_subscription( - topic_arn: snstopic_arn, - token: amazon_sns_request['Token'] + topic_arn: snstopic_arn, + token: amazon_sns_request['Token'] ) elsif amazon_sns_request['Type'].to_s.casecmp('Notification') >= 0 message = build_message_text amazon_sns_request end # send message to basecamp - helpers.send_message(command_params[:callback_url], message) + Chatbot.send_message(command_params[:callback_url], message) end private diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6eacdbf..a7fff51 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,8 +1,13 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception - + skip_before_action :verify_authenticity_token, if: :json_request? + private + def json_request? + request.format.json? + end + def command_params params.permit(:command, :callback_url) end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8ebd5bc..de6be79 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,14 +1,2 @@ module ApplicationHelper - def parse_webhook - # Parse JSON request from remote calback server - JSON.parse request.body.read - # Handle exceptions in case of failed request - rescue JSON::ParserError => error - return { error: error.to_s } - end - - def send_message(basecampbot_url, message) - basecampbot_url ||= Rails.configuration.service['basecampbot_url'] - HTTParty.post basecampbot_url, query: { content: message } - end end diff --git a/app/models/chatbot.rb b/app/models/chatbot.rb new file mode 100644 index 0000000..10c8aab --- /dev/null +++ b/app/models/chatbot.rb @@ -0,0 +1,14 @@ +class Chatbot + + def self.parse_webhook(resp) + JSON.parse resp + # Handle exceptions in case of failed request + rescue JSON::ParserError => error + return { error: error.to_s } + end + + def self.send_message(basecampbot_url, message) + basecampbot_url ||= Rails.configuration.service['basecampbot_url'] + HTTParty.post basecampbot_url, query: { content: message } + end +end diff --git a/config/initializers/aws_sdk.rb b/config/initializers/aws_sdk.rb index c5af2d9..cebc4cd 100644 --- a/config/initializers/aws_sdk.rb +++ b/config/initializers/aws_sdk.rb @@ -1,11 +1,11 @@ # aws_secret_file: path to *.yml file with AWS_ACCESS_KEY_ID and AWS_SECRET_KEY_ID if exist aws_secret_file = Rails.configuration.service['aws_secret_file'] -if aws_secret_file? +if aws_secret_file.present? creds = YAML.load(File.read(aws_secret_file)) aws_creds = Aws::Credentials.new( - creds['aws_access_key'], - creds['aws_secret_key'] - ) + creds['aws_access_key'], + creds['aws_secret_key'] + ) Aws.config.update(region: creds['aws_region'], credentials: aws_creds) end diff --git a/config/service.yml b/config/service.yml index c5fa90d..6e1a680 100644 --- a/config/service.yml +++ b/config/service.yml @@ -1,11 +1,11 @@ # Add this file to .gitignore right now !!! default: &default - basecampbot_url: https://3.basecamp.com/3900178/integrations/3gtJyBKVQHvrQ90N2h7FitRJSK/buckets/3797353/chats/437542399/lines + basecampbot_url: https://3.basecamp.com/3734398/integrations/Kvre67sn95bakxFzJLqDGDRe/buckets/3504557/chats/491031306/lines snstopic_arn: arn:aws:sns:us-west-2:230306836787:bascamp_chatbot # Path to the .yml file that contains 'aws_access_key' and 'aws_secret_key'. Attention!!! Delete it, if you are using Amazon EC2 hosting - aws_secret_file: /home/user/aws.yml - aws_region: 'us-west-6' + aws_secret_file: /home/klim/aws.yml + aws_region: 'us-west-2' # Giphy API url + public API key giphy_api_key: "dc6zaTOxFJmzC" @@ -17,4 +17,4 @@ test: production: basecampbot_url: <%= ENV["BASECAMPBOT_URL"] %> -giphy_api_key: <%= ENV["GIPHY_API_KEY"] %> + iphy_api_key: <%= ENV["GIPHY_API_KEY"] %> From 295c7911e2954ed81feeda8b3579e1107fad4a4c Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 28 Apr 2017 21:53:26 +0400 Subject: [PATCH 101/110] Update service.yml --- config/service.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/service.yml b/config/service.yml index 6e1a680..a5c65a4 100644 --- a/config/service.yml +++ b/config/service.yml @@ -1,11 +1,11 @@ # Add this file to .gitignore right now !!! default: &default - basecampbot_url: https://3.basecamp.com/3734398/integrations/Kvre67sn95bakxFzJLqDGDRe/buckets/3504557/chats/491031306/lines - snstopic_arn: arn:aws:sns:us-west-2:230306836787:bascamp_chatbot + basecampbot_url: https://3.basecamp.com/34334368/integrations/Kvre67sn895bakxFzJLqD99GDRe/buckets/3854557/chats/498331306/lines + snstopic_arn: arn:aws:sns:us-west-2:2303078387557:bascamp_chatbot # Path to the .yml file that contains 'aws_access_key' and 'aws_secret_key'. Attention!!! Delete it, if you are using Amazon EC2 hosting aws_secret_file: /home/klim/aws.yml - aws_region: 'us-west-2' + aws_region: 'us-west-6' # Giphy API url + public API key giphy_api_key: "dc6zaTOxFJmzC" @@ -17,4 +17,4 @@ test: production: basecampbot_url: <%= ENV["BASECAMPBOT_URL"] %> - iphy_api_key: <%= ENV["GIPHY_API_KEY"] %> + giphy_api_key: <%= ENV["GIPHY_API_KEY"] %> From ad3f2464e1229037d4d2b61be3d222efbbfb1331 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 28 Apr 2017 21:56:07 +0400 Subject: [PATCH 102/110] Update chatbot.rb --- app/models/chatbot.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/chatbot.rb b/app/models/chatbot.rb index 10c8aab..bd6d45a 100644 --- a/app/models/chatbot.rb +++ b/app/models/chatbot.rb @@ -1,5 +1,5 @@ class Chatbot - + def self.parse_webhook(resp) JSON.parse resp # Handle exceptions in case of failed request From 90f0a29432c4252cd057be2f17cb0a9c1fdc2fb2 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 28 Apr 2017 21:57:56 +0400 Subject: [PATCH 103/110] Update application_controller.rb --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a7fff51..07c405a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,7 +1,7 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception skip_before_action :verify_authenticity_token, if: :json_request? - + private def json_request? From deae4ece05f3ae264bc8f7f71df9c793591e3fcd Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 28 Apr 2017 21:59:37 +0400 Subject: [PATCH 104/110] Update messages_controller.rb --- app/controllers/api/sns/messages_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/api/sns/messages_controller.rb b/app/controllers/api/sns/messages_controller.rb index 1c8daf3..0bb67a2 100644 --- a/app/controllers/api/sns/messages_controller.rb +++ b/app/controllers/api/sns/messages_controller.rb @@ -1,5 +1,4 @@ class Api::Sns::MessagesController < ApplicationController - def create amazon_sns_request = Chatbot.parse_webhook(request.body.read) snstopic_arn = Rails.configuration.service['snstopic_arn'] From f5ce2d1dbbff7f39928ca9262a28715d0c5c5641 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 28 Apr 2017 22:00:33 +0400 Subject: [PATCH 105/110] Update messages_controller.rb --- app/controllers/api/gitlab/messages_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/api/gitlab/messages_controller.rb b/app/controllers/api/gitlab/messages_controller.rb index 47a6bc9..3b2b3c2 100644 --- a/app/controllers/api/gitlab/messages_controller.rb +++ b/app/controllers/api/gitlab/messages_controller.rb @@ -1,5 +1,4 @@ class Api::Gitlab::MessagesController < ApplicationController - def create # Get the parsed JSON string gitlab_parsed = Chatbot.parse_webhook(request.body.read) From c8363ed85d565fc5f1cb13fd715542a83de3f040 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 28 Apr 2017 22:01:14 +0400 Subject: [PATCH 106/110] Update messages_controller.rb --- app/controllers/api/rollbar/messages_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/api/rollbar/messages_controller.rb b/app/controllers/api/rollbar/messages_controller.rb index 117476f..7b78d47 100644 --- a/app/controllers/api/rollbar/messages_controller.rb +++ b/app/controllers/api/rollbar/messages_controller.rb @@ -1,5 +1,4 @@ class Api::Rollbar::MessagesController < ApplicationController - def create # Get the parsed JSON string rollbar_parsed = Chatbot.parse_webhook(request.body.read) From db86b21f014a81da4e4defa6952288eca26e79f4 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 28 Apr 2017 22:02:02 +0400 Subject: [PATCH 107/110] Update messages_controller.rb --- app/controllers/api/giphy/messages_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/api/giphy/messages_controller.rb b/app/controllers/api/giphy/messages_controller.rb index 4fa6386..c6fab45 100644 --- a/app/controllers/api/giphy/messages_controller.rb +++ b/app/controllers/api/giphy/messages_controller.rb @@ -1,5 +1,4 @@ class Api::Giphy::MessagesController < ApplicationController - def create image = Giphy.random(command_params[:command]).image_original_url.to_s Chatbot.send_message(command_params[:callback_url], "") From 586dc040356ec2f50d3450b30bfe209adf16a1d5 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 28 Apr 2017 22:02:51 +0400 Subject: [PATCH 108/110] Update chatbot.rb --- app/models/chatbot.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/models/chatbot.rb b/app/models/chatbot.rb index bd6d45a..0704dce 100644 --- a/app/models/chatbot.rb +++ b/app/models/chatbot.rb @@ -1,5 +1,4 @@ class Chatbot - def self.parse_webhook(resp) JSON.parse resp # Handle exceptions in case of failed request From 71fa344f390657f49cd380bfe748d03cbb0c2ac5 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 28 Apr 2017 22:05:33 +0400 Subject: [PATCH 109/110] Update messages_controller.rb --- app/controllers/api/bugsnag/messages_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/api/bugsnag/messages_controller.rb b/app/controllers/api/bugsnag/messages_controller.rb index 9fa2a66..1e9e1c4 100644 --- a/app/controllers/api/bugsnag/messages_controller.rb +++ b/app/controllers/api/bugsnag/messages_controller.rb @@ -1,5 +1,4 @@ class Api::Bugsnag::MessagesController < ApplicationController - def create # Get the parsed JSON string bugsnag_parsed = Chatbot.parse_webhook(request.body.read) From 46c77287e8799fe6e49b2134428c7c0acd79bbe9 Mon Sep 17 00:00:00 2001 From: Klim Agarkov Date: Fri, 28 Apr 2017 22:08:05 +0400 Subject: [PATCH 110/110] Update service.yml --- config/service.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/service.yml b/config/service.yml index a5c65a4..822b30b 100644 --- a/config/service.yml +++ b/config/service.yml @@ -4,7 +4,7 @@ default: &default basecampbot_url: https://3.basecamp.com/34334368/integrations/Kvre67sn895bakxFzJLqD99GDRe/buckets/3854557/chats/498331306/lines snstopic_arn: arn:aws:sns:us-west-2:2303078387557:bascamp_chatbot # Path to the .yml file that contains 'aws_access_key' and 'aws_secret_key'. Attention!!! Delete it, if you are using Amazon EC2 hosting - aws_secret_file: /home/klim/aws.yml + aws_secret_file: /home/user/aws.yml aws_region: 'us-west-6' # Giphy API url + public API key giphy_api_key: "dc6zaTOxFJmzC"