intercom-rails 0.4.1 → 1.0.0

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: 5dee175c5039fa80194ff69042d5de615a7a801351da87b5c7459e2504f58e05
4
+ data.tar.gz: ccbaed8ae280936a62c3c1b3ca90f907b71e67b18b0e3e5f6aa2bcf4e7f11f05
5
5
  SHA512:
6
- metadata.gz: 3baa59dfce787f287e1442da9cbc63d9d564e720cf445a930dfe7c1351cfd5982b46184af342e51454a034910e6966487b7c0029db495e3018bb63c2ddba25bb
7
- data.tar.gz: f2f35de9546ef409652ef7956161eb05ad5798c23808b8320764e49519648c5f0aa0b01ee276efc98f2f0982bd0e5dfc3036910d4b97c574ff2a7f8900904d08
6
+ metadata.gz: 1bb0fd7b74175353525d1feb105b69be217620b831d17c639aa8666bfd03249ac25a57542be9419294a71ee54990d89af73473952d5fc24fd6b4e25caae83ead
7
+ data.tar.gz: eccb8b923bba00629e59784e8ff76f7fd4d8489568d9e3c2d199e30bf9e6e5c1493d4a35d095299dfcca7d3af107df08396aac7cd1e0caae28ba0e1e6e6d092c
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`
@@ -242,6 +240,23 @@ config.company.custom_data = {
242
240
  }
243
241
  ```
244
242
 
243
+ In some situations you'll want to set some custom company data attribute specific to a request.
244
+ You can do this similarly to user data attribute set by using the `intercom_custom_data` helper available in your controllers:
245
+
246
+ ```ruby
247
+ class AppsController < ActionController::Base
248
+ def activate
249
+ intercom_custom_data.company[:app_activated_at] = Time.now
250
+ ...
251
+ end
252
+
253
+ def destroy
254
+ intercom_custom_data.company[:app_deleted_at] = Time.now
255
+ ...
256
+ end
257
+ end
258
+ ```
259
+
245
260
  ### Messenger
246
261
  Intercom includes an in-app messenger which allows a user to read messages and start conversations.
247
262
 
@@ -381,10 +396,10 @@ You can do this using the [intercom-ruby](https://github.com/intercom/intercom-r
381
396
 
382
397
  ```
383
398
  class User
384
- after_destroy { DeleteFromIntercom.perform_later(self)
399
+ after_destroy { DeleteFromIntercomJob.perform_later(self) }
385
400
  end
386
401
 
387
- class DeleteFromIntercom < ApplicationJob
402
+ class DeleteFromIntercomJob < ApplicationJob
388
403
  def perform(user)
389
404
  intercom = Intercom::Client.new
390
405
  user = intercom.users.find(id: user.id)
@@ -433,4 +448,4 @@ intercom-rails is released under the [MIT License](http://www.opensource.org/lic
433
448
 
434
449
  ## Copyright
435
450
 
436
- Copyright (c) 2011-2012 Intercom, Inc. All rights reserved.
451
+ 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,12 +10,11 @@ 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
+ BLOCKED_CONTROLLER_NAMES = %w{ Devise::PasswordsController }
14
15
 
15
16
  def self.filter(controller)
16
- return if BLACKLISTED_CONTROLLER_NAMES.include?(controller.class.name)
17
+ return if BLOCKED_CONTROLLER_NAMES.include?(controller.class.name)
17
18
  auto_include_filter = new(controller)
18
19
  return unless auto_include_filter.include_javascript?
19
20
 
@@ -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,13 +1,20 @@
1
- require 'active_support/json'
2
- require 'active_support/core_ext/hash/indifferent_access'
3
- require 'active_support/core_ext/string/output_safety'
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/all'
4
4
  require 'action_view'
5
5
 
6
6
  module IntercomRails
7
7
 
8
8
  class ScriptTag
9
+ # Base64 regexp:
10
+ # - blocks of 4 [A-Za-z0-9+/]
11
+ # followed either by:
12
+ # - blocks of 2 [A-Za-z0-9+/] + '=='
13
+ # - blocks of 3 [A-Za-z0-9+/] + '='
14
+ NONCE_RE = %r{^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$}
9
15
 
10
16
  include ::ActionView::Helpers::JavaScriptHelper
17
+ include ::ActionView::Helpers::TagHelper
11
18
 
12
19
  attr_reader :user_details, :company_details, :show_everywhere, :session_duration
13
20
  attr_accessor :secret, :widget_options, :controller, :nonce, :encrypted_mode_enabled, :encrypted_mode
@@ -46,21 +53,14 @@ module IntercomRails
46
53
  valid
47
54
  end
48
55
 
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
56
+ if //.respond_to?(:match?)
57
+ def valid_nonce?
58
+ nonce && NONCE_RE.match?(nonce)
59
+ end
60
+ else
61
+ def valid_nonce?
62
+ nonce && !!NONCE_RE.match(nonce)
62
63
  end
63
- valid
64
64
  end
65
65
 
66
66
  def intercom_settings
@@ -69,16 +69,15 @@ module IntercomRails
69
69
  hsh[:widget] = widget_options if widget_options.present?
70
70
  hsh[:company] = company_details if company_details.present?
71
71
  hsh[:hide_default_launcher] = Config.hide_default_launcher if Config.hide_default_launcher
72
+ hsh[:api_base] = Config.api_base if Config.api_base
73
+ hsh[:installation_type] = 'rails'
72
74
  hsh
73
75
  end
74
76
 
75
77
  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
78
+ html_options = { id: 'IntercomSettingsScriptTag' }
79
+ html_options['nonce'] = nonce if valid_nonce?
80
+ javascript_tag(intercom_javascript, html_options) + "\n"
82
81
  end
83
82
 
84
83
  def csp_sha256
@@ -111,9 +110,7 @@ module IntercomRails
111
110
  plaintext_javascript = ActiveSupport::JSON.encode(plaintext_settings).gsub('<', '\u003C')
112
111
  intercom_encrypted_payload_javascript = encrypted_mode.encrypted_javascript(intercom_settings)
113
112
 
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
113
+ "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
114
  end
118
115
 
119
116
  def user_details=(user_details)
@@ -1,3 +1,3 @@
1
1
  module IntercomRails
2
- VERSION = "0.4.1"
2
+ VERSION = "1.0.0"
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: 1.0.0
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: 2024-02-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - ">"
20
20
  - !ruby/object:Gem::Version
21
- version: '3.0'
21
+ version: '4.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - ">"
27
27
  - !ruby/object:Gem::Version
28
- version: '3.0'
28
+ version: '4.0'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: rake
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -46,42 +46,42 @@ dependencies:
46
46
  requirements:
47
47
  - - ">"
48
48
  - !ruby/object:Gem::Version
49
- version: 3.2.12
49
+ version: '5.0'
50
50
  type: :development
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - ">"
55
55
  - !ruby/object:Gem::Version
56
- version: 3.2.12
56
+ version: '5.0'
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: rspec
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - "~>"
62
62
  - !ruby/object:Gem::Version
63
- version: '3.1'
63
+ version: '3.13'
64
64
  type: :development
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
68
  - - "~>"
69
69
  - !ruby/object:Gem::Version
70
- version: '3.1'
70
+ version: '3.13'
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: rspec-rails
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
75
  - - "~>"
76
76
  - !ruby/object:Gem::Version
77
- version: '3.1'
77
+ version: '5.0'
78
78
  type: :development
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
82
  - - "~>"
83
83
  - !ruby/object:Gem::Version
84
- version: '3.1'
84
+ version: '5.0'
85
85
  - !ruby/object:Gem::Dependency
86
86
  name: pry
87
87
  requirement: !ruby/object:Gem::Requirement
@@ -102,14 +102,14 @@ dependencies:
102
102
  requirements:
103
103
  - - "~>"
104
104
  - !ruby/object:Gem::Version
105
- version: 1.4.5
105
+ version: '2.0'
106
106
  type: :development
107
107
  prerelease: false
108
108
  version_requirements: !ruby/object:Gem::Requirement
109
109
  requirements:
110
110
  - - "~>"
111
111
  - !ruby/object:Gem::Version
112
- version: 1.4.5
112
+ version: '2.0'
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: thin
115
115
  requirement: !ruby/object:Gem::Requirement
@@ -124,6 +124,20 @@ dependencies:
124
124
  - - "~>"
125
125
  - !ruby/object:Gem::Version
126
126
  version: 1.7.0
127
+ - !ruby/object:Gem::Dependency
128
+ name: bigdecimal
129
+ requirement: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - '='
132
+ - !ruby/object:Gem::Version
133
+ version: 1.3.5
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - '='
139
+ - !ruby/object:Gem::Version
140
+ version: 1.3.5
127
141
  - !ruby/object:Gem::Dependency
128
142
  name: tzinfo
129
143
  requirement: !ruby/object:Gem::Requirement
@@ -187,7 +201,7 @@ homepage: http://www.intercom.io
187
201
  licenses:
188
202
  - MIT
189
203
  metadata: {}
190
- post_install_message:
204
+ post_install_message:
191
205
  rdoc_options: []
192
206
  require_paths:
193
207
  - lib
@@ -202,9 +216,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
216
  - !ruby/object:Gem::Version
203
217
  version: '0'
204
218
  requirements: []
205
- rubyforge_project: intercom-rails
206
- rubygems_version: 2.7.6.2
207
- signing_key:
219
+ rubygems_version: 3.1.6
220
+ signing_key:
208
221
  specification_version: 4
209
222
  summary: Rails helper for emitting javascript script tags for Intercom
210
223
  test_files: []