From 774ebdb67a880718f54418f27a63f9b027c87a3a Mon Sep 17 00:00:00 2001 From: Martin Verzilli Date: Fri, 23 Nov 2018 14:12:46 -0300 Subject: [PATCH 1/3] Add Intercom --- Gemfile | 1 + Gemfile.lock | 7 +- README.md | 7 ++ app/controllers/home_controller.rb | 15 +++- app/controllers/sessions_controller.rb | 8 ++ config/initializers/intercom.rb | 116 +++++++++++++++++++++++++ config/routes.rb | 5 +- 7 files changed, 152 insertions(+), 7 deletions(-) create mode 100644 app/controllers/sessions_controller.rb create mode 100644 config/initializers/intercom.rb diff --git a/Gemfile b/Gemfile index ca8c96e..6428676 100644 --- a/Gemfile +++ b/Gemfile @@ -23,6 +23,7 @@ gem 'ruby-openid' gem 'rack-oauth2' gem 'alto_guisso', git: "https://github.com/instedd/alto_guisso.git", branch: 'master' gem 'alto_guisso_rails', git: "https://github.com/instedd/alto_guisso_rails.git", branch: 'master' +gem 'intercom-rails' gem 'breadcrumbs_on_rails' gem 'fast_gettext' diff --git a/Gemfile.lock b/Gemfile.lock index adf76ee..db21d4f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -10,7 +10,7 @@ GIT GIT remote: git://github.com/instedd/telemetry_rails.git - revision: b361d4cf3167a7184f77c678d77c517f5680f032 + revision: db0ef5c0e72b8a944befb7b9b88beedb876b296c branch: master specs: instedd_telemetry (0.0.1) @@ -145,6 +145,8 @@ GEM httpclient (2.6.0.1) i18n (0.7.0) ice_cube (0.6.14) + intercom-rails (0.4.0) + activesupport (> 3.0) io-console (0.4.2) journey (1.0.4) jquery-rails (2.1.4) @@ -290,6 +292,7 @@ DEPENDENCIES hub_client! ice_cube (~> 0.6.13) instedd_telemetry! + intercom-rails io-console jquery-rails (~> 2.1.0) kaminari @@ -315,4 +318,4 @@ DEPENDENCIES uglifier (>= 1.0.3) BUNDLED WITH - 1.10.6 + 1.11.2 diff --git a/README.md b/README.md index 4839a9f..b5aab9c 100644 --- a/README.md +++ b/README.md @@ -64,3 +64,10 @@ To setup and run test, once the web container is running: $ docker-compose exec web bash root@web_1 $ rake ``` + +## Intercom + +Remindem supports Intercom as its CRM platform. To load the Intercom chat widget, simply start Remindem 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). +Remindem 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`. diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 744f326..b1b2b07 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,22 +1,29 @@ # Copyright (C) 2011-2012, InSTEDD -# +# # This file is part of Remindem. -# +# # Remindem is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# +# # Remindem is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with Remindem. If not, see . class HomeController < ApplicationController + after_filter :intercom_shutdown, :only => [:index] + def index add_body_class 'homepage' end + + protected + def intercom_shutdown + IntercomRails::ShutdownHelper.intercom_shutdown(session, cookies, request.domain) + end end \ No newline at end of file diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 0000000..8f2c06b --- /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 \ No newline at end of file diff --git a/config/initializers/intercom.rb b/config/initializers/intercom.rb new file mode 100644 index 0000000..051042e --- /dev/null +++ b/config/initializers/intercom.rb @@ -0,0 +1,116 @@ +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 + # } + + # == 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 22d85e0..0801054 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -29,7 +29,10 @@ scope "(:locale)", :locale => /#{Locales.available.keys.join('|')}/ do - devise_for :users, :controllers => {:registrations => 'users/registrations', omniauth_callbacks: "omniauth_callbacks" } do + devise_for :users, :controllers => { + :registrations => 'users/registrations', + omniauth_callbacks: "omniauth_callbacks", + :sessions => "sessions"} do get 'users/registrations/success', :to => 'users/registrations#success' end From 398de09e111eadff62dbaf76d4b3540aafa260e9 Mon Sep 17 00:00:00 2001 From: pmallol Date: Thu, 6 Dec 2018 16:03:44 -0300 Subject: [PATCH 2/3] Use user email as user id --- config/initializers/intercom.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/config/initializers/intercom.rb b/config/initializers/intercom.rb index 051042e..dc5e455 100644 --- a/config/initializers/intercom.rb +++ b/config/initializers/intercom.rb @@ -22,8 +22,8 @@ # 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 }] + 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 @@ -57,6 +57,9 @@ # :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, From ec5bddbcccfbfb0fec02f51c2085498aa2027b22 Mon Sep 17 00:00:00 2001 From: pmallol Date: Thu, 6 Dec 2018 16:04:38 -0300 Subject: [PATCH 3/3] Update README --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index b5aab9c..e633e8e 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,9 @@ root@web_1 $ rake ## Intercom Remindem supports Intercom as its CRM platform. To load the Intercom chat widget, simply start Remindem 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). + Remindem 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`.