Skip to content

Add Intercom #349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.0-p353
2.0.0
21 changes: 15 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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=


1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 4 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -377,6 +379,7 @@ DEPENDENCIES
instedd-bootstrap!
instedd-pigeon!
instedd_telemetry!
intercom-rails
jquery-rails
listings
machinist
Expand Down Expand Up @@ -406,4 +409,4 @@ DEPENDENCIES
underscore-rails

BUNDLED WITH
1.10.6
1.11.2
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,13 @@ root@web_1 $ rake
powered by capistrano. `$ HOSTS=<server> 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`.
7 changes: 7 additions & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -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
119 changes: 119 additions & 0 deletions config/initializers/intercom.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions docker-compose.ci.yml
Original file line number Diff line number Diff line change
@@ -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: