diff --git a/.ruby-version b/.ruby-version index 7fa1d1e..359a5b9 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.0.0-p353 +2.0.0 \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a6bd9b7..86b7387 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,20 @@ -language: ruby -cache: bundler +cache: + directories: + - ~/cache services: - - elasticsearch -before_script: - - bundle exec rake db:setup + - docker +before_install: + - docker-compose --version + - mv docker-compose.ci.yml docker-compose.override.yml + - docker-compose pull + - docker-compose run --rm --no-deps web bundle install + - docker-compose up -d db elasticsearch + - docker-compose run --rm --no-deps web rake db:setup + - docker-compose run --rm --no-deps web rake db:test:prepare script: - - bundle exec rspec + - docker-compose run --rm web bundle exec rspec notifications: slack: secure: L7ysz/oWaFNMmSFmJN4z2iRqyDX2zmT8sqvsukKTNMyl9ENqbZFPyvC53ICMa2DLtP/X/XX1tzfHEqg9hZ2On2hju/Ohn9DG+RRjCm5Cu+05rpkliZO98gfVo1pTAfA4vn3HXsSHHRL5tmjUx7+YxbbF3YugJ2M0TUqFxI/1yiM= + + diff --git a/Gemfile b/Gemfile index 6318563..31536d1 100644 --- a/Gemfile +++ b/Gemfile @@ -43,6 +43,7 @@ gem 'guid' gem 'instedd-bootstrap', github: "instedd/instedd-bootstrap", branch: 'master' gem 'hub_client', github: 'instedd/ruby-hub_client', branch: 'master' gem 'instedd_telemetry', github: 'instedd/telemetry_rails', branch: 'master' +gem 'intercom-rails' group :assets do gem 'sass-rails', '~> 3.2.3' diff --git a/Gemfile.lock b/Gemfile.lock index 8af01df..636c275 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -194,6 +194,8 @@ GEM httpclient (2.5.3.3) i18n (0.6.11) ice_cube (0.11.0) + intercom-rails (0.4.0) + activesupport (> 3.0) journey (1.0.4) jquery-rails (3.0.4) railties (>= 3.0, < 5.0) @@ -377,6 +379,7 @@ DEPENDENCIES instedd-bootstrap! instedd-pigeon! instedd_telemetry! + intercom-rails jquery-rails listings machinist @@ -406,4 +409,4 @@ DEPENDENCIES underscore-rails BUNDLED WITH - 1.10.6 + 1.11.2 diff --git a/README.md b/README.md index 263c9a9..3584e75 100644 --- a/README.md +++ b/README.md @@ -71,3 +71,13 @@ root@web_1 $ rake powered by capistrano. `$ HOSTS= cap deploy`. Configuration files are symlinked in a shared path. check `symlink_configs` task. + +## Intercom + +mBuilder supports Intercom as its CRM platform. To load the Intercom chat widget, simply start mBuilder with the env variable `INTERCOM_APP_ID` set to your Intercom app id (https://www.intercom.com/help/faqs-and-troubleshooting/getting-set-up/where-can-i-find-my-workspace-id-app-id). + +mBuilder will forward any conversation with a logged user identifying them through their email address. Anonymous, unlogged users will also be able to communicate. + +If you don't want to use Intercom, you can simply omit `INTERCOM_APP_ID` or set it to `''`. + +To test the feature in development, add the `INTERCOM_APP_ID` variable and its value to the `environment` object inside the `web` service in `docker-compose.yml`. \ No newline at end of file diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index fe1b0f9..0f0e26a 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,7 +1,14 @@ class HomeController < ApplicationController + after_filter :intercom_shutdown, :only => [:index] + def index end def test end + + protected + def intercom_shutdown + IntercomRails::ShutdownHelper.intercom_shutdown(session, cookies, request.domain) + end end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 0000000..7798d40 --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,8 @@ +class SessionsController < Devise::SessionsController + after_filter :prepare_intercom_shutdown, :only => [:destroy] + + protected + def prepare_intercom_shutdown + IntercomRails::ShutdownHelper.prepare_intercom_shutdown(session) + end +end diff --git a/config/initializers/intercom.rb b/config/initializers/intercom.rb new file mode 100644 index 0000000..f4e13d0 --- /dev/null +++ b/config/initializers/intercom.rb @@ -0,0 +1,119 @@ +if ENV["INTERCOM_APP_ID"] + IntercomRails.config do |config| + # == Intercom app_id + # + config.app_id = ENV["INTERCOM_APP_ID"] + + # == Intercom session_duration + # + # config.session_duration = 300000 + # == Intercom secret key + # This is required to enable Identity Verification, you can find it on your Setup + # guide in the "Identity Verification" step. + # + # config.api_secret = "..." + + # == Enabled Environments + # Which environments is auto inclusion of the Javascript enabled for + # + config.enabled_environments = ["development", "production"] + + # == Current user method/variable + # The method/variable that contains the logged in user in your controllers. + # If it is `current_user` or `@user`, then you can ignore this + # + # config.user.current = [Proc.new { current_user }] + config.user.current = Proc.new { current_user } + # + # == Include for logged out Users + # If set to true, include the Intercom messenger on all pages, regardless of whether + # The user model class (set below) is present. + config.include_for_logged_out_users = true + + # == User model class + # The class which defines your user model + # + # config.user.model = Proc.new { User } + + # == Lead/custom attributes for non-signed up users + # Pass additional attributes to for potential leads or + # non-signed up users as an an array. + # Any attribute contained in config.user.lead_attributes can be used + # as custom attribute in the application. + # config.user.lead_attributes = %w(ref_data utm_source) + + # == Exclude users + # A Proc that given a user returns true if the user should be excluded + # from imports and Javascript inclusion, false otherwise. + # + # config.user.exclude_if = Proc.new { |user| user.deleted? } + + # == User Custom Data + # A hash of additional data you wish to send about your users. + # You can provide either a method name which will be sent to the current + # user object, or a Proc which will be passed the current user. + # + # config.user.custom_data = { + # :plan => Proc.new { |current_user| current_user.plan.name }, + # :favorite_color => :favorite_color + # } + config.user.custom_data = { + :user_id => Proc.new { |user| user.email } + } + + # == Current company method/variable + # The method/variable that contains the current company for the current user, + # in your controllers. 'Companies' are generic groupings of users, so this + # could be a company, app or group. + # + # config.company.current = Proc.new { current_company } + # + # Or if you are using devise you can just use the following config + # + # config.company.current = Proc.new { current_user.company } + + # == Exclude company + # A Proc that given a company returns true if the company should be excluded + # from imports and Javascript inclusion, false otherwise. + # + # config.company.exclude_if = Proc.new { |app| app.subdomain == 'demo' } + + # == Company Custom Data + # A hash of additional data you wish to send about a company. + # This works the same as User custom data above. + # + # config.company.custom_data = { + # :number_of_messages => Proc.new { |app| app.messages.count }, + # :is_interesting => :is_interesting? + # } + + # == Company Plan name + # This is the name of the plan a company is currently paying (or not paying) for. + # e.g. Messaging, Free, Pro, etc. + # + # config.company.plan = Proc.new { |current_company| current_company.plan.name } + + # == Company Monthly Spend + # This is the amount the company spends each month on your app. If your company + # has a plan, it will set the 'total value' of that plan appropriately. + # + # config.company.monthly_spend = Proc.new { |current_company| current_company.plan.price } + # config.company.monthly_spend = Proc.new { |current_company| (current_company.plan.price - current_company.subscription.discount) } + + # == Custom Style + # By default, Intercom will add a button that opens the messenger to + # the page. If you'd like to use your own link to open the messenger, + # uncomment this line and clicks on any element with id 'Intercom' will + # open the messenger. + # + # config.inbox.style = :custom + # + # If you'd like to use your own link activator CSS selector + # uncomment this line and clicks on any element that matches the query will + # open the messenger + # config.inbox.custom_activator = '.intercom' + # + # If you'd like to hide default launcher button uncomment this line + # config.hide_default_launcher = true + end +end diff --git a/config/routes.rb b/config/routes.rb index 92a1b5e..50001a3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,7 +3,7 @@ get "logs/index" - devise_for :users, controllers: {omniauth_callbacks: 'omniauth_callbacks'} + devise_for :users, controllers: {omniauth_callbacks: 'omniauth_callbacks', sessions: 'sessions'} guisso_for :user resources :applications do diff --git a/docker-compose.ci.yml b/docker-compose.ci.yml new file mode 100644 index 0000000..dc12ecb --- /dev/null +++ b/docker-compose.ci.yml @@ -0,0 +1,40 @@ +version: '2.0' + +services: + db: + image: mysql:5.6 + environment: + MYSQL_ALLOW_EMPTY_PASSWORD: 'yes' + volumes: + - db:/var/lib/mysql + + elasticsearch: + image: elasticsearch:2.3 + command: elasticsearch -Des.network.host=0.0.0.0 + volumes: + - elastic:/usr/share/elasticsearch/data + + web: &rails + image: instedd/nginx-rails:2.0 + environment: + RAILS_ENV: + ELASTICSEARCH_URL: 'http://elasticsearch:9200' + DATABASE_HOST: 'db' + volumes: + - ~/cache/bundle:/usr/local/bundle + depends_on: + - db + - elasticsearch + command: 'rails server' + ports: + - 3000:3000 + + jobs_work: + <<: *rails + command: 'rake jobs:work' + ports: [] + +volumes: + db: + bundle: + elastic: