intercom-rails 0.3.5 → 0.3.8
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 +7 -4
- data/lib/intercom-rails.rb +1 -0
- data/lib/intercom-rails/config.rb +1 -0
- data/lib/intercom-rails/encrypted_mode.rb +34 -0
- data/lib/intercom-rails/script_tag.rb +16 -3
- data/lib/intercom-rails/script_tag_helper.rb +2 -2
- data/lib/intercom-rails/shutdown_helper.rb +0 -1
- data/lib/intercom-rails/version.rb +1 -1
- data/lib/rails/generators/intercom/config/config_generator.rb +1 -1
- data/lib/rails/generators/intercom/config/intercom.rb.erb +3 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c8c86341c15d5e3d7620a1a737c2a2eb62744b3
|
4
|
+
data.tar.gz: bccf57bc964ba2aa3daa7dee8b7e569e21d28d4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 923ca98ea86eee4d13dbfc68691f706883fe08929e6d147888522e2aa1f93f95f6720e5ce033671e29531d4811fff9e13a73ec6bc7c26f23f805b085d3617f63
|
7
|
+
data.tar.gz: 396f0c39720971cd3afc59869e015c076cc4ba5e608b41069a0406902ad70e9b70c784a7f41ee7983739e04feaca4d619a832d8f1b2c9d704c5fb5ee7b14a747
|
data/README.md
CHANGED
@@ -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 for `intercom-rails >= 4.0`
|
8
|
+
|
7
9
|
## Installation
|
8
10
|
Add this to your Gemfile:
|
9
11
|
|
@@ -26,7 +28,7 @@ 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
|
31
|
+
### Live Chat
|
30
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:
|
31
33
|
```ruby
|
32
34
|
config.include_for_logged_out_users = true
|
@@ -60,7 +62,7 @@ Feel free to mail us: team@intercom.io, if you're still having trouble.
|
|
60
62
|
## Configuration
|
61
63
|
|
62
64
|
### API Secret
|
63
|
-
If you want to use
|
65
|
+
If you want to use Identity Verification, ensure you set your API secret in `config/initializers/intercom.rb`:
|
64
66
|
|
65
67
|
```ruby
|
66
68
|
config.api_secret = '123456'
|
@@ -384,7 +386,8 @@ end
|
|
384
386
|
class DeleteFromIntercom < ApplicationJob
|
385
387
|
def perform(user)
|
386
388
|
intercom = Intercom::Client.new
|
387
|
-
intercom.users.find(
|
389
|
+
user = intercom.users.find(id: user.id)
|
390
|
+
deleted_user = intercom.users.delete(user)
|
388
391
|
end
|
389
392
|
end
|
390
393
|
```
|
@@ -416,7 +419,7 @@ bundle exec rspec spec/
|
|
416
419
|
- **Send coherent history**. Make sure each individual commit in your pull
|
417
420
|
request is meaningful. If you had to make multiple intermediate commits while
|
418
421
|
developing, please squash them before sending them to us.
|
419
|
-
|
422
|
+
|
420
423
|
|
421
424
|
## Contributors
|
422
425
|
|
data/lib/intercom-rails.rb
CHANGED
@@ -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'
|
@@ -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 :encrypted_mode
|
111
112
|
|
112
113
|
def self.api_key=(*)
|
113
114
|
warn "Setting an Intercom API key is no longer supported; remove the `config.api_key = ...` line from config/initializers/intercom.rb"
|
@@ -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, :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
|
@@ -10,7 +10,7 @@ module IntercomRails
|
|
10
10
|
include ::ActionView::Helpers::JavaScriptHelper
|
11
11
|
|
12
12
|
attr_reader :user_details, :company_details, :show_everywhere, :session_duration
|
13
|
-
attr_accessor :secret, :widget_options, :controller, :nonce
|
13
|
+
attr_accessor :secret, :widget_options, :controller, :nonce, :encrypted_mode_enabled, :encrypted_mode
|
14
14
|
|
15
15
|
def initialize(options = {})
|
16
16
|
self.secret = options[:secret] || Config.api_secret
|
@@ -20,6 +20,9 @@ module IntercomRails
|
|
20
20
|
@session_duration = session_duration_from_config
|
21
21
|
self.user_details = options[:find_current_user_details] ? find_current_user_details : options[:user_details]
|
22
22
|
|
23
|
+
self.encrypted_mode_enabled = options[:encrypted_mode] || Config.encrypted_mode
|
24
|
+
self.encrypted_mode = IntercomRails::EncryptedMode.new(secret, options[:initialization_vector], {:enabled => encrypted_mode_enabled})
|
25
|
+
|
23
26
|
# Request specific custom data for non-signed up users base on lead_attributes
|
24
27
|
self.user_details = self.user_details.merge(find_lead_attributes)
|
25
28
|
|
@@ -94,11 +97,21 @@ module IntercomRails
|
|
94
97
|
custom_data.select {|k, v| lead_attributes.map(&:to_s).include?(k)}
|
95
98
|
end
|
96
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
|
+
|
97
108
|
private
|
109
|
+
|
98
110
|
def intercom_javascript
|
99
|
-
|
111
|
+
plaintext_javascript = ActiveSupport::JSON.encode(plaintext_settings).gsub('<', '\u003C')
|
112
|
+
intercom_encrypted_payload_javascript = encrypted_mode.encrypted_javascript(intercom_settings)
|
100
113
|
|
101
|
-
str = "window.intercomSettings = #{
|
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);}};})()"
|
102
115
|
|
103
116
|
str
|
104
117
|
end
|
@@ -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
|
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
|
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,7 +2,6 @@ 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
6
|
def self.intercom_shutdown_helper(cookies)
|
8
7
|
if (cookies.is_a?(ActionDispatch::Cookies::CookieJar))
|
@@ -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
|
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
|
15
|
-
# guide in the "
|
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.
|
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 -%>
|
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.3.
|
4
|
+
version: 0.3.8
|
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: 2018-01-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -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
|
@@ -202,9 +203,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
202
203
|
version: '0'
|
203
204
|
requirements: []
|
204
205
|
rubyforge_project: intercom-rails
|
205
|
-
rubygems_version: 2.
|
206
|
+
rubygems_version: 2.5.1
|
206
207
|
signing_key:
|
207
208
|
specification_version: 4
|
208
209
|
summary: Rails helper for emitting javascript script tags for Intercom
|
209
210
|
test_files: []
|
210
|
-
has_rdoc:
|