ish_models 3.1.0.10 → 3.1.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ish_models.rb +4 -0
- data/lib/wco/lead.rb +6 -0
- data/lib/wco/office_action.rb +32 -0
- data/lib/wco_email/campaign.rb +55 -0
- data/lib/wco_email/context.rb +114 -0
- data/lib/wco_email/scheduled_email_action.rb +64 -0
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b627aad79581526f09eb54fc4ccbc0008a196def8f094ccdcc4040056f176ec
|
4
|
+
data.tar.gz: e06ce92b8f549fdb0d5909d4d338aef318388c90f63869c9baa89e52afdf9705
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ab2ea04a6d77d2f4245f330ce5cee822169b7a1449f8f92936c583f2099472088770f96123bf8a6f57466c1e3e2ceccb6924f09f0a7a7fc8697096042e46001
|
7
|
+
data.tar.gz: b0f242406016f9b680964a984564f428b70c80aed5cab8dfcf5ab602b9fb2780a98b601cdd1f01d2a5b02611f53d1ea6c25c6dec0bcb6ccd4cb5ce5a3946c3ed
|
data/lib/ish_models.rb
CHANGED
@@ -8,13 +8,17 @@ module Wco; end
|
|
8
8
|
module WcoEmail; end
|
9
9
|
module WcoHosting; end
|
10
10
|
|
11
|
+
require 'wco/lead'
|
11
12
|
require 'wco/leadset'
|
13
|
+
require 'wco/office_action'
|
12
14
|
require 'wco/profile'
|
13
15
|
require 'wco/tag'
|
14
16
|
|
17
|
+
require 'wco_email/context'
|
15
18
|
require 'wco_email/conversation'
|
16
19
|
require 'wco_email/email_filter'
|
17
20
|
require 'wco_email/message_template'
|
21
|
+
require 'wco_email/scheduled_email_action'
|
18
22
|
|
19
23
|
require 'wco_hosting/appliance'
|
20
24
|
require 'wco_hosting/appliance_tmpl'
|
data/lib/wco/lead.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
##
|
3
|
+
## 2023-09-13 _vp_ I don't know if it's even used.
|
4
|
+
##
|
5
|
+
class Wco::OfficeAction
|
6
|
+
include Mongoid::Document
|
7
|
+
include Mongoid::Timestamps
|
8
|
+
store_in collection: 'office_actions'
|
9
|
+
|
10
|
+
field :slug, type: :string
|
11
|
+
validates :slug, uniqueness: true, allow_nil: true
|
12
|
+
|
13
|
+
field :descr, type: :string ## optional
|
14
|
+
|
15
|
+
|
16
|
+
STATE_ACTIVE = 'active'
|
17
|
+
STATE_INACTIVE = 'inactive'
|
18
|
+
STATES = [ STATE_ACTIVE, STATE_INACTIVE ]
|
19
|
+
field :state, type: :string
|
20
|
+
scope :active, ->{ where( state: STATE_ACTIVE ) }
|
21
|
+
|
22
|
+
|
23
|
+
has_many :ties, class_name: '::Office::ActionTie', inverse_of: :office_action
|
24
|
+
has_many :prev_ties, class_name: '::Office::ActionTie', inverse_of: :next_office_action
|
25
|
+
accepts_nested_attributes_for :ties
|
26
|
+
|
27
|
+
field :action_exe, type: :string
|
28
|
+
|
29
|
+
field :perform_at, type: :time
|
30
|
+
|
31
|
+
end
|
32
|
+
OAct = Wco::OfficeAction
|
@@ -0,0 +1,55 @@
|
|
1
|
+
|
2
|
+
##
|
3
|
+
## Sends a campaign.
|
4
|
+
## _vp_ 2023-02-02
|
5
|
+
##
|
6
|
+
class WcoEmail::Campaign
|
7
|
+
include Mongoid::Document
|
8
|
+
include Mongoid::Timestamps
|
9
|
+
store_in collection: 'ish_email_campaigns'
|
10
|
+
|
11
|
+
field :slug
|
12
|
+
validates_uniqueness_of :slug, allow_nil: true
|
13
|
+
|
14
|
+
PAGE_PARAM_NAME = 'email_contexts_page'
|
15
|
+
|
16
|
+
field :from_email
|
17
|
+
validates_presence_of :from_email
|
18
|
+
|
19
|
+
belongs_to :email_template
|
20
|
+
def tmpl; email_template; end
|
21
|
+
|
22
|
+
field :subject
|
23
|
+
field :body
|
24
|
+
|
25
|
+
field :sent_at, type: DateTime
|
26
|
+
field :send_at, type: DateTime
|
27
|
+
|
28
|
+
has_many :unsubscribes, class_name: '::Ish::EmailUnsubscribe', inverse_of: :campaign
|
29
|
+
|
30
|
+
def campaign_leads
|
31
|
+
return ::EmailCampaignLead.where( email_campaign_id: self.id.to_s ).includes( :lead )
|
32
|
+
end
|
33
|
+
|
34
|
+
def leads
|
35
|
+
::Lead.joins( :email_campaign_leads ).where( 'email_campaign_leads.email_campaign_id' => self.id.to_s )
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
## For tracking
|
40
|
+
##
|
41
|
+
attr_reader :tid
|
42
|
+
|
43
|
+
def do_send
|
44
|
+
leads.each do |lead|
|
45
|
+
ctx = Ctx.create!({
|
46
|
+
email_template: tmpl,
|
47
|
+
from_email: tmpl.from_email,
|
48
|
+
lead_id: lead.id,
|
49
|
+
send_at: Time.now,
|
50
|
+
subject: tmpl.subject,
|
51
|
+
})
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
##
|
2
|
+
## Send a single email
|
3
|
+
##
|
4
|
+
|
5
|
+
class WcoEmail::Context
|
6
|
+
include Mongoid::Document
|
7
|
+
include Mongoid::Timestamps
|
8
|
+
store_in collection: 'ish_email_contexts'
|
9
|
+
|
10
|
+
field :slug
|
11
|
+
validates_uniqueness_of :slug, allow_nil: true
|
12
|
+
|
13
|
+
field :preview_str, type: :string
|
14
|
+
def preview_str
|
15
|
+
if self[:preview_str].presence
|
16
|
+
return self[:preview_str]
|
17
|
+
else
|
18
|
+
return tmpl.preview_str
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
field :body
|
23
|
+
def body
|
24
|
+
if self[:body].presence
|
25
|
+
return self[:body]
|
26
|
+
else
|
27
|
+
return tmpl.body
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
PAGE_PARAM_NAME = 'email_contexts_page'
|
32
|
+
|
33
|
+
field :from_email
|
34
|
+
def from_email
|
35
|
+
if self[:from_email].presence
|
36
|
+
return self[:from_email]
|
37
|
+
else
|
38
|
+
return tmpl.from_email
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
field :subject
|
43
|
+
def subject
|
44
|
+
self[:subject].presence || tmpl.subject
|
45
|
+
end
|
46
|
+
|
47
|
+
belongs_to :email_template
|
48
|
+
def tmpl; email_template; end
|
49
|
+
|
50
|
+
belongs_to :scheduled_email_action, class_name: '::Office::ScheduledEmailAction', optional: true
|
51
|
+
def sch; scheduled_email_action; end
|
52
|
+
|
53
|
+
belongs_to :email_campaign, class_name: 'Ish::EmailCampaign', optional: true
|
54
|
+
|
55
|
+
field :rendered_str
|
56
|
+
|
57
|
+
field :sent_at, type: DateTime
|
58
|
+
field :send_at, type: DateTime
|
59
|
+
field :unsubscribed_at, type: DateTime
|
60
|
+
|
61
|
+
|
62
|
+
def notsent
|
63
|
+
Ish::EmailContext.where( sent_at: nil, unsubscribed_at: nil )
|
64
|
+
end
|
65
|
+
def self.notsent; new.notsent; end
|
66
|
+
|
67
|
+
|
68
|
+
def scheduled
|
69
|
+
# or({ :send_at.lte => Time.now }, { :send_at => nil }) ## This won't work b/c I need draft state!
|
70
|
+
Ish::EmailContext.where({ :send_at.lte => Time.now })
|
71
|
+
end
|
72
|
+
def self.scheduled; new.scheduled; end
|
73
|
+
|
74
|
+
|
75
|
+
## like belongs_to to_lead , but Lead is SQL to just the lead_id
|
76
|
+
field :lead_id, type: :integer
|
77
|
+
def lead; Lead.find( lead_id ); end
|
78
|
+
def to_email; lead[:email]; end ## @TODO: remove, just use the lead. _vp_ 2023-03-27
|
79
|
+
# ## no `to` field b/c that's the lead
|
80
|
+
# field :tos, type: :array, default: []
|
81
|
+
field :cc, type: :string
|
82
|
+
field :ccs, type: :array, default: []
|
83
|
+
|
84
|
+
##
|
85
|
+
## For tracking / utm
|
86
|
+
##
|
87
|
+
attr_reader :tid
|
88
|
+
|
89
|
+
def get_binding
|
90
|
+
@lead = lead()
|
91
|
+
@utm_tracking_str = {
|
92
|
+
'cid' => lead.id,
|
93
|
+
'utm_campaign' => tmpl.slug,
|
94
|
+
'utm_medium' => 'email',
|
95
|
+
'utm_source' => tmpl.slug,
|
96
|
+
}.map { |k, v| "#{k}=#{v}" }.join("&")
|
97
|
+
eval( tmpl.config_exe )
|
98
|
+
binding()
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.summary
|
102
|
+
pipeline = [
|
103
|
+
{ '$group' => {
|
104
|
+
'_id' => { '$dateToString' => { 'format' => "%Y-%m-%d", 'date' => "$sent_at", 'timezone' => 'America/Chicago' } }, 'total' => { '$sum' => 1 }
|
105
|
+
} },
|
106
|
+
{ '$sort' => { '_id': -1 } },
|
107
|
+
]
|
108
|
+
outs = Ish::EmailContext.collection.aggregate( pipeline )
|
109
|
+
outs.to_a
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
Ctx = WcoEmail::Context
|
114
|
+
|
@@ -0,0 +1,64 @@
|
|
1
|
+
|
2
|
+
require 'mongoid-paranoia'
|
3
|
+
|
4
|
+
##
|
5
|
+
## 2023-03-04 _vp_ An instance of an EmailAction.
|
6
|
+
##
|
7
|
+
class WcoEmail::ScheduledEmailAction
|
8
|
+
include Mongoid::Document
|
9
|
+
include Mongoid::Timestamps
|
10
|
+
include Mongoid::Paranoia
|
11
|
+
store_in collection: 'office_scheduled_email_actions'
|
12
|
+
|
13
|
+
field :lead_id, type: :integer
|
14
|
+
def lead
|
15
|
+
Lead.find( lead_id )
|
16
|
+
end
|
17
|
+
|
18
|
+
STATE_ACTIVE = 'active'
|
19
|
+
STATE_INACTIVE = 'inactive'
|
20
|
+
STATE_TRASH = 'trash'
|
21
|
+
STATE_UNSUBSCRIBED = 'unsubscribed'
|
22
|
+
STATES = [ STATE_ACTIVE, STATE_INACTIVE, STATE_UNSUBSCRIBED, STATE_TRASH ]
|
23
|
+
field :state, type: :string
|
24
|
+
scope :active, ->{ where( state: STATE_ACTIVE ) }
|
25
|
+
|
26
|
+
belongs_to :email_action, class_name: '::Office::EmailAction'
|
27
|
+
validates :email_action, uniqueness: { scope: :lead_id }
|
28
|
+
def act; email_action; end
|
29
|
+
def act= a; email_action= a; end
|
30
|
+
|
31
|
+
has_many :email_contexts, class_name: '::Ish::EmailContext'
|
32
|
+
def ctxs; email_contexts; end
|
33
|
+
|
34
|
+
field :perform_at, type: :time
|
35
|
+
|
36
|
+
def send_and_roll
|
37
|
+
sch = self
|
38
|
+
sch.update({ state: Sch::STATE_INACTIVE })
|
39
|
+
|
40
|
+
# send now
|
41
|
+
ctx = Ctx.create!({
|
42
|
+
email_template_id: sch.act.tmpl.id,
|
43
|
+
from_email: sch.act.tmpl.from_email,
|
44
|
+
lead_id: sch.lead.id,
|
45
|
+
scheduled_email_action_id: sch.act.id,
|
46
|
+
send_at: Time.now,
|
47
|
+
subject: sch.act.tmpl.subject,
|
48
|
+
})
|
49
|
+
|
50
|
+
# schedule next actions & update the action
|
51
|
+
sch.act.ties.each do |tie|
|
52
|
+
next_sch = Sch.find_or_initialize_by({
|
53
|
+
lead_id: sch.lead_id,
|
54
|
+
email_action_id: tie.next_email_action.id,
|
55
|
+
})
|
56
|
+
next_sch.perform_at = eval(tie.next_at_exe)
|
57
|
+
next_sch.state = Sch::STATE_ACTIVE
|
58
|
+
next_sch.save!
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
::Sch = WcoEmail::ScheduledEmailAction
|
64
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ish_models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.0.
|
4
|
+
version: 3.1.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mac_a2141
|
@@ -142,12 +142,17 @@ files:
|
|
142
142
|
- lib/ish_models.rb
|
143
143
|
- lib/ish_models/engine.rb
|
144
144
|
- lib/tasks/ish_models_tasks.rake
|
145
|
+
- lib/wco/lead.rb
|
145
146
|
- lib/wco/leadset.rb
|
147
|
+
- lib/wco/office_action.rb
|
146
148
|
- lib/wco/profile.rb
|
147
149
|
- lib/wco/tag.rb
|
150
|
+
- lib/wco_email/campaign.rb
|
151
|
+
- lib/wco_email/context.rb
|
148
152
|
- lib/wco_email/conversation.rb
|
149
153
|
- lib/wco_email/email_filter.rb
|
150
154
|
- lib/wco_email/message_template.rb
|
155
|
+
- lib/wco_email/scheduled_email_action.rb
|
151
156
|
- lib/wco_email/tag.rb-trash
|
152
157
|
- lib/wco_hosting/appliance.rb
|
153
158
|
- lib/wco_hosting/appliance_tmpl.rb
|