heya 0.5.2 → 0.7.0
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/CHANGELOG.md +21 -0
- data/README.md +47 -1
- data/app/mailers/heya/campaign_mailer.rb +28 -2
- data/lib/heya/campaigns/actions/email.rb +1 -1
- data/lib/heya/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 897c67c77ab4b26f47d21ddde192e5957239cdb319c662fd72dd806de3c552d2
|
4
|
+
data.tar.gz: e34438a886e4c1598b0bca34bab406b84b83561310857f2c8730c669961e5a9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6efc0529915073f5e3e2abb9a878e1f2e290cf66b66913989555325ac29f508988378e48637efaa36a345f3bc6ebd6978c110879c52d1999cea7bb3ec35e67a4
|
7
|
+
data.tar.gz: 02e88ebd7dea87ba644b380be61ffc41788c24045f8e103df302e44b1a8f82a37850ed56beb12b763b183061abf2526a5cd2affb6a175e155f7096d22a8dde7d
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,27 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
|
+
|
9
|
+
## [0.7.0] - 2022-02-03
|
10
|
+
### Fixed
|
11
|
+
- Automatically include Rails url helpers from application in campaign mailer templates (#158, @feliperaul)
|
12
|
+
|
13
|
+
### Added
|
14
|
+
- Allow the customization of the to field (#155, @feliperaul)
|
15
|
+
|
16
|
+
## [0.6.1] - 2022-01-05
|
17
|
+
### Fixed
|
18
|
+
- Support Rails 7 (#151, @800a7b32)
|
19
|
+
|
20
|
+
## [0.6.0] - 2021-11-02
|
21
|
+
### Added
|
22
|
+
- Optional `layout` parameter for steps; allowing override from default `heya/campaign_mailer`
|
23
|
+
|
24
|
+
## [0.5.3] - 2021-08-18
|
25
|
+
### Added
|
26
|
+
- Create `bcc:` optional parameter for steps; use case is quality control
|
27
|
+
|
28
|
+
## [0.5.2] - 2021-08-11
|
8
29
|
### Fixed
|
9
30
|
- Fix typo in initializer (#139, @800a7b32)
|
10
31
|
|
data/README.md
CHANGED
@@ -247,12 +247,54 @@ The `wait` option tells Heya how long to wait before sending each message (the d
|
|
247
247
|
Heya uses the following additional options to build the message itself:
|
248
248
|
|
249
249
|
| Option Name | Default | Description |
|
250
|
-
|
250
|
+
|-------------|--------------|----------------------------|
|
251
251
|
| `subject` | **required** | The email's subject |
|
252
252
|
| `from` | Heya default | The sender's email address |
|
253
|
+
| `layout` | Heya default | The email's layout file |
|
254
|
+
| `to` | See below | See below |
|
253
255
|
|
254
256
|
You can change the default options using the `default` method at the top of the campaign. Heya applies default options to each step which doesn't supply its own:
|
255
257
|
|
258
|
+
```ruby
|
259
|
+
class OnboardingCampaign < ApplicationCampaign
|
260
|
+
default wait: 1.day,
|
261
|
+
queue: "onboarding",
|
262
|
+
from: "support@example.com",
|
263
|
+
layout: "onboarding"
|
264
|
+
|
265
|
+
# Will still be sent after one day from the
|
266
|
+
# email address support@example.com
|
267
|
+
step :welcome,
|
268
|
+
subject: "Welcome to my app!"
|
269
|
+
end
|
270
|
+
```
|
271
|
+
|
272
|
+
#### Customizing the `to` field
|
273
|
+
|
274
|
+
You can customize the `to` field by passing a callable object, which Heya will invoke with the user. For instance:
|
275
|
+
|
276
|
+
```ruby
|
277
|
+
class OnboardingCampaign < ApplicationCampaign
|
278
|
+
step :welcome,
|
279
|
+
subject: "Welcome to my app!",
|
280
|
+
to: -> (user) { ActionMailer::Base.email_address_with_name(user.email, user.nickname) }
|
281
|
+
end
|
282
|
+
```
|
283
|
+
|
284
|
+
It is recommended to rely on `ActionMailer::Base.email_address_with_name` so that sanitization is correctly applied.
|
285
|
+
|
286
|
+
If the `to` param is not provided, Heya will default to:
|
287
|
+
|
288
|
+
1. `user#first_name`
|
289
|
+
1. `user#name`
|
290
|
+
|
291
|
+
If the `user` object doesn't respond to these methods, it will fallback to a simple `user.email` in the `to` field.
|
292
|
+
|
293
|
+
#### Quality control option
|
294
|
+
|
295
|
+
You may wish to apply quality control to individual steps of a campaign. For example, when adding a new step to an existing campaign it is
|
296
|
+
a good idea to inspect real-time results in production. You can do this by using the `bcc:` step option, which would look like this:
|
297
|
+
|
256
298
|
```ruby
|
257
299
|
class OnboardingCampaign < ApplicationCampaign
|
258
300
|
default wait: 1.day,
|
@@ -263,6 +305,10 @@ class OnboardingCampaign < ApplicationCampaign
|
|
263
305
|
# email address support@example.com
|
264
306
|
step :welcome,
|
265
307
|
subject: "Welcome to my app!"
|
308
|
+
|
309
|
+
step :added_two_months_later,
|
310
|
+
subject: "We now have something new to say!",
|
311
|
+
bcc: 'quality_control@example.com'
|
266
312
|
end
|
267
313
|
```
|
268
314
|
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Heya
|
2
2
|
class CampaignMailer < ApplicationMailer
|
3
|
-
|
3
|
+
DEFAULT_LAYOUT = "heya/campaign_mailer"
|
4
|
+
layout -> { params.fetch(:step).params.fetch("layout", DEFAULT_LAYOUT) }
|
5
|
+
include Rails.application.routes.url_helpers
|
4
6
|
|
5
7
|
def build
|
6
8
|
user = params.fetch(:user)
|
@@ -10,6 +12,7 @@ module Heya
|
|
10
12
|
step_name = step.name.underscore
|
11
13
|
|
12
14
|
from = step.params.fetch("from")
|
15
|
+
bcc = step.params.fetch("bcc", nil)
|
13
16
|
reply_to = step.params.fetch("reply_to", nil)
|
14
17
|
|
15
18
|
subject = step.params.fetch("subject") {
|
@@ -22,8 +25,9 @@ module Heya
|
|
22
25
|
|
23
26
|
mail(
|
24
27
|
from: from,
|
28
|
+
bcc: bcc,
|
25
29
|
reply_to: reply_to,
|
26
|
-
to: user
|
30
|
+
to: to_address(user, step),
|
27
31
|
subject: subject,
|
28
32
|
template_path: "heya/campaign_mailer/#{campaign_name}",
|
29
33
|
template_name: step_name
|
@@ -49,5 +53,27 @@ module Heya
|
|
49
53
|
end
|
50
54
|
end
|
51
55
|
end
|
56
|
+
|
57
|
+
def to_address(user, step)
|
58
|
+
return step.params["to"].call(user) if step.params["to"].respond_to?(:call)
|
59
|
+
|
60
|
+
if user.respond_to?(:first_name)
|
61
|
+
self.class.email_address_with_name(user.email, user.first_name)
|
62
|
+
elsif user.respond_to?(:name)
|
63
|
+
self.class.email_address_with_name(user.email, user.name)
|
64
|
+
else
|
65
|
+
user.email
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# This method is a backport and can be removed when we drop support of
|
70
|
+
# Rails 6.0; As of Rails 6.1, ActionMailer::Base, which we inherit from,
|
71
|
+
# already includes it.
|
72
|
+
def self.email_address_with_name(address, name)
|
73
|
+
Mail::Address.new.tap do |builder|
|
74
|
+
builder.address = address
|
75
|
+
builder.display_name = name
|
76
|
+
end.to_s
|
77
|
+
end
|
52
78
|
end
|
53
79
|
end
|
data/lib/heya/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: heya
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Wood
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: 5.2.3
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
22
|
+
version: 7.1.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: 5.2.3
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
32
|
+
version: 7.1.0
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: pg
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
131
|
- !ruby/object:Gem::Version
|
132
132
|
version: '0'
|
133
133
|
requirements: []
|
134
|
-
rubygems_version: 3.
|
134
|
+
rubygems_version: 3.3.3
|
135
135
|
signing_key:
|
136
136
|
specification_version: 4
|
137
137
|
summary: "Heya \U0001F44B"
|