intercom-rails 0.2.31 → 0.2.33
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.mdown +42 -8
- data/lib/intercom-rails.rb +1 -0
- data/lib/intercom-rails/config.rb +1 -0
- data/lib/intercom-rails/script_tag.rb +14 -1
- data/lib/intercom-rails/shutdown_helper.rb +11 -0
- data/lib/intercom-rails/version.rb +1 -1
- data/lib/rails/generators/intercom/config/config_generator.rb +2 -0
- data/lib/rails/generators/intercom/config/intercom.rb.erb +10 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03b50b1d5b763f0ef0a553e7d72d8daa1a3cd412
|
4
|
+
data.tar.gz: 4aacec38fd8a8696f56ee130487b9519959ea946
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d80bc1ade277f6ea62376c67abd0185c30e9730fe2ba19b3132afb193229c3cbda4128e5d51566fa0a2a8adcdc0da975444651b52851f9717ce7ed313e7e728
|
7
|
+
data.tar.gz: 1a7bb15f5946f704f24a33007eda1dc19757bc78b7389c99c0f51dcb80665a73ab57f7717a5e8703338373ddfff783dd11363a12cd739623cdf659353b6237bf
|
data/README.mdown
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# IntercomRails
|
2
2
|
|
3
|
+
[![Join the chat at https://gitter.im/intercom/intercom-rails](https://badges.gitter.im/intercom/intercom-rails.svg)](https://gitter.im/intercom/intercom-rails?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
4
|
+
|
3
5
|
The easiest way to install Intercom in a rails app.
|
4
6
|
|
5
7
|
For interacting with the Intercom REST API, use the `intercom` gem (https://github.com/intercom/intercom-ruby)
|
@@ -54,8 +56,44 @@ If you want to use secure mode, ensure you set your API secret in `config/initia
|
|
54
56
|
```ruby
|
55
57
|
config.api_secret = '123456'
|
56
58
|
```
|
59
|
+
**Note: This example is just for the sake of simplicity, you should never include your api secret in source control. Instead, you should use the Rails [secret config](http://guides.rubyonrails.org/4_1_release_notes.html#config-secrets-yml) feature.**
|
60
|
+
### Shutdown
|
61
|
+
|
62
|
+
If you use Intercom Acquire combined with another product like Support, Learn or Engage, any user that uses a shared computer and browser with someone else will be able to see the most recently logged in user’s conversation history until the cookie expires.
|
63
|
+
Because of this, it’s very important to properly shutdown Intercom when a user’s session on your app ends (via manually or automatically logging out).
|
64
|
+
|
65
|
+
#### Using Devise
|
66
|
+
|
67
|
+
If your Rails application uses devise for authentication, you simply need to add the following line in your "config/initializers/session_store.rb" :
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
Rails.application.config.session_store :cookie_store, key: 'intercom-session-' + IntercomRails.config.app_id
|
71
|
+
```
|
72
|
+
|
73
|
+
You should not modify or remove existing configurations in this file.
|
74
|
+
|
75
|
+
#### Using another service
|
76
|
+
|
77
|
+
If you use another service than Devise or if you implemented your own authentication service, you can call the following method in a controller to shutdown Intercom on logout (self being the controller instance).
|
78
|
+
**Be aware that if you call this method before a 'redirect_to' (quite common on logout) it will have no impact** as it is impossible to update cookies when you use a redirection.
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
IntercomRails::ShutdownHelper::intercom_shutdown_helper(self)
|
82
|
+
```
|
83
|
+
|
84
|
+
#### Session Duration
|
85
|
+
|
86
|
+
To add a `session_duration` variable (in ms) to the widget, add the following line to `config/initializers/intercom.rb`:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
config.session_duration = 5 * 60 * 1000
|
90
|
+
```
|
91
|
+
That will force your Intercom session to expire after 5 minutes which is the minimum amount of time authorized.
|
92
|
+
|
93
|
+
More information about how session_duration works in [intercom documentation](https://docs.intercom.io/configuring-for-your-product-or-site/customizing-the-intercom-messenger#secure-user-conversations-configure-your-cookie-timeout)
|
57
94
|
|
58
95
|
### User Custom data attributes
|
96
|
+
|
59
97
|
You can associate any attributes, specific to your app, with a user in Intercom.
|
60
98
|
For custom data attributes you want updated on every request set them in `config/initializers/intercom.rb`, the latest value will be sent to Intercom on each page visit.
|
61
99
|
|
@@ -106,6 +144,10 @@ Basic usage is as follows - in `config/initializers/intercom.rb`
|
|
106
144
|
config.company.current = Proc.new { current_company }
|
107
145
|
```
|
108
146
|
|
147
|
+
`current_company` is the method/variable that contains the user's current company in your controllers.
|
148
|
+
If you are using devise you should replace `current_company` with `current_user.company` in the above code and every time you see 'current_company' in your configuration file.
|
149
|
+
This will result in injecting the user current company in the widget settings.
|
150
|
+
|
109
151
|
and like with Users, you can set custom attribute on companies too:
|
110
152
|
|
111
153
|
```ruby
|
@@ -247,14 +289,6 @@ The SHA-256 hash is available using `csp_sha256` just after generating the tag i
|
|
247
289
|
<%= intercom_script_tag %>
|
248
290
|
<% add_entry_to_csp_whitelist(intercom_script_tag.csp_sha256) %>
|
249
291
|
```
|
250
|
-
## Importing your users
|
251
|
-
To get started faster with Intercom, `IntercomRails` includes a Rake task that will do an initial import of your users:
|
252
|
-
|
253
|
-
```
|
254
|
-
rake intercom:import
|
255
|
-
```
|
256
|
-
|
257
|
-
Any custom data defined in `config/initializers/intercom.rb` will also be sent.
|
258
292
|
|
259
293
|
## Running tests/specs
|
260
294
|
|
data/lib/intercom-rails.rb
CHANGED
@@ -6,6 +6,7 @@ require 'intercom-rails/proxy/company'
|
|
6
6
|
require 'intercom-rails/script_tag'
|
7
7
|
require 'intercom-rails/script_tag_helper'
|
8
8
|
require 'intercom-rails/custom_data_helper'
|
9
|
+
require 'intercom-rails/shutdown_helper'
|
9
10
|
require 'intercom-rails/auto_include_filter'
|
10
11
|
require 'intercom-rails/config'
|
11
12
|
require 'intercom-rails/import'
|
@@ -9,7 +9,7 @@ module IntercomRails
|
|
9
9
|
|
10
10
|
include ::ActionView::Helpers::JavaScriptHelper
|
11
11
|
|
12
|
-
attr_reader :user_details, :company_details, :show_everywhere
|
12
|
+
attr_reader :user_details, :company_details, :show_everywhere, :session_duration
|
13
13
|
attr_accessor :secret, :widget_options, :controller, :nonce
|
14
14
|
|
15
15
|
def initialize(options = {})
|
@@ -17,6 +17,7 @@ module IntercomRails
|
|
17
17
|
self.widget_options = widget_options_from_config.merge(options[:widget] || {})
|
18
18
|
self.controller = options[:controller]
|
19
19
|
@show_everywhere = options[:show_everywhere]
|
20
|
+
@session_duration = session_duration_from_config
|
20
21
|
self.user_details = options[:find_current_user_details] ? find_current_user_details : options[:user_details]
|
21
22
|
self.company_details = if options[:find_current_company_details]
|
22
23
|
find_current_company_details
|
@@ -56,6 +57,7 @@ module IntercomRails
|
|
56
57
|
|
57
58
|
def intercom_settings
|
58
59
|
hsh = user_details
|
60
|
+
hsh[:session_duration] = @session_duration if @session_duration.present?
|
59
61
|
hsh[:widget] = widget_options if widget_options.present?
|
60
62
|
hsh[:company] = company_details if company_details.present?
|
61
63
|
hsh
|
@@ -121,6 +123,17 @@ module IntercomRails
|
|
121
123
|
OpenSSL::HMAC.hexdigest("sha256", secret, (user_details[:user_id] || user_details[:email]).to_s)
|
122
124
|
end
|
123
125
|
|
126
|
+
def session_duration_from_config
|
127
|
+
session_duration = IntercomRails.config.session_duration
|
128
|
+
if session_duration && valid_session_duration?(session_duration)
|
129
|
+
session_duration
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def valid_session_duration?(session_duration)
|
134
|
+
session_duration.is_a?(Integer) && session_duration > 0
|
135
|
+
end
|
136
|
+
|
124
137
|
def app_id
|
125
138
|
return user_details[:app_id] if user_details[:app_id].present?
|
126
139
|
return IntercomRails.config.app_id if IntercomRails.config.app_id.present?
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module IntercomRails
|
2
|
+
module ShutdownHelper
|
3
|
+
# This helper allows to erase cookies when a user log out of an application
|
4
|
+
# It is recommanded to call this function every time a user log out of your application
|
5
|
+
# specifically if you use both "Acquire" and another Intercom product
|
6
|
+
# Do not use before a redirect_to because it will not clear the cookies on a redirection
|
7
|
+
def self.intercom_shutdown_helper (controller)
|
8
|
+
controller.response.delete_cookie("intercom-session-#{IntercomRails.config.app_id}")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -9,12 +9,14 @@ module Intercom
|
|
9
9
|
argument :app_id, :desc => "Your Intercom app-id, which can be found here: https://app.intercom.io/apps/api_keys"
|
10
10
|
argument :api_secret, :desc => "Your Intercom api-secret, used for secure mode", :optional => true
|
11
11
|
argument :api_key, :desc => "An Intercom API key, for various rake tasks", :optional => true
|
12
|
+
argument :session_duration, :desc => "user session duration, this should match your app", :optional => true
|
12
13
|
|
13
14
|
FALSEY_RESPONSES = ['n', 'no']
|
14
15
|
def create_config_file
|
15
16
|
@app_id = app_id
|
16
17
|
@api_secret = api_secret
|
17
18
|
@api_key = api_key
|
19
|
+
@session_duration = session_duration
|
18
20
|
@include_for_logged_out_users = false
|
19
21
|
|
20
22
|
introduction = <<-desc
|
@@ -3,6 +3,10 @@ IntercomRails.config do |config|
|
|
3
3
|
#
|
4
4
|
config.app_id = ENV["INTERCOM_APP_ID"] || "<%= @app_id %>"
|
5
5
|
|
6
|
+
# == Intercom session_duration
|
7
|
+
#
|
8
|
+
config.session_duration = <%= @session_duration %>
|
9
|
+
|
6
10
|
# == Intercom secret key
|
7
11
|
# This is required to enable secure mode, you can find it on your Setup
|
8
12
|
# guide in the "Secure Mode" step.
|
@@ -71,6 +75,7 @@ IntercomRails.config do |config|
|
|
71
75
|
# == User -> Company association
|
72
76
|
# A Proc that given a user returns an array of companies
|
73
77
|
# that the user belongs to.
|
78
|
+
# This is only used for importing users using rake command but it will not inject a list of companies in the intercom widget
|
74
79
|
#
|
75
80
|
# config.user.company_association = Proc.new { |user| user.companies.to_a }
|
76
81
|
# config.user.company_association = Proc.new { |user| [user.company] }
|
@@ -81,6 +86,11 @@ IntercomRails.config do |config|
|
|
81
86
|
# could be a company, app or group.
|
82
87
|
#
|
83
88
|
# config.company.current = Proc.new { current_company }
|
89
|
+
#
|
90
|
+
# Or if you are using devise you can just use the following config
|
91
|
+
#
|
92
|
+
# config.company.current = Proc.new { current_user.company }
|
93
|
+
|
84
94
|
|
85
95
|
# == Company Custom Data
|
86
96
|
# A hash of additional data you wish to send about a company.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: intercom-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.33
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben McRedmond
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-
|
13
|
+
date: 2016-04-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -180,11 +180,13 @@ files:
|
|
180
180
|
- lib/intercom-rails/railtie.rb
|
181
181
|
- lib/intercom-rails/script_tag.rb
|
182
182
|
- lib/intercom-rails/script_tag_helper.rb
|
183
|
+
- lib/intercom-rails/shutdown_helper.rb
|
183
184
|
- lib/intercom-rails/version.rb
|
184
185
|
- lib/rails/generators/intercom/config/config_generator.rb
|
185
186
|
- lib/rails/generators/intercom/config/intercom.rb.erb
|
186
187
|
homepage: http://www.intercom.io
|
187
|
-
licenses:
|
188
|
+
licenses:
|
189
|
+
- MIT
|
188
190
|
metadata: {}
|
189
191
|
post_install_message:
|
190
192
|
rdoc_options: []
|
@@ -202,7 +204,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
202
204
|
version: '0'
|
203
205
|
requirements: []
|
204
206
|
rubyforge_project: intercom-rails
|
205
|
-
rubygems_version: 2.
|
207
|
+
rubygems_version: 2.2.3
|
206
208
|
signing_key:
|
207
209
|
specification_version: 4
|
208
210
|
summary: Rails helper for emitting javascript script tags for Intercom
|