intercom-rails 0.4.2 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +17 -0
- data/lib/intercom-rails/auto_include_filter.rb +2 -2
- data/lib/intercom-rails/config.rb +10 -0
- data/lib/intercom-rails/script_tag.rb +49 -10
- data/lib/intercom-rails/version.rb +1 -1
- metadata +27 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c9335eca559ae32c3965cf1969443c0e20b65d29b81f1e5c6200d1d9e8d734c
|
4
|
+
data.tar.gz: 120b0878b7f09a4301c94c2c8dbc0c0376623a91e48948339482aafd203c9b99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f584dbf2f062e00f9b3d00b53a5cf8b9bef4406cf79f1afa5af805e106a7ef52402668a01f45f5302c04a15985d808651022d45be8b4af6ec8a52a571c12b7f9
|
7
|
+
data.tar.gz: cadbf3a8a2927260fc51131f688f8a5ae321af6d5d661db9688efa3c2bf2276608ae28264c0b535494610cac561f551151cdedaca4f78dae9b39f9f0bf1ec2d4
|
data/README.md
CHANGED
@@ -240,6 +240,23 @@ config.company.custom_data = {
|
|
240
240
|
}
|
241
241
|
```
|
242
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
|
+
|
243
260
|
### Messenger
|
244
261
|
Intercom includes an in-app messenger which allows a user to read messages and start conversations.
|
245
262
|
|
@@ -11,10 +11,10 @@ module IntercomRails
|
|
11
11
|
|
12
12
|
class Filter
|
13
13
|
CLOSING_BODY_TAG = "</body>"
|
14
|
-
|
14
|
+
BLOCKED_CONTROLLER_NAMES = %w{ Devise::PasswordsController }
|
15
15
|
|
16
16
|
def self.filter(controller)
|
17
|
-
return if
|
17
|
+
return if BLOCKED_CONTROLLER_NAMES.include?(controller.class.name)
|
18
18
|
auto_include_filter = new(controller)
|
19
19
|
return unless auto_include_filter.include_javascript?
|
20
20
|
|
@@ -143,6 +143,16 @@ module IntercomRails
|
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
146
|
+
config_group :jwt do
|
147
|
+
config_accessor :enabled
|
148
|
+
config_accessor :expiry
|
149
|
+
config_accessor :signed_user_fields do |value|
|
150
|
+
unless value.nil? || (value.kind_of?(Array) && value.all? { |v| v.kind_of?(Symbol) || v.kind_of?(String) })
|
151
|
+
raise ArgumentError, "jwt.signed_user_fields must be an array of symbols or strings"
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
146
156
|
end
|
147
157
|
|
148
158
|
end
|
@@ -1,9 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'active_support/
|
4
|
-
require 'active_support/core_ext/hash/indifferent_access'
|
5
|
-
require 'active_support/core_ext/string/output_safety'
|
3
|
+
require 'active_support/all'
|
6
4
|
require 'action_view'
|
5
|
+
require 'jwt'
|
7
6
|
|
8
7
|
module IntercomRails
|
9
8
|
|
@@ -19,7 +18,7 @@ module IntercomRails
|
|
19
18
|
include ::ActionView::Helpers::TagHelper
|
20
19
|
|
21
20
|
attr_reader :user_details, :company_details, :show_everywhere, :session_duration
|
22
|
-
attr_accessor :secret, :widget_options, :controller, :nonce, :encrypted_mode_enabled, :encrypted_mode
|
21
|
+
attr_accessor :secret, :widget_options, :controller, :nonce, :encrypted_mode_enabled, :encrypted_mode, :jwt_enabled, :jwt_expiry
|
23
22
|
|
24
23
|
def initialize(options = {})
|
25
24
|
self.secret = options[:secret] || Config.api_secret
|
@@ -27,14 +26,22 @@ module IntercomRails
|
|
27
26
|
self.controller = options[:controller]
|
28
27
|
@show_everywhere = options[:show_everywhere]
|
29
28
|
@session_duration = session_duration_from_config
|
30
|
-
self.
|
29
|
+
self.jwt_enabled = options[:jwt_enabled] || Config.jwt.enabled
|
30
|
+
self.jwt_expiry = options[:jwt_expiry] || Config.jwt.expiry
|
31
|
+
|
32
|
+
initial_user_details = if options[:find_current_user_details]
|
33
|
+
find_current_user_details
|
34
|
+
else
|
35
|
+
options[:user_details] || {}
|
36
|
+
end
|
37
|
+
|
38
|
+
lead_attributes = find_lead_attributes
|
39
|
+
|
40
|
+
self.user_details = initial_user_details.merge(lead_attributes)
|
31
41
|
|
32
42
|
self.encrypted_mode_enabled = options[:encrypted_mode] || Config.encrypted_mode
|
33
43
|
self.encrypted_mode = IntercomRails::EncryptedMode.new(secret, options[:initialization_vector], {:enabled => encrypted_mode_enabled})
|
34
44
|
|
35
|
-
# Request specific custom data for non-signed up users base on lead_attributes
|
36
|
-
self.user_details = self.user_details.merge(find_lead_attributes)
|
37
|
-
|
38
45
|
self.company_details = if options[:find_current_company_details]
|
39
46
|
find_current_company_details
|
40
47
|
elsif options[:user_details]
|
@@ -72,6 +79,7 @@ module IntercomRails
|
|
72
79
|
hsh[:company] = company_details if company_details.present?
|
73
80
|
hsh[:hide_default_launcher] = Config.hide_default_launcher if Config.hide_default_launcher
|
74
81
|
hsh[:api_base] = Config.api_base if Config.api_base
|
82
|
+
hsh[:installation_type] = 'rails'
|
75
83
|
hsh
|
76
84
|
end
|
77
85
|
|
@@ -111,7 +119,26 @@ module IntercomRails
|
|
111
119
|
plaintext_javascript = ActiveSupport::JSON.encode(plaintext_settings).gsub('<', '\u003C')
|
112
120
|
intercom_encrypted_payload_javascript = encrypted_mode.encrypted_javascript(intercom_settings)
|
113
121
|
|
114
|
-
"window.intercomSettings = #{plaintext_javascript};#{intercom_encrypted_payload_javascript}(function(){var w=window;var ic=w.Intercom;if(typeof ic===\"function\"){ic('
|
122
|
+
"window.intercomSettings = #{plaintext_javascript};#{intercom_encrypted_payload_javascript}(function(){var w=window;var ic=w.Intercom;if(typeof ic===\"function\"){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(document.readyState==='complete'){l();}else if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}};})()"
|
123
|
+
end
|
124
|
+
|
125
|
+
def generate_jwt
|
126
|
+
return nil unless user_details[:user_id].present?
|
127
|
+
|
128
|
+
payload = { user_id: user_details[:user_id].to_s }
|
129
|
+
|
130
|
+
if jwt_expiry
|
131
|
+
payload[:exp] = jwt_expiry.from_now.to_i
|
132
|
+
end
|
133
|
+
|
134
|
+
if Config.jwt.signed_user_fields.present?
|
135
|
+
Config.jwt.signed_user_fields.each do |field|
|
136
|
+
field = field.to_sym
|
137
|
+
payload[field] = user_details[field].to_s if user_details[field].present?
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
JWT.encode(payload, secret, 'HS256')
|
115
142
|
end
|
116
143
|
|
117
144
|
def user_details=(user_details)
|
@@ -119,7 +146,19 @@ module IntercomRails
|
|
119
146
|
@user_details = @user_details.with_indifferent_access.tap do |u|
|
120
147
|
[:email, :name, :user_id].each { |k| u.delete(k) if u[k].nil? }
|
121
148
|
|
122
|
-
|
149
|
+
if secret.present?
|
150
|
+
if jwt_enabled && u[:user_id].present?
|
151
|
+
u[:intercom_user_jwt] ||= generate_jwt
|
152
|
+
|
153
|
+
u.delete(:user_id)
|
154
|
+
Config.jwt.signed_user_fields&.each do |field|
|
155
|
+
u.delete(field.to_sym)
|
156
|
+
end
|
157
|
+
elsif (u[:user_id] || u[:email]).present?
|
158
|
+
u[:user_hash] ||= user_hash
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
123
162
|
u[:app_id] ||= app_id
|
124
163
|
end
|
125
164
|
end
|
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.
|
4
|
+
version: 1.0.6
|
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:
|
13
|
+
date: 2025-01-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -18,14 +18,28 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ">"
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
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: '
|
28
|
+
version: '4.0'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: jwt
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - "~>"
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '2.0'
|
36
|
+
type: :runtime
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '2.0'
|
29
43
|
- !ruby/object:Gem::Dependency
|
30
44
|
name: rake
|
31
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -46,42 +60,42 @@ dependencies:
|
|
46
60
|
requirements:
|
47
61
|
- - ">"
|
48
62
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
63
|
+
version: '5.0'
|
50
64
|
type: :development
|
51
65
|
prerelease: false
|
52
66
|
version_requirements: !ruby/object:Gem::Requirement
|
53
67
|
requirements:
|
54
68
|
- - ">"
|
55
69
|
- !ruby/object:Gem::Version
|
56
|
-
version:
|
70
|
+
version: '5.0'
|
57
71
|
- !ruby/object:Gem::Dependency
|
58
72
|
name: rspec
|
59
73
|
requirement: !ruby/object:Gem::Requirement
|
60
74
|
requirements:
|
61
75
|
- - "~>"
|
62
76
|
- !ruby/object:Gem::Version
|
63
|
-
version: '3.
|
77
|
+
version: '3.13'
|
64
78
|
type: :development
|
65
79
|
prerelease: false
|
66
80
|
version_requirements: !ruby/object:Gem::Requirement
|
67
81
|
requirements:
|
68
82
|
- - "~>"
|
69
83
|
- !ruby/object:Gem::Version
|
70
|
-
version: '3.
|
84
|
+
version: '3.13'
|
71
85
|
- !ruby/object:Gem::Dependency
|
72
86
|
name: rspec-rails
|
73
87
|
requirement: !ruby/object:Gem::Requirement
|
74
88
|
requirements:
|
75
89
|
- - "~>"
|
76
90
|
- !ruby/object:Gem::Version
|
77
|
-
version: '
|
91
|
+
version: '5.0'
|
78
92
|
type: :development
|
79
93
|
prerelease: false
|
80
94
|
version_requirements: !ruby/object:Gem::Requirement
|
81
95
|
requirements:
|
82
96
|
- - "~>"
|
83
97
|
- !ruby/object:Gem::Version
|
84
|
-
version: '
|
98
|
+
version: '5.0'
|
85
99
|
- !ruby/object:Gem::Dependency
|
86
100
|
name: pry
|
87
101
|
requirement: !ruby/object:Gem::Requirement
|
@@ -102,28 +116,14 @@ dependencies:
|
|
102
116
|
requirements:
|
103
117
|
- - "~>"
|
104
118
|
- !ruby/object:Gem::Version
|
105
|
-
version:
|
106
|
-
type: :development
|
107
|
-
prerelease: false
|
108
|
-
version_requirements: !ruby/object:Gem::Requirement
|
109
|
-
requirements:
|
110
|
-
- - "~>"
|
111
|
-
- !ruby/object:Gem::Version
|
112
|
-
version: 1.4.5
|
113
|
-
- !ruby/object:Gem::Dependency
|
114
|
-
name: thin
|
115
|
-
requirement: !ruby/object:Gem::Requirement
|
116
|
-
requirements:
|
117
|
-
- - "~>"
|
118
|
-
- !ruby/object:Gem::Version
|
119
|
-
version: 1.7.0
|
119
|
+
version: '3.0'
|
120
120
|
type: :development
|
121
121
|
prerelease: false
|
122
122
|
version_requirements: !ruby/object:Gem::Requirement
|
123
123
|
requirements:
|
124
124
|
- - "~>"
|
125
125
|
- !ruby/object:Gem::Version
|
126
|
-
version:
|
126
|
+
version: '3.0'
|
127
127
|
- !ruby/object:Gem::Dependency
|
128
128
|
name: tzinfo
|
129
129
|
requirement: !ruby/object:Gem::Requirement
|
@@ -202,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
202
202
|
- !ruby/object:Gem::Version
|
203
203
|
version: '0'
|
204
204
|
requirements: []
|
205
|
-
rubygems_version: 3.
|
205
|
+
rubygems_version: 3.5.22
|
206
206
|
signing_key:
|
207
207
|
specification_version: 4
|
208
208
|
summary: Rails helper for emitting javascript script tags for Intercom
|