intercom-rails 0.3.4 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ae61e5efdf193cc74b1176e5689e18ec2ceca704
4
- data.tar.gz: e5dfb686a1b287f254d6f4fa16f6a6c794f885d4
2
+ SHA256:
3
+ metadata.gz: 02ee9e097fd0d56647c686ee99951ffab111c4dbb557945724b2a0bc3fe4e5db
4
+ data.tar.gz: d07d7828811fc2efa8e9de4396d6209de92b6b094e70ea29d999a3c717620abf
5
5
  SHA512:
6
- metadata.gz: d8296981fcc1ce3cbbc916f8ba0d99ccf2689c19bc92e9d3b2496908f79de5202aceb8a3c14bf7e79bd367864295cb7a7737f853b70ea226c0c5094cd18b9e95
7
- data.tar.gz: 1b0b1c01a2de42adf788f684616d33ef7de2e147a8f3fe1392105f2619051c067fa337dcfe7cfc2f20fd5a7bb694810961d151405470c2f0de7f33942acd70fc
6
+ metadata.gz: e4549531a669d19d6d2dae37bbb46ed70771a7bc5b3c4541ee5b194679d335346278a5bb65e2256ae402e72eff417f17bee27b6ecb0e7039225a608240b27c56
7
+ data.tar.gz: 811c41ee91378ed52c256aa360d3f5c0bb01f44cdb18b617c3d8610f6b9ca1afcd54e6958525cbcbd4748c6116a3e90e61e2097de45363d00efde32f78033783
@@ -4,6 +4,8 @@ The easiest way to install Intercom in a rails app.
4
4
 
5
5
  For interacting with the Intercom REST API, use the `intercom` gem (https://github.com/intercom/intercom-ruby)
6
6
 
7
+ Requires Ruby 2.0 or higher.
8
+
7
9
  ## Installation
8
10
  Add this to your Gemfile:
9
11
 
@@ -17,7 +19,7 @@ Then run:
17
19
  bundle install
18
20
  ```
19
21
 
20
- Take note of your `app_id` from [here](https://app.intercom.io/a/apps/_/settings/api-keys) and generate a config file:
22
+ Take note of your `app_id` from [here](https://app.intercom.com/a/apps/_/settings/web) and generate a config file:
21
23
 
22
24
  ```
23
25
  rails generate intercom:config YOUR-APP-ID
@@ -26,9 +28,8 @@ rails generate intercom:config YOUR-APP-ID
26
28
  To make installing Intercom easy, where possible a `<script>` tag **will be automatically inserted before the closing `</body>` tag**. For most Rails apps, **you won't need to do any extra config**. Having trouble? Check out troubleshooting below.
27
29
 
28
30
 
29
- ### Live Chat / Acquire
30
- With our [Acquire package](https://www.intercom.io/live-chat), Intercom Messenger now works with logged out users and visitors to your web site. Include the Intercom snippet on every page by setting:
31
-
31
+ ### Live Chat
32
+ With the Intercom Messenger you can [chat](https://www.intercom.com/live-chat) with users and visitors to your web site. Include the Intercom Messenger on every page by setting:
32
33
  ```ruby
33
34
  config.include_for_logged_out_users = true
34
35
  ```
@@ -42,7 +43,7 @@ To disable automatic insertion for a particular controller or action you can:
42
43
  ```
43
44
 
44
45
  ### Troubleshooting
45
- If it's not working make sure:
46
+ If things are not working make sure that:
46
47
 
47
48
  * You've generated a config file with your `app_id` as detailed above.
48
49
  * Your user object responds to an `id` or `email` method.
@@ -50,37 +51,36 @@ If it's not working make sure:
50
51
  ```ruby
51
52
  config.user.current = Proc.new { current_user_object }
52
53
  ```
53
- If your users can be defined in different ways in your app you can also pass an array as follows :
54
+ If your users can be defined in different ways in your app you can also pass an array as follows:
54
55
  ```ruby
55
56
  config.user.current = [Proc.new { current_user_object }, Proc.new { @user_object }]
56
57
  ```
57
- * If you want the Intercom Messenger to be available when there is no current user, set `config.include_for_logged_out_users = true` in your config and sign up for the [Acquire](https://www.intercom.io/live-chat) package.
58
+ * If you want the Intercom Messenger to be available when there is no current user, set `config.include_for_logged_out_users = true` in your config.
58
59
 
59
- Feel free to mail us: team@intercom.io, if you're still having trouble.
60
+ Feel free to mail us: team@intercom.io, if you're still having trouble and we'll work with you to get you sorted.
60
61
 
61
62
  ## Configuration
62
63
 
63
64
  ### API Secret
64
- If you want to use secure mode, ensure you set your API secret in `config/initializers/intercom.rb`:
65
+ It is possible to enable Identity Verification for the Intercom Messenger and you can find the documentation in how to do it [here](https://developers.intercom.com/docs/enable-secure-mode-on-your-web-product). We strongly encourage doing this as it makes your installation more secure! If you want to use this feature, ensure you set your Identity Verification Secret as the API secret in `config/initializers/intercom.rb`:
65
66
 
66
67
  ```ruby
67
68
  config.api_secret = '123456'
68
69
  ```
69
- **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.**
70
- ### Shutdown
70
+ **Note: This example is just for the sake of simplicity, you should never include this 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.**
71
71
 
72
- 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.
73
- 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).
72
+ ### Shutdown
73
+ We make use of first-party cookies so that we can identify your users the next time they open your messenger. When people share devices with someone else, they might be able to see the most recently logged in user’s conversation history until the cookie expires. Because of this, it’s very important to properly shutdown Intercom when a user’s session on your app ends (either manually or due to an automated logout).
74
74
 
75
75
  #### Using Devise
76
76
 
77
- If you use devise, you can override (if not already done) the session_controller by replacing in your `config/routes.rb` file :
77
+ If you use devise, you can override (if not already done) the session_controller by replacing in your `config/routes.rb` file:
78
78
  ```ruby
79
79
  devise_for :users
80
80
  ```
81
- by
81
+ with
82
82
  ```ruby
83
- devise_for :users, controllers: {sessions: "sessions"}
83
+ devise_for :users, controllers: { sessions: "sessions" }
84
84
  ```
85
85
 
86
86
  Then you can use the following code to prepare Intercom Shutdown on log out in your `app/session_controller.rb`
@@ -114,7 +114,7 @@ class VisitorsController < ApplicationController
114
114
 
115
115
  protected
116
116
  def intercom_shutdown
117
- IntercomRails::ShutdownHelper.intercom_shutdown(session, cookies)
117
+ IntercomRails::ShutdownHelper.intercom_shutdown(session, cookies, request.domain)
118
118
  end
119
119
  end
120
120
  ```
@@ -124,7 +124,7 @@ end
124
124
  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.
125
125
 
126
126
  ```ruby
127
- IntercomRails::ShutdownHelper::intercom_shutdown_helper(cookies)
127
+ IntercomRails::ShutdownHelper::intercom_shutdown_helper(cookies, domain)
128
128
  ```
129
129
 
130
130
  **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.
@@ -379,13 +379,14 @@ You can do this using the [intercom-ruby](https://github.com/intercom/intercom-r
379
379
 
380
380
  ```
381
381
  class User
382
- after_destroy { DeleteFromIntercom.perform_later(self)
382
+ after_destroy { DeleteFromIntercomJob.perform_later(self) }
383
383
  end
384
384
 
385
- class DeleteFromIntercom < ApplicationJob
385
+ class DeleteFromIntercomJob < ApplicationJob
386
386
  def perform(user)
387
387
  intercom = Intercom::Client.new
388
- intercom.users.find(email: user.email).delete
388
+ user = intercom.users.find(id: user.id)
389
+ deleted_user = intercom.users.delete(user)
389
390
  end
390
391
  end
391
392
  ```
@@ -417,7 +418,7 @@ bundle exec rspec spec/
417
418
  - **Send coherent history**. Make sure each individual commit in your pull
418
419
  request is meaningful. If you had to make multiple intermediate commits while
419
420
  developing, please squash them before sending them to us.
420
-
421
+
421
422
 
422
423
  ## Contributors
423
424
 
@@ -430,4 +431,4 @@ intercom-rails is released under the [MIT License](http://www.opensource.org/lic
430
431
 
431
432
  ## Copyright
432
433
 
433
- Copyright (c) 2011-2012 Intercom, Inc. All rights reserved.
434
+ Copyright (c) 2011-2020 Intercom, Inc. All rights reserved.
@@ -3,6 +3,7 @@ require 'intercom-rails/date_helper'
3
3
  require 'intercom-rails/proxy'
4
4
  require 'intercom-rails/proxy/user'
5
5
  require 'intercom-rails/proxy/company'
6
+ require 'intercom-rails/encrypted_mode'
6
7
  require 'intercom-rails/script_tag'
7
8
  require 'intercom-rails/script_tag_helper'
8
9
  require 'intercom-rails/custom_data_helper'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module IntercomRails
2
4
 
3
5
  module AutoInclude
@@ -8,9 +10,8 @@ module IntercomRails
8
10
  end
9
11
 
10
12
  class Filter
11
-
12
- CLOSING_BODY_TAG = %r{</body>}
13
- BLACKLISTED_CONTROLLER_NAMES = ["Devise::PasswordsController"]
13
+ CLOSING_BODY_TAG = "</body>"
14
+ BLACKLISTED_CONTROLLER_NAMES = %w{ Devise::PasswordsController }
14
15
 
15
16
  def self.filter(controller)
16
17
  return if BLACKLISTED_CONTROLLER_NAMES.include?(controller.class.name)
@@ -32,9 +33,7 @@ module IntercomRails
32
33
  end
33
34
 
34
35
  def include_javascript!
35
- split = response.body.split("</body>")
36
- response.body = split.first + intercom_script_tag.to_s + "</body>"
37
- response.body = response.body + split.last if split.size > 1
36
+ response.body = response.body.insert(response.body.rindex(CLOSING_BODY_TAG), intercom_script_tag.to_s)
38
37
  end
39
38
 
40
39
  def include_javascript?
@@ -55,11 +54,15 @@ module IntercomRails
55
54
  end
56
55
 
57
56
  def html_content_type?
58
- response.content_type == 'text/html'
57
+ if response.respond_to?(:media_type)
58
+ response.media_type == 'text/html'
59
+ else
60
+ response.content_type == 'text/html'
61
+ end
59
62
  end
60
63
 
61
64
  def response_has_closing_body_tag?
62
- !!(response.body[CLOSING_BODY_TAG])
65
+ response.body.include? CLOSING_BODY_TAG
63
66
  end
64
67
 
65
68
  def intercom_script_tag_called_manually?
@@ -79,7 +82,7 @@ module IntercomRails
79
82
  nonce = CoreExtensions::IntercomRails::AutoInclude.csp_nonce_hook(controller)
80
83
  options.merge!(:nonce => nonce)
81
84
  end
82
- @script_tag = ScriptTag.new(options)
85
+ @script_tag ||= ScriptTag.new(options)
83
86
  end
84
87
 
85
88
  def show_everywhere?
@@ -108,6 +108,8 @@ module IntercomRails
108
108
  config_accessor :enabled_environments, &ARRAY_VALIDATOR
109
109
  config_accessor :include_for_logged_out_users
110
110
  config_accessor :hide_default_launcher
111
+ config_accessor :api_base
112
+ config_accessor :encrypted_mode
111
113
 
112
114
  def self.api_key=(*)
113
115
  warn "Setting an Intercom API key is no longer supported; remove the `config.api_key = ...` line from config/initializers/intercom.rb"
@@ -1,6 +1,7 @@
1
1
  module IntercomRails
2
2
 
3
3
  module CustomDataHelper
4
+ STORE = Struct.new(:user, :company)
4
5
 
5
6
  # This helper allows custom data attributes to be added to a user
6
7
  # for the current request from within the controller. e.g.
@@ -10,12 +11,7 @@ module IntercomRails
10
11
  # ...
11
12
  # end
12
13
  def intercom_custom_data
13
- @_request_specific_intercom_custom_data ||= begin
14
- s = Struct.new(:user, :company).new
15
- s.user = {}
16
- s.company = {}
17
- s
18
- end
14
+ @_request_specific_intercom_custom_data ||= STORE.new({}, {})
19
15
  end
20
16
 
21
17
  end
@@ -0,0 +1,34 @@
1
+ module IntercomRails
2
+ class EncryptedMode
3
+ attr_reader :secret, :initialization_vector, :enabled
4
+
5
+ ENCRYPTED_MODE_SETTINGS_WHITELIST = [:app_id, :session_duration, :widget, :custom_launcher_selector, :hide_default_launcher, :api_base, :alignment, :horizontal_padding, :vertical_padding]
6
+
7
+ def initialize(secret, initialization_vector, options)
8
+ @secret = secret
9
+ @initialization_vector = initialization_vector || SecureRandom.random_bytes(12)
10
+ @enabled = options.fetch(:enabled, false)
11
+ end
12
+
13
+ def plaintext_part(settings)
14
+ enabled ? settings.slice(*ENCRYPTED_MODE_SETTINGS_WHITELIST) : settings
15
+ end
16
+
17
+ def encrypted_javascript(payload)
18
+ enabled ? "window.intercomEncryptedPayload = \"#{encrypt(payload)}\";" : ""
19
+ end
20
+
21
+ def encrypt(payload)
22
+ return nil unless enabled
23
+ payload = payload.except(*ENCRYPTED_MODE_SETTINGS_WHITELIST)
24
+ key = Digest::SHA256.digest(secret)
25
+ cipher = OpenSSL::Cipher.new('aes-256-gcm')
26
+ cipher.encrypt
27
+ cipher.key = key
28
+ cipher.iv = initialization_vector
29
+ json = ActiveSupport::JSON.encode(payload).gsub('<', '\u003C')
30
+ encrypted = initialization_vector + cipher.update(json) + cipher.final + cipher.auth_tag
31
+ Base64.encode64(encrypted).gsub("\n", "\\n")
32
+ end
33
+ end
34
+ end
@@ -2,6 +2,7 @@ module IntercomRails
2
2
 
3
3
  class Error < StandardError; end
4
4
  class NoUserFoundError < Error; end
5
+ class ExcludedUserFoundError < Error; end
5
6
  class NoCompanyFoundError < Error; end
6
7
 
7
8
  end
@@ -31,11 +31,11 @@ module IntercomRails
31
31
  begin
32
32
  user_proxy = new(search_object.instance_eval(&potential_object), search_object)
33
33
  return user_proxy if user_proxy.valid?
34
+ raise ExcludedUserFoundError if user_proxy.excluded?
34
35
  rescue NameError
35
36
  next
36
37
  end
37
38
  end
38
-
39
39
  raise NoUserFoundError
40
40
  end
41
41
 
@@ -47,10 +47,14 @@ module IntercomRails
47
47
 
48
48
  def valid?
49
49
  return false if user.blank? || user.respond_to?(:new_record?) && user.new_record?
50
- return false if config.user.exclude_if.present? && config.user.exclude_if.call(user)
50
+ return false if excluded?
51
51
  identity_present?
52
52
  end
53
53
 
54
+ def excluded?
55
+ config.user.exclude_if.present? && config.user.exclude_if.call(user)
56
+ end
57
+
54
58
  end
55
59
 
56
60
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support/json'
2
4
  require 'active_support/core_ext/hash/indifferent_access'
3
5
  require 'active_support/core_ext/string/output_safety'
@@ -6,11 +8,18 @@ require 'action_view'
6
8
  module IntercomRails
7
9
 
8
10
  class ScriptTag
11
+ # Base64 regexp:
12
+ # - blocks of 4 [A-Za-z0-9+/]
13
+ # followed either by:
14
+ # - blocks of 2 [A-Za-z0-9+/] + '=='
15
+ # - blocks of 3 [A-Za-z0-9+/] + '='
16
+ NONCE_RE = %r{^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$}
9
17
 
10
18
  include ::ActionView::Helpers::JavaScriptHelper
19
+ include ::ActionView::Helpers::TagHelper
11
20
 
12
21
  attr_reader :user_details, :company_details, :show_everywhere, :session_duration
13
- attr_accessor :secret, :widget_options, :controller, :nonce
22
+ attr_accessor :secret, :widget_options, :controller, :nonce, :encrypted_mode_enabled, :encrypted_mode
14
23
 
15
24
  def initialize(options = {})
16
25
  self.secret = options[:secret] || Config.api_secret
@@ -20,18 +29,22 @@ module IntercomRails
20
29
  @session_duration = session_duration_from_config
21
30
  self.user_details = options[:find_current_user_details] ? find_current_user_details : options[:user_details]
22
31
 
32
+ self.encrypted_mode_enabled = options[:encrypted_mode] || Config.encrypted_mode
33
+ self.encrypted_mode = IntercomRails::EncryptedMode.new(secret, options[:initialization_vector], {:enabled => encrypted_mode_enabled})
34
+
23
35
  # Request specific custom data for non-signed up users base on lead_attributes
24
36
  self.user_details = self.user_details.merge(find_lead_attributes)
25
37
 
26
38
  self.company_details = if options[:find_current_company_details]
27
39
  find_current_company_details
28
40
  elsif options[:user_details]
29
- options[:user_details].delete(:company) if options[:user_details]
41
+ options[:user_details].delete(:company)
30
42
  end
31
43
  self.nonce = options[:nonce]
32
44
  end
33
45
 
34
46
  def valid?
47
+ return false if user_details[:excluded_user] == true
35
48
  valid = user_details[:app_id].present?
36
49
  unless @show_everywhere
37
50
  valid = valid && (user_details[:user_id] || user_details[:email]).present?
@@ -42,21 +55,14 @@ module IntercomRails
42
55
  valid
43
56
  end
44
57
 
45
- def valid_nonce?
46
- valid = false
47
- if nonce
48
- # Base64 regexp:
49
- # - blocks of 4 [A-Za-z0-9+/]
50
- # followed either by:
51
- # - blocks of 2 [A-Za-z0-9+/] + '=='
52
- # - blocks of 3 [A-Za-z0-9+/] + '='
53
- base64_regexp = Regexp.new('^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$')
54
- m = base64_regexp.match(nonce)
55
- if nonce == m.to_s
56
- valid = true
57
- end
58
+ if //.respond_to?(:match?)
59
+ def valid_nonce?
60
+ nonce && NONCE_RE.match?(nonce)
61
+ end
62
+ else
63
+ def valid_nonce?
64
+ nonce && !!NONCE_RE.match(nonce)
58
65
  end
59
- valid
60
66
  end
61
67
 
62
68
  def intercom_settings
@@ -65,16 +71,14 @@ module IntercomRails
65
71
  hsh[:widget] = widget_options if widget_options.present?
66
72
  hsh[:company] = company_details if company_details.present?
67
73
  hsh[:hide_default_launcher] = Config.hide_default_launcher if Config.hide_default_launcher
74
+ hsh[:api_base] = Config.api_base if Config.api_base
68
75
  hsh
69
76
  end
70
77
 
71
78
  def to_s
72
- js_options = 'id="IntercomSettingsScriptTag"'
73
- if nonce && valid_nonce?
74
- js_options = js_options + " nonce=\"#{nonce}\""
75
- end
76
- str = "<script #{js_options}>#{intercom_javascript}</script>\n"
77
- str.respond_to?(:html_safe) ? str.html_safe : str
79
+ html_options = { id: 'IntercomSettingsScriptTag' }
80
+ html_options['nonce'] = nonce if valid_nonce?
81
+ javascript_tag(intercom_javascript, html_options) + "\n"
78
82
  end
79
83
 
80
84
  def csp_sha256
@@ -93,13 +97,21 @@ module IntercomRails
93
97
  custom_data.select {|k, v| lead_attributes.map(&:to_s).include?(k)}
94
98
  end
95
99
 
100
+ def plaintext_settings
101
+ encrypted_mode.plaintext_part(intercom_settings)
102
+ end
103
+
104
+ def encrypted_settings
105
+ encrypted_mode.encrypt(intercom_settings)
106
+ end
107
+
96
108
  private
97
- def intercom_javascript
98
- intercom_settings_json = ActiveSupport::JSON.encode(intercom_settings).gsub('<', '\u003C')
99
109
 
100
- str = "window.intercomSettings = #{intercom_settings_json};(function(){var w=window;var ic=w.Intercom;if(typeof ic===\"function\"){ic('reattach_activator');ic('update',intercomSettings);}else{var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args){i.q.push(args)};w.Intercom=i;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='#{Config.library_url || "https://widget.intercom.io/widget/#{j app_id}"}';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}};})()"
110
+ def intercom_javascript
111
+ plaintext_javascript = ActiveSupport::JSON.encode(plaintext_settings).gsub('<', '\u003C')
112
+ intercom_encrypted_payload_javascript = encrypted_mode.encrypted_javascript(intercom_settings)
101
113
 
102
- str
114
+ "window.intercomSettings = #{plaintext_javascript};#{intercom_encrypted_payload_javascript}(function(){var w=window;var ic=w.Intercom;if(typeof ic===\"function\"){ic('reattach_activator');ic('update',intercomSettings);}else{var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args){i.q.push(args)};w.Intercom=i;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='#{Config.library_url || "https://widget.intercom.io/widget/#{j app_id}"}';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}};})()"
103
115
  end
104
116
 
105
117
  def user_details=(user_details)
@@ -117,6 +129,10 @@ module IntercomRails
117
129
  Proxy::User.current_in_context(controller).to_hash
118
130
  rescue NoUserFoundError
119
131
  {}
132
+ rescue ExcludedUserFoundError
133
+ {
134
+ excluded_user: true
135
+ }
120
136
  end
121
137
 
122
138
  def company_details=(company_details)
@@ -5,14 +5,14 @@ module IntercomRails
5
5
  # Generate an intercom script tag.
6
6
  #
7
7
  # @param user_details [Hash] a customizable hash of user details
8
- # @param options [Hash] an optional hash for secure mode and widget customisation
8
+ # @param options [Hash] an optional hash for Identity Verification and widget customization
9
9
  # @option user_details [String] :app_id Your application id
10
10
  # @option user_details [String] :user_id unique id of this user within your application
11
11
  # @option user_details [String] :email email address for this user
12
12
  # @option user_details [String] :name the users name, _optional_ but useful for identify people in the Intercom App.
13
13
  # @option user_details [Hash] :custom_data custom attributes you'd like saved for this user on Intercom.
14
14
  # @option options [String] :widget a hash containing a css selector for an element which when clicked should show the Intercom widget
15
- # @option options [String] :secret Your app secret for secure mode
15
+ # @option options [String] :secret Your app secret for Identity Verification
16
16
  # @option options [String] :nonce a nonce generated by your CSP framework to be included inside the javascript tag
17
17
  # @return [String] Intercom script tag
18
18
  # @example basic example
@@ -2,15 +2,17 @@ module IntercomRails
2
2
  module ShutdownHelper
3
3
  # This helper allows to erase cookies when a user log out of an application
4
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
5
  # Do not use before a redirect_to because it will not clear the cookies on a redirection
7
- def self.intercom_shutdown_helper(cookies)
6
+ def self.intercom_shutdown_helper(cookies, domain = nil)
7
+ nil_session = { value: nil, expires: 1.day.ago }
8
+ nil_session = nil_session.merge(domain: domain) unless domain.nil? || domain == 'localhost'
9
+
8
10
  if (cookies.is_a?(ActionDispatch::Cookies::CookieJar))
9
- cookies["intercom-session-#{IntercomRails.config.app_id}"] = { value: nil, expires: 1.day.ago}
11
+ cookies["intercom-session-#{IntercomRails.config.app_id}"] = nil_session
10
12
  else
11
13
  controller = cookies
12
14
  Rails.logger.info("Warning: IntercomRails::ShutdownHelper.intercom_shutdown_helper takes an instance of ActionDispatch::Cookies::CookieJar as an argument since v0.2.34. Passing a controller is depreciated. See https://github.com/intercom/intercom-rails#shutdown for more details.")
13
- controller.response.delete_cookie("intercom-session-#{IntercomRails.config.app_id}", { value: nil, expires: 1.day.ago})
15
+ controller.response.delete_cookie("intercom-session-#{IntercomRails.config.app_id}", nil_session)
14
16
  end
15
17
  rescue
16
18
  end
@@ -19,10 +21,10 @@ module IntercomRails
19
21
  session[:perform_intercom_shutdown] = true
20
22
  end
21
23
 
22
- def self.intercom_shutdown(session, cookies)
24
+ def self.intercom_shutdown(session, cookies, domain = nil)
23
25
  if session[:perform_intercom_shutdown]
24
26
  session.delete(:perform_intercom_shutdown)
25
- intercom_shutdown_helper(cookies)
27
+ intercom_shutdown_helper(cookies, domain)
26
28
  end
27
29
  end
28
30
 
@@ -1,3 +1,3 @@
1
1
  module IntercomRails
2
- VERSION = "0.3.4"
2
+ VERSION = "0.4.2"
3
3
  end
@@ -7,7 +7,7 @@ module Intercom
7
7
  end
8
8
 
9
9
  argument :app_id, :desc => "Your Intercom app-id, which can be found here: https://app.intercom.io/apps/api_keys"
10
- argument :api_secret, :desc => "Your Intercom api-secret, used for secure mode", :optional => true
10
+ argument :api_secret, :desc => "Your Intercom api-secret, used for Identity Verification", :optional => true
11
11
  argument :session_duration, :desc => "user session duration, this should match your app", :optional => true
12
12
 
13
13
  FALSEY_RESPONSES = ['n', 'no']
@@ -11,8 +11,8 @@ IntercomRails.config do |config|
11
11
  # config.session_duration = 300000
12
12
  <%- end -%>
13
13
  # == Intercom secret key
14
- # This is required to enable secure mode, you can find it on your Setup
15
- # guide in the "Secure Mode" step.
14
+ # This is required to enable Identity Verification, you can find it on your Setup
15
+ # guide in the "Identity Verification" step.
16
16
  #
17
17
  <%- if @api_secret -%>
18
18
  config.api_secret = "<%= @api_secret %>"
@@ -38,7 +38,7 @@ IntercomRails.config do |config|
38
38
 
39
39
  # == Include for logged out Users
40
40
  # If set to true, include the Intercom messenger on all pages, regardless of whether
41
- # The user model class (set below) is present. Only available for Apps on the Acquire plan.
41
+ # The user model class (set below) is present.
42
42
  <%- if @include_for_logged_out_users -%>
43
43
  config.include_for_logged_out_users = true
44
44
  <%- else -%>
@@ -127,4 +127,8 @@ IntercomRails.config do |config|
127
127
  #
128
128
  # If you'd like to hide default launcher button uncomment this line
129
129
  # config.hide_default_launcher = true
130
+ #
131
+ # If you need to route your Messenger requests through a different endpoint than the default, uncomment the below line. Generally speaking, this is not needed.
132
+ # config.api_base = "https://#{config.app_id}.intercom-messenger.com"
133
+ #
130
134
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: intercom-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben McRedmond
8
8
  - Ciaran Lee
9
9
  - Darragh Curran
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-10-24 00:00:00.000000000 Z
13
+ date: 2020-10-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -163,7 +163,7 @@ executables: []
163
163
  extensions: []
164
164
  extra_rdoc_files: []
165
165
  files:
166
- - README.mdown
166
+ - README.md
167
167
  - Rakefile
168
168
  - lib/data/cacert.pem
169
169
  - lib/intercom-rails.rb
@@ -171,6 +171,7 @@ files:
171
171
  - lib/intercom-rails/config.rb
172
172
  - lib/intercom-rails/custom_data_helper.rb
173
173
  - lib/intercom-rails/date_helper.rb
174
+ - lib/intercom-rails/encrypted_mode.rb
174
175
  - lib/intercom-rails/exceptions.rb
175
176
  - lib/intercom-rails/proxy.rb
176
177
  - lib/intercom-rails/proxy/company.rb
@@ -186,7 +187,7 @@ homepage: http://www.intercom.io
186
187
  licenses:
187
188
  - MIT
188
189
  metadata: {}
189
- post_install_message:
190
+ post_install_message:
190
191
  rdoc_options: []
191
192
  require_paths:
192
193
  - lib
@@ -201,10 +202,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
202
  - !ruby/object:Gem::Version
202
203
  version: '0'
203
204
  requirements: []
204
- rubyforge_project: intercom-rails
205
- rubygems_version: 2.4.8
206
- signing_key:
205
+ rubygems_version: 3.0.4
206
+ signing_key:
207
207
  specification_version: 4
208
208
  summary: Rails helper for emitting javascript script tags for Intercom
209
209
  test_files: []
210
- has_rdoc: