intercom-rails 0.1.0 → 0.1.1
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.
- data/README.mdown +105 -38
- data/lib/intercom-rails/user_proxy.rb +1 -0
- data/lib/intercom-rails/version.rb +1 -1
- data/test/intercom-rails/user_proxy_test.rb +6 -0
- metadata +4 -4
data/README.mdown
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# IntercomRails
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The easiest way to install Intercom in a rails app.
|
|
4
4
|
|
|
5
|
-
For interacting with the Intercom API, use the intercom gem (https://github.com/intercom/intercom-ruby)
|
|
5
|
+
For interacting with the Intercom REST API, use the `intercom` gem (https://github.com/intercom/intercom-ruby)
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
Add this to your Gemfile:
|
|
@@ -17,43 +17,108 @@ Then run:
|
|
|
17
17
|
bundle install
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
Take note of your `app_id` from [here](https://www.intercom.io/apps/api_keys) and generate a config file:
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
```
|
|
23
|
+
rails generate intercom:config YOUR-APP-ID
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
To make installing Intercom as easy as possible, 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.
|
|
23
27
|
|
|
24
|
-
|
|
28
|
+
To disable automatic insertion for a particular controller or action you can:
|
|
25
29
|
|
|
26
|
-
|
|
30
|
+
```ruby
|
|
31
|
+
skip_after_filter IntercomRails::AutoIncludeFilter
|
|
32
|
+
```
|
|
27
33
|
|
|
28
|
-
|
|
34
|
+
### Troubleshooting
|
|
35
|
+
If it's not working make sure:
|
|
29
36
|
|
|
30
|
-
|
|
37
|
+
* You've generated a config file with your `app_id` as detailed above.
|
|
38
|
+
* Your user object responds to an `id` or `email` method.
|
|
39
|
+
* Your current user is accessible in your controllers as `current_user` or `@user`, if not in `config/initializers/intercom.rb`:
|
|
31
40
|
|
|
41
|
+
```ruby
|
|
42
|
+
config.current_user = Proc.new { current_user_object }
|
|
32
43
|
```
|
|
33
|
-
|
|
44
|
+
|
|
45
|
+
Feel free to mail us: team@intercom.io, if you're still having trouble.
|
|
46
|
+
|
|
47
|
+
## Configuration
|
|
48
|
+
|
|
49
|
+
### API Secret
|
|
50
|
+
If you want to use secure mode, ensure you set your API secret in `config/initializers/intercom.rb`:
|
|
51
|
+
|
|
52
|
+
```ruby
|
|
53
|
+
config.api_secret = '123456'
|
|
34
54
|
```
|
|
35
55
|
|
|
36
|
-
|
|
56
|
+
### Custom Data
|
|
57
|
+
Custom data lets you associate any data, specific to your app, with a user in Intercom. For custom data variables you want updated on every request set them in `config/initializers/intercom.rb`.
|
|
37
58
|
|
|
38
|
-
|
|
59
|
+
You can give either a:
|
|
60
|
+
|
|
61
|
+
* `Proc` which will be passed the current user object
|
|
62
|
+
* Or, a method which will be sent to the current user object
|
|
63
|
+
|
|
64
|
+
to generate the values of the custom data:
|
|
65
|
+
|
|
66
|
+
```ruby
|
|
67
|
+
config.custom_data = {
|
|
68
|
+
:plan => Proc.new { |user| user.plan.name },
|
|
69
|
+
:is_paid => Proc.new { |user| user.plan.present? },
|
|
70
|
+
:email_verified => :email_verified?
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
In some situations you'll want to set some custom data specific to a request. You can do this using the `intercom_custom_data` helper available in your controllers:
|
|
39
75
|
|
|
40
76
|
```ruby
|
|
41
|
-
|
|
77
|
+
class AppsController < ActionController::Base
|
|
78
|
+
def activate
|
|
79
|
+
intercom_custom_data[:app_activated_at] = Time.now
|
|
80
|
+
...
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def destroy
|
|
84
|
+
intercom_custom_data[:app_deleted_at] = Time.now
|
|
85
|
+
...
|
|
86
|
+
end
|
|
87
|
+
end
|
|
42
88
|
```
|
|
43
89
|
|
|
44
|
-
###
|
|
90
|
+
### Inbox
|
|
91
|
+
Intercom includes an inbox which allows a user to read their past conversations with your app, and start new conversations. It's hidden by default, you can include a link to open it by adding a line to `config/initializers/intercom.rb`:
|
|
45
92
|
|
|
46
|
-
|
|
93
|
+
To use the default link style, which requires no extra config and includes a small question mark icon in the bottom right corner of your app:
|
|
47
94
|
|
|
95
|
+
```ruby
|
|
96
|
+
config.inbox.style = :default
|
|
48
97
|
```
|
|
49
|
-
|
|
98
|
+
|
|
99
|
+
If you want to customize the style of the link that opens the inbox:
|
|
100
|
+
|
|
101
|
+
```ruby
|
|
102
|
+
config.inbox.style = :custom
|
|
50
103
|
```
|
|
51
104
|
|
|
52
|
-
|
|
105
|
+
This option attaches the inbox open event to the click event of an element with an id of `#Intercom`. So the simplest option here would be to add something like the following to your layout:
|
|
53
106
|
|
|
54
|
-
|
|
107
|
+
```html
|
|
108
|
+
<a id="#Intercom">Support</a>
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
You can read more about configuring the Inbox within Intercom (Config menu -> Inbox Link).
|
|
112
|
+
|
|
113
|
+
### Manually Inserting the Intercom Javascript
|
|
114
|
+
|
|
115
|
+
Some situations may require manually inserting the Intercom script tag. If you simply wish to place the Intercom javascript in a different place within the page or, on a page without a closing `</body>` tag:
|
|
116
|
+
|
|
117
|
+
```erb
|
|
118
|
+
<%= intercom_script_tag %>
|
|
119
|
+
```
|
|
55
120
|
|
|
56
|
-
|
|
121
|
+
This will behave exactly the same as the default auto-install. If for whatever reason you can't use auto-install, you can also provide a hash of user data as the first argument:
|
|
57
122
|
|
|
58
123
|
```erb
|
|
59
124
|
<% if logged_in? %>
|
|
@@ -64,25 +129,13 @@ In your layout file:
|
|
|
64
129
|
:name => current_user.name
|
|
65
130
|
:created_at => current_user.created_at
|
|
66
131
|
:custom_data => {
|
|
67
|
-
|
|
68
|
-
}
|
|
132
|
+
'plan' => current_user.plan.name
|
|
133
|
+
}
|
|
134
|
+
}) %>
|
|
69
135
|
<% end %>
|
|
70
136
|
```
|
|
71
137
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
e.g.
|
|
75
|
-
|
|
76
|
-
```ruby
|
|
77
|
-
:custom_data => {
|
|
78
|
-
:plan => "Pro",
|
|
79
|
-
:dashboard_page => 'http://dashboard.example.com/user-id'
|
|
80
|
-
}
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
### Secure mode
|
|
84
|
-
|
|
85
|
-
Pass in a second argument to `intercom_script_tag`, a hash containing the secret, like so:
|
|
138
|
+
You can also override `IntercomRails::Config` options such as your `api_secret`, or widget configuration with a second hash:
|
|
86
139
|
|
|
87
140
|
```erb
|
|
88
141
|
<% if logged_in? %>
|
|
@@ -92,13 +145,27 @@ Pass in a second argument to `intercom_script_tag`, a hash containing the secret
|
|
|
92
145
|
:email => current_user.email
|
|
93
146
|
:name => current_user.name
|
|
94
147
|
:created_at => current_user.created_at
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
148
|
+
}, {
|
|
149
|
+
:secret => 'your-apps-secret',
|
|
150
|
+
:widget => {:activator => '#Intercom'}
|
|
151
|
+
}) %>
|
|
98
152
|
<% end %>
|
|
99
153
|
```
|
|
100
154
|
|
|
101
|
-
|
|
155
|
+
The `intercom:install` rails generator will add the `intercom_script_tag` to your application layout:
|
|
156
|
+
|
|
157
|
+
```
|
|
158
|
+
rails g intercom:install YOUR-APP-ID
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Importing your users
|
|
162
|
+
To get started faster with Intercom, `IntercomRails` includes a Rake task that will do an initial import of your users:
|
|
163
|
+
|
|
164
|
+
```
|
|
165
|
+
rake intercom:import
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Any custom data defined in `config/initializers/intercom.rb` will also be sent.
|
|
102
169
|
|
|
103
170
|
## Contributors
|
|
104
171
|
|
|
@@ -86,4 +86,10 @@ class UserProxyTest < MiniTest::Unit::TestCase
|
|
|
86
86
|
assert_equal expected_custom_data, @user_proxy.to_hash[:custom_data]
|
|
87
87
|
end
|
|
88
88
|
|
|
89
|
+
def test_valid_returns_false_for_nil
|
|
90
|
+
search_object = false
|
|
91
|
+
search_object.stub(:id) { raise NameError }
|
|
92
|
+
assert_equal false, UserProxy.new(search_object).valid?
|
|
93
|
+
end
|
|
94
|
+
|
|
89
95
|
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.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -11,7 +11,7 @@ authors:
|
|
|
11
11
|
autorequire:
|
|
12
12
|
bindir: bin
|
|
13
13
|
cert_chain: []
|
|
14
|
-
date: 2012-11-
|
|
14
|
+
date: 2012-11-28 00:00:00.000000000 Z
|
|
15
15
|
dependencies:
|
|
16
16
|
- !ruby/object:Gem::Dependency
|
|
17
17
|
name: activesupport
|
|
@@ -178,7 +178,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
178
178
|
version: '0'
|
|
179
179
|
segments:
|
|
180
180
|
- 0
|
|
181
|
-
hash:
|
|
181
|
+
hash: 2121047111901162592
|
|
182
182
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
183
183
|
none: false
|
|
184
184
|
requirements:
|
|
@@ -187,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
187
187
|
version: '0'
|
|
188
188
|
segments:
|
|
189
189
|
- 0
|
|
190
|
-
hash:
|
|
190
|
+
hash: 2121047111901162592
|
|
191
191
|
requirements: []
|
|
192
192
|
rubyforge_project: intercom-rails
|
|
193
193
|
rubygems_version: 1.8.23
|