intercom-rails 0.4.1 → 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
2
  SHA256:
3
- metadata.gz: ff3876d40d57f39f1867e5a85924bb95b37881f0f412f55d62b6aaafdd4bd137
4
- data.tar.gz: 57411d70e56d4aca7ec19c8e99f891527819c8d878ca8354de7d9750f8b48bae
3
+ metadata.gz: 02ee9e097fd0d56647c686ee99951ffab111c4dbb557945724b2a0bc3fe4e5db
4
+ data.tar.gz: d07d7828811fc2efa8e9de4396d6209de92b6b094e70ea29d999a3c717620abf
5
5
  SHA512:
6
- metadata.gz: 3baa59dfce787f287e1442da9cbc63d9d564e720cf445a930dfe7c1351cfd5982b46184af342e51454a034910e6966487b7c0029db495e3018bb63c2ddba25bb
7
- data.tar.gz: f2f35de9546ef409652ef7956161eb05ad5798c23808b8320764e49519648c5f0aa0b01ee276efc98f2f0982bd0e5dfc3036910d4b97c574ff2a7f8900904d08
6
+ metadata.gz: e4549531a669d19d6d2dae37bbb46ed70771a7bc5b3c4541ee5b194679d335346278a5bb65e2256ae402e72eff417f17bee27b6ecb0e7039225a608240b27c56
7
+ data.tar.gz: 811c41ee91378ed52c256aa360d3f5c0bb01f44cdb18b617c3d8610f6b9ca1afcd54e6958525cbcbd4748c6116a3e90e61e2097de45363d00efde32f78033783
data/README.md CHANGED
@@ -4,7 +4,7 @@ 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 for `intercom-rails >= 0.4.0`
7
+ Requires Ruby 2.0 or higher.
8
8
 
9
9
  ## Installation
10
10
  Add this to your Gemfile:
@@ -19,7 +19,7 @@ Then run:
19
19
  bundle install
20
20
  ```
21
21
 
22
- 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:
23
23
 
24
24
  ```
25
25
  rails generate intercom:config YOUR-APP-ID
@@ -43,7 +43,7 @@ To disable automatic insertion for a particular controller or action you can:
43
43
  ```
44
44
 
45
45
  ### Troubleshooting
46
- If it's not working make sure:
46
+ If things are not working make sure that:
47
47
 
48
48
  * You've generated a config file with your `app_id` as detailed above.
49
49
  * Your user object responds to an `id` or `email` method.
@@ -51,18 +51,18 @@ If it's not working make sure:
51
51
  ```ruby
52
52
  config.user.current = Proc.new { current_user_object }
53
53
  ```
54
- 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:
55
55
  ```ruby
56
56
  config.user.current = [Proc.new { current_user_object }, Proc.new { @user_object }]
57
57
  ```
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 and sign up for the [Inbox](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.
59
59
 
60
- 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.
61
61
 
62
62
  ## Configuration
63
63
 
64
64
  ### API Secret
65
- It is possible to enable Identity Verification for the Intercom Messenger and you can find the documentation in how to [here](https://developers.intercom.com/docs/enable-secure-mode-on-your-web-product). If you want to use this feature, ensure you set your Identity Verification Secret as the 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`:
66
66
 
67
67
  ```ruby
68
68
  config.api_secret = '123456'
@@ -70,19 +70,17 @@ It is possible to enable Identity Verification for the Intercom Messenger and yo
70
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
72
  ### Shutdown
73
-
74
- If you use Intercom Inbox combined with another product like Messages, 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.
75
- 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).
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).
76
74
 
77
75
  #### Using Devise
78
76
 
79
- 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:
80
78
  ```ruby
81
79
  devise_for :users
82
80
  ```
83
- by
81
+ with
84
82
  ```ruby
85
- devise_for :users, controllers: {sessions: "sessions"}
83
+ devise_for :users, controllers: { sessions: "sessions" }
86
84
  ```
87
85
 
88
86
  Then you can use the following code to prepare Intercom Shutdown on log out in your `app/session_controller.rb`
@@ -381,10 +379,10 @@ You can do this using the [intercom-ruby](https://github.com/intercom/intercom-r
381
379
 
382
380
  ```
383
381
  class User
384
- after_destroy { DeleteFromIntercom.perform_later(self)
382
+ after_destroy { DeleteFromIntercomJob.perform_later(self) }
385
383
  end
386
384
 
387
- class DeleteFromIntercom < ApplicationJob
385
+ class DeleteFromIntercomJob < ApplicationJob
388
386
  def perform(user)
389
387
  intercom = Intercom::Client.new
390
388
  user = intercom.users.find(id: user.id)
@@ -433,4 +431,4 @@ intercom-rails is released under the [MIT License](http://www.opensource.org/lic
433
431
 
434
432
  ## Copyright
435
433
 
436
- Copyright (c) 2011-2012 Intercom, Inc. All rights reserved.
434
+ Copyright (c) 2011-2020 Intercom, Inc. All rights reserved.
@@ -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?
@@ -63,7 +62,7 @@ module IntercomRails
63
62
  end
64
63
 
65
64
  def response_has_closing_body_tag?
66
- !!(response.body[CLOSING_BODY_TAG])
65
+ response.body.include? CLOSING_BODY_TAG
67
66
  end
68
67
 
69
68
  def intercom_script_tag_called_manually?
@@ -83,7 +82,7 @@ module IntercomRails
83
82
  nonce = CoreExtensions::IntercomRails::AutoInclude.csp_nonce_hook(controller)
84
83
  options.merge!(:nonce => nonce)
85
84
  end
86
- @script_tag = ScriptTag.new(options)
85
+ @script_tag ||= ScriptTag.new(options)
87
86
  end
88
87
 
89
88
  def show_everywhere?
@@ -108,6 +108,7 @@ 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
111
112
  config_accessor :encrypted_mode
112
113
 
113
114
  def self.api_key=(*)
@@ -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
@@ -2,7 +2,7 @@ module IntercomRails
2
2
  class EncryptedMode
3
3
  attr_reader :secret, :initialization_vector, :enabled
4
4
 
5
- ENCRYPTED_MODE_SETTINGS_WHITELIST = [:app_id, :session_duration, :widget, :custom_launcher_selector, :hide_default_launcher, :alignment, :horizontal_padding, :vertical_padding]
5
+ ENCRYPTED_MODE_SETTINGS_WHITELIST = [:app_id, :session_duration, :widget, :custom_launcher_selector, :hide_default_launcher, :api_base, :alignment, :horizontal_padding, :vertical_padding]
6
6
 
7
7
  def initialize(secret, initialization_vector, options)
8
8
  @secret = secret
@@ -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,8 +8,15 @@ 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
22
  attr_accessor :secret, :widget_options, :controller, :nonce, :encrypted_mode_enabled, :encrypted_mode
@@ -46,21 +55,14 @@ module IntercomRails
46
55
  valid
47
56
  end
48
57
 
49
- def valid_nonce?
50
- valid = false
51
- if nonce
52
- # Base64 regexp:
53
- # - blocks of 4 [A-Za-z0-9+/]
54
- # followed either by:
55
- # - blocks of 2 [A-Za-z0-9+/] + '=='
56
- # - blocks of 3 [A-Za-z0-9+/] + '='
57
- base64_regexp = Regexp.new('^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$')
58
- m = base64_regexp.match(nonce)
59
- if nonce == m.to_s
60
- valid = true
61
- 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)
62
65
  end
63
- valid
64
66
  end
65
67
 
66
68
  def intercom_settings
@@ -69,16 +71,14 @@ module IntercomRails
69
71
  hsh[:widget] = widget_options if widget_options.present?
70
72
  hsh[:company] = company_details if company_details.present?
71
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
72
75
  hsh
73
76
  end
74
77
 
75
78
  def to_s
76
- js_options = 'id="IntercomSettingsScriptTag"'
77
- if nonce && valid_nonce?
78
- js_options = js_options + " nonce=\"#{nonce}\""
79
- end
80
- str = "<script #{js_options}>#{intercom_javascript}</script>\n"
81
- 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"
82
82
  end
83
83
 
84
84
  def csp_sha256
@@ -111,9 +111,7 @@ module IntercomRails
111
111
  plaintext_javascript = ActiveSupport::JSON.encode(plaintext_settings).gsub('<', '\u003C')
112
112
  intercom_encrypted_payload_javascript = encrypted_mode.encrypted_javascript(intercom_settings)
113
113
 
114
- str = "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);}};})()"
115
-
116
- 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);}};})()"
117
115
  end
118
116
 
119
117
  def user_details=(user_details)
@@ -1,3 +1,3 @@
1
1
  module IntercomRails
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
@@ -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.4.1
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: 2019-08-06 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
@@ -187,7 +187,7 @@ homepage: http://www.intercom.io
187
187
  licenses:
188
188
  - MIT
189
189
  metadata: {}
190
- post_install_message:
190
+ post_install_message:
191
191
  rdoc_options: []
192
192
  require_paths:
193
193
  - lib
@@ -202,9 +202,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
202
  - !ruby/object:Gem::Version
203
203
  version: '0'
204
204
  requirements: []
205
- rubyforge_project: intercom-rails
206
- rubygems_version: 2.7.6.2
207
- signing_key:
205
+ rubygems_version: 3.0.4
206
+ signing_key:
208
207
  specification_version: 4
209
208
  summary: Rails helper for emitting javascript script tags for Intercom
210
209
  test_files: []