Class: WcoEmail::EmailAction

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Paranoia, Mongoid::Timestamps
Defined in:
app/models/wco_email/email_action.rb

Overview

2023-03-04 vp An instance of an EmailAction. 2023-03-04 vp An instance of an EmailActionTemplate.

Constant Summary collapse

STATUS_ACTIVE =
'active'
STATUS_INACTIVE =
'inactive'
STATUS_TRASH =
'trash'
STATUS_UNSUBSCRIBED =
'unsubscribed'
STATUSES =
[ nil, STATUS_ACTIVE, STATUS_INACTIVE, STATUS_UNSUBSCRIBED, STATUS_TRASH ]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.listObject



62
63
64
# File 'app/models/wco_email/email_action.rb', line 62

def self.list
  [[nil,nil]] + all.map { |p| [ "#{p.lead&.email} :: #{p.tmpl&.slug}", p.id ] }
end

Instance Method Details

#ctxsObject



30
# File 'app/models/wco_email/email_action.rb', line 30

def ctxs; email_contexts; end

#send_and_rollObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/wco_email/email_action.rb', line 35

def send_and_roll
  sch = self
  sch.update!({ status: STATUS_INACTIVE })

  # send now
  ctx = WcoEmail::Context.create!({
    email_action:   sch,
    email_template: sch.tmpl.email_template,
    from_email:     sch.tmpl.email_template.from_email,
    lead:           sch.lead,
    send_at:        Time.now,
    subject:        sch.tmpl.email_template.subject,
  })

  # schedule next actions & update the action
  sch.tmpl.ties.each do |tie|
    next_sch = self.class.find_or_initialize_by({
      lead_id:                  sch.lead_id,
      email_action_template_id: tie.next_tmpl.id,
    })
    next_sch.perform_at = eval(tie.next_at_exe)
    next_sch.status     = STATUS_ACTIVE
    next_sch.save!
  end
end

#tmplObject



27
# File 'app/models/wco_email/email_action.rb', line 27

def tmpl; email_action_template; end