diff --git a/.env.example b/.env.example index 599b1fb60..1b9cbb3e6 100644 --- a/.env.example +++ b/.env.example @@ -19,6 +19,10 @@ FB_VERIFY_TOKEN= FB_APP_SECRET= FB_APP_ID= +#twitter app +TWITTER_CONSUMER_KEY= +TWITTER_CONSUMER_SECRET= + #mail MAILER_SENDER_EMAIL=accounts@chatwoot.com SMTP_PORT=1025 diff --git a/.rubocop.yml b/.rubocop.yml index 09b36e576..a21f6eada 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -20,6 +20,9 @@ Style/GlobalVars: Exclude: - 'config/initializers/redis.rb' - 'lib/redis/alfred.rb' + - 'app/controllers/api/v1/webhooks_controller.rb' + - 'app/services/twitter/send_reply_service.rb' + - 'spec/services/twitter/send_reply_service_spec.rb' Metrics/BlockLength: Exclude: - spec/**/* diff --git a/Gemfile b/Gemfile index fd1d783e4..284e9bff7 100644 --- a/Gemfile +++ b/Gemfile @@ -61,6 +61,9 @@ gem 'chargebee' gem 'facebook-messenger' gem 'telegram-bot-ruby' gem 'twitter' +# twitty will handle subscription of twitter account events +gem 'twitty', git: 'https://github.com/chatwoot/twitty' + # facebook client gem 'koala' # Random name generator diff --git a/Gemfile.lock b/Gemfile.lock index cba93566b..3bf10b7ae 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,10 @@ +GIT + remote: https://github.com/chatwoot/twitty + revision: a005f8f6740fc8d2d3500701e1ab4ab0f1416c26 + specs: + twitty (0.1.0) + oauth + GEM remote: https://rubygems.org/ specs: @@ -66,15 +73,15 @@ GEM activerecord (>= 3.2, < 7.0) rake (>= 10.4, < 14.0) ast (2.4.0) - attr_extras (6.2.1) + attr_extras (6.2.2) aws-eventstream (1.0.3) - aws-partitions (1.262.0) - aws-sdk-core (3.86.0) + aws-partitions (1.268.0) + aws-sdk-core (3.89.1) aws-eventstream (~> 1.0, >= 1.0.2) aws-partitions (~> 1, >= 1.239.0) aws-sigv4 (~> 1.1) jmespath (~> 1.0) - aws-sdk-kms (1.27.0) + aws-sdk-kms (1.28.0) aws-sdk-core (~> 3, >= 3.71.0) aws-sigv4 (~> 1.1) aws-sdk-s3 (1.60.1) @@ -101,10 +108,10 @@ GEM bootsnap (1.4.5) msgpack (~> 1.0) brakeman (4.7.2) - browser (2.7.1) + browser (3.0.3) buftok (0.2.0) builder (3.2.4) - bullet (6.0.2) + bullet (6.1.0) activesupport (>= 3.0.0) uniform_notifier (~> 1.11) bundle-audit (0.1.0) @@ -112,8 +119,8 @@ GEM bundler-audit (0.6.1) bundler (>= 1.2.0, < 3) thor (~> 0.18) - byebug (11.0.1) - chargebee (2.7.1) + byebug (11.1.1) + chargebee (2.7.3) json_pure (~> 2.1) rest-client (>= 1.8, < 3.0) coderay (1.1.2) @@ -121,7 +128,7 @@ GEM descendants_tracker (~> 0.0.1) concurrent-ruby (1.1.5) connection_pool (2.2.2) - crass (1.0.5) + crass (1.0.6) declarative (0.0.10) declarative-option (0.1.0) descendants_tracker (0.0.4) @@ -156,14 +163,14 @@ GEM factory_bot_rails (5.1.1) factory_bot (~> 5.1.0) railties (>= 4.2.0) - faker (2.9.0) - i18n (>= 1.6, < 1.8) - faraday (0.17.1) + faker (2.10.1) + i18n (>= 1.6, < 2) + faraday (0.17.3) multipart-post (>= 1.2, < 3) - faraday_middleware (0.13.1) + faraday_middleware (0.14.0) faraday (>= 0.7.4, < 1.0) - ffi (1.11.3) - foreman (0.86.0) + ffi (1.12.1) + foreman (0.87.0) globalid (0.4.2) activesupport (>= 4.2.0) google-api-client (0.36.4) @@ -174,10 +181,12 @@ GEM representable (~> 3.0) retriable (>= 2.0, < 4.0) signet (~> 0.12) - google-cloud-core (1.4.1) + google-cloud-core (1.5.0) google-cloud-env (~> 1.0) + google-cloud-errors (~> 1.0) google-cloud-env (1.3.0) faraday (~> 0.11) + google-cloud-errors (1.0.0) google-cloud-storage (1.25.1) addressable (~> 2.5) digest-crc (~> 0.4) @@ -202,13 +211,13 @@ GEM http-accept (1.7.0) http-cookie (1.0.3) domain_name (~> 0.5) - http-form_data (2.1.1) + http-form_data (2.2.0) http_parser.rb (0.6.0) httparty (0.17.3) mime-types (~> 3.0) multi_xml (>= 0.5.2) httpclient (2.8.3) - i18n (1.7.0) + i18n (1.8.2) concurrent-ruby (~> 1.0) ice_nine (0.11.2) inflecto (0.0.2) @@ -253,14 +262,14 @@ GEM memoizable (0.4.2) thread_safe (~> 0.3, >= 0.3.1) method_source (0.9.2) - mime-types (3.3) + mime-types (3.3.1) mime-types-data (~> 3.2015) mime-types-data (3.2019.1009) mimemagic (0.3.3) - mini_magick (4.9.5) + mini_magick (4.10.1) mini_mime (1.0.2) mini_portile2 (2.4.0) - minitest (5.13.0) + minitest (5.14.0) mock_redis (0.22.0) msgpack (1.3.1) multi_json (1.14.1) @@ -272,28 +281,29 @@ GEM nio4r (2.5.2) nokogiri (1.10.7) mini_portile2 (~> 2.4.0) + oauth (0.5.4) orm_adapter (0.5.0) os (1.0.1) parallel (1.19.1) - parser (2.6.5.0) + parser (2.7.0.2) ast (~> 2.4.0) - pg (1.1.4) + pg (1.2.2) pry (0.12.2) coderay (~> 1.1.0) method_source (~> 0.9.0) pry-rails (0.3.9) pry (>= 0.10.4) - public_suffix (4.0.1) + public_suffix (4.0.3) puma (4.3.1) nio4r (~> 2.0) pundit (2.1.0) activesupport (>= 3.0.0) - rack (2.0.8) - rack-cache (1.10.0) + rack (2.1.1) + rack-cache (1.11.0) rack (>= 0.4) - rack-cors (1.1.0) + rack-cors (1.1.1) rack (>= 2.0.0) - rack-protection (2.0.7) + rack-protection (2.0.8.1) rack rack-proxy (0.6.5) rack @@ -328,7 +338,7 @@ GEM rainbow (3.0.0) rake (13.0.1) rb-fsevent (0.10.3) - rb-inotify (0.10.0) + rb-inotify (0.10.1) ffi (~> 1.0) redis (4.1.3) redis-namespace (1.7.0) @@ -351,33 +361,33 @@ GEM mime-types (>= 1.16, < 4.0) netrc (~> 0.8) retriable (3.1.2) - rspec-core (3.9.0) - rspec-support (~> 3.9.0) + rspec-core (3.9.1) + rspec-support (~> 3.9.1) rspec-expectations (3.9.0) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.9.0) - rspec-mocks (3.9.0) + rspec-mocks (3.9.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.9.0) - rspec-rails (4.0.0.beta3) + rspec-rails (4.0.0.beta4) actionpack (>= 4.2) activesupport (>= 4.2) railties (>= 4.2) - rspec-core (~> 3.8) - rspec-expectations (~> 3.8) - rspec-mocks (~> 3.8) - rspec-support (~> 3.8) - rspec-support (3.9.0) - rubocop (0.78.0) + rspec-core (~> 3.9) + rspec-expectations (~> 3.9) + rspec-mocks (~> 3.9) + rspec-support (~> 3.9) + rspec-support (3.9.2) + rubocop (0.79.0) jaro_winkler (~> 1.5.1) parallel (~> 1.10) - parser (>= 2.6) + parser (>= 2.7.0.1) rainbow (>= 2.2.2, < 4.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 1.7) - rubocop-performance (1.5.1) + rubocop-performance (1.5.2) rubocop (>= 0.71.0) - rubocop-rails (2.4.0) + rubocop-rails (2.4.1) rack (>= 1.1) rubocop (>= 0.72.0) rubocop-rspec (1.37.1) @@ -388,7 +398,7 @@ GEM activesupport (>= 4) sentry-raven (2.13.0) faraday (>= 0.7.6, < 1.0) - shoulda-matchers (4.1.2) + shoulda-matchers (4.2.0) activesupport (>= 4.2.0) sidekiq (6.0.4) connection_pool (>= 2.2.2) @@ -437,7 +447,7 @@ GEM multipart-post (~> 2.0) naught (~> 1.0) simple_oauth (~> 0.3.0) - tzinfo (1.2.5) + tzinfo (1.2.6) thread_safe (~> 0.1) tzinfo-data (1.2019.3) tzinfo (>= 1.0.0) @@ -447,7 +457,7 @@ GEM unf (0.1.4) unf_ext unf_ext (0.0.7.6) - unicode-display_width (1.6.0) + unicode-display_width (1.6.1) uniform_notifier (1.13.0) valid_email2 (3.1.3) activemodel (>= 3.2) @@ -535,6 +545,7 @@ DEPENDENCIES telegram-bot-ruby time_diff twitter + twitty! tzinfo-data uglifier valid_email2 diff --git a/app/controllers/api/v1/webhooks_controller.rb b/app/controllers/api/v1/webhooks_controller.rb index 6ea63cf53..10bcfc25a 100644 --- a/app/controllers/api/v1/webhooks_controller.rb +++ b/app/controllers/api/v1/webhooks_controller.rb @@ -3,7 +3,7 @@ class Api::V1::WebhooksController < ApplicationController skip_before_action :set_current_user skip_before_action :check_subscription - before_action :login_from_basic_auth + before_action :login_from_basic_auth, only: [:chargebee] def chargebee chargebee_consumer.consume head :ok @@ -12,6 +12,18 @@ class Api::V1::WebhooksController < ApplicationController head :ok end + def twitter_crc + render json: { response_token: "sha256=#{$twitter.generate_crc(params[:crc_token])}" } + end + + def twitter_events + twitter_consumer.consume + head :ok + rescue StandardError => e + Raven.capture_exception(e) + head :ok + end + private def login_from_basic_auth @@ -21,6 +33,10 @@ class Api::V1::WebhooksController < ApplicationController end def chargebee_consumer - @consumer ||= ::Webhooks::Chargebee.new(params) + @chargebee_consumer ||= ::Webhooks::Chargebee.new(params) + end + + def twitter_consumer + @twitter_consumer ||= ::Webhooks::Twitter.new(params) end end diff --git a/app/javascript/dashboard/assets/images/Mask.png b/app/javascript/dashboard/assets/images/Mask.png new file mode 100644 index 000000000..1894f1f76 Binary files /dev/null and b/app/javascript/dashboard/assets/images/Mask.png differ diff --git a/app/javascript/dashboard/assets/images/twitter-badge.png b/app/javascript/dashboard/assets/images/twitter-badge.png new file mode 100644 index 000000000..9dd805942 Binary files /dev/null and b/app/javascript/dashboard/assets/images/twitter-badge.png differ diff --git a/app/javascript/dashboard/components/widgets/Thumbnail.vue b/app/javascript/dashboard/components/widgets/Thumbnail.vue index b27a49028..3f7b1a7a2 100644 --- a/app/javascript/dashboard/components/widgets/Thumbnail.vue +++ b/app/javascript/dashboard/components/widgets/Thumbnail.vue @@ -27,6 +27,13 @@ class="source-badge user--online" :style="statusStyle" > +