ish_models 0.0.33.191 → 0.0.33.192
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ish/email_campaign.rb +68 -0
- data/lib/ish/email_context.rb +9 -5
- data/lib/ish_models.rb +7 -0
- data/lib/office/action.rb +44 -0
- data/lib/office/email_message.rb +77 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6da0c443f4fa1d09ab99af29832021711aaa151abd165a0b5e70ef5c60361b77
|
4
|
+
data.tar.gz: d5acaf403668bc945aee9fc93ecbfaca3a46621dbe596035f7cd5afb1bed8e06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e101f25e3b4c00530cbd1dfaad7510fa0204b6e226e01075107d0a6bf41d07fbde8c6889368657345db175b03e82c0a0167a7f448ac464fcbbf7a24d32241d0d
|
7
|
+
data.tar.gz: e16cc3d97165e974b24649a9759c87ec3c6a7e49a8ad158bfeda23a7d6e7bb57decf6571363d5cc12848aa0f7e4ef4e2a9616d558b09c900472484b53119f0d5
|
@@ -0,0 +1,68 @@
|
|
1
|
+
|
2
|
+
#
|
3
|
+
# Sends a campaign.
|
4
|
+
# _vp_ 2023-02-02
|
5
|
+
#
|
6
|
+
|
7
|
+
class Ish::EmailCampaign
|
8
|
+
include Mongoid::Document
|
9
|
+
include Mongoid::Timestamps
|
10
|
+
|
11
|
+
field :title
|
12
|
+
def slug
|
13
|
+
title
|
14
|
+
end
|
15
|
+
|
16
|
+
PAGE_PARAM_NAME = 'email_contexts_page'
|
17
|
+
|
18
|
+
FROM_EMAILS = %w| hello@infiniteshelter.com no-reply@infiniteshelter.com
|
19
|
+
piousbox@gmail.com victor@piousbox.com no-reply@piousbox.com
|
20
|
+
admin@wasya.co hello@wasya.co no-reply@wasya.co victor@wasya.co |
|
21
|
+
field :from_email
|
22
|
+
validates_presence_of :from_email
|
23
|
+
def self.from_email_list
|
24
|
+
[ [nil, nil] ] + FROM_EMAILS.map { |i| [i, i] }
|
25
|
+
end
|
26
|
+
|
27
|
+
field :subject
|
28
|
+
validates_presence_of :subject
|
29
|
+
|
30
|
+
field :body
|
31
|
+
# validates_presence_of :body
|
32
|
+
|
33
|
+
belongs_to :email_template
|
34
|
+
|
35
|
+
field :sent_at, type: DateTime
|
36
|
+
field :send_at, type: DateTime
|
37
|
+
|
38
|
+
# def campaign_leads
|
39
|
+
# return ::EmailCampaignLead.where( email_campaign_id: self.id.to_s ).includes( :lead )
|
40
|
+
# end
|
41
|
+
|
42
|
+
# def leads
|
43
|
+
# campaign_leads&.map { |p| p.lead }
|
44
|
+
# end
|
45
|
+
|
46
|
+
|
47
|
+
##
|
48
|
+
## For templating:
|
49
|
+
##
|
50
|
+
## commonly: name, companyName
|
51
|
+
field :tmpl, type: Hash, default: {}
|
52
|
+
def body_templated
|
53
|
+
out = email_template.body
|
54
|
+
tmpl.each do |k, v|
|
55
|
+
out.gsub!("{#{k}}", v)
|
56
|
+
end
|
57
|
+
out
|
58
|
+
end
|
59
|
+
|
60
|
+
field :to_email
|
61
|
+
validates_presence_of :to_email, if: -> { type == TYPE_SINGLE }
|
62
|
+
|
63
|
+
#
|
64
|
+
# For tracking
|
65
|
+
#
|
66
|
+
attr_reader :tid
|
67
|
+
|
68
|
+
end
|
data/lib/ish/email_context.rb
CHANGED
@@ -1,20 +1,23 @@
|
|
1
1
|
|
2
2
|
#
|
3
|
-
# Sends a single email
|
3
|
+
# Sends a single email
|
4
4
|
#
|
5
5
|
|
6
6
|
class Ish::EmailContext
|
7
7
|
include Mongoid::Document
|
8
8
|
include Mongoid::Timestamps
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
## @TODO: probably rename it to slug
|
11
|
+
field :slug
|
12
|
+
validates_uniqueness_of :slug, allow_nil: true
|
13
|
+
def title
|
14
|
+
slug
|
13
15
|
end
|
14
16
|
|
15
17
|
PAGE_PARAM_NAME = 'email_contexts_page'
|
16
18
|
|
17
|
-
FROM_EMAILS = %w|
|
19
|
+
FROM_EMAILS = %w| hello@infiniteshelter.com no-reply@infiniteshelter.com
|
20
|
+
piousbox@gmail.com victor@piousbox.com no-reply@piousbox.com
|
18
21
|
admin@wasya.co hello@wasya.co no-reply@wasya.co victor@wasya.co |
|
19
22
|
field :from_email
|
20
23
|
validates_presence_of :from_email
|
@@ -22,6 +25,7 @@ class Ish::EmailContext
|
|
22
25
|
[ [nil, nil] ] + FROM_EMAILS.map { |i| [i, i] }
|
23
26
|
end
|
24
27
|
|
28
|
+
## @deprecated, campaigns are now separate.
|
25
29
|
TYPE_SINGLE = 'TYPE_SINGLE'
|
26
30
|
TYPE_CAMPAIGN = 'TYPE_CAMPAIGN'
|
27
31
|
field :type, default: TYPE_SINGLE
|
data/lib/ish_models.rb
CHANGED
@@ -13,6 +13,8 @@ module Ish; end
|
|
13
13
|
# I need this thing for permissions???
|
14
14
|
class Manager; end
|
15
15
|
|
16
|
+
module Office; end
|
17
|
+
|
16
18
|
module Warbler; end
|
17
19
|
|
18
20
|
module IshModels
|
@@ -44,6 +46,7 @@ require 'gameui/premium_purchase'
|
|
44
46
|
|
45
47
|
require 'ish/cache_key'
|
46
48
|
require 'ish/crawler'
|
49
|
+
require 'ish/email_campaign'
|
47
50
|
require 'ish/email_context'
|
48
51
|
require 'ish/email_template'
|
49
52
|
require 'ish/email_unsubscribe'
|
@@ -63,6 +66,10 @@ require 'photo'
|
|
63
66
|
require 'report'
|
64
67
|
require 'video'
|
65
68
|
|
69
|
+
require 'office/action'
|
70
|
+
require 'office/email_message'
|
71
|
+
|
72
|
+
|
66
73
|
|
67
74
|
|
68
75
|
|
@@ -0,0 +1,44 @@
|
|
1
|
+
|
2
|
+
##
|
3
|
+
## Such actions as auto-responder.
|
4
|
+
##
|
5
|
+
class Office::Action
|
6
|
+
include Mongoid::Document
|
7
|
+
include Mongoid::Timestamps
|
8
|
+
|
9
|
+
field :status, type: String, default: 'active'
|
10
|
+
field :channel, type: String ## eg 'email'
|
11
|
+
field :match_from, type: String ## eg '@synchrony.com', '*@synchrony.com$'
|
12
|
+
|
13
|
+
scope :active, -> { where( status: 'active' ) }
|
14
|
+
|
15
|
+
## eg [ { 'method': 'create_lead', 'params': {} },
|
16
|
+
## { 'method': 'autorespond', 'params': {}, ... ]
|
17
|
+
field :actions, type: Array, default: []
|
18
|
+
|
19
|
+
def self.create_lead params
|
20
|
+
msg = params[:msg]
|
21
|
+
leadset = Leadset.find_or_create_by({ company_url: msg.company_url })
|
22
|
+
lead = Lead.new({
|
23
|
+
email: msg.from_str,
|
24
|
+
name: msg.name,
|
25
|
+
leadset: leadset,
|
26
|
+
})
|
27
|
+
lead.save
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.autorespond params
|
31
|
+
msg = params[:msg]
|
32
|
+
email_template = ::Ish::EmailTemplate.find_by!({ slug: '20230207-autorespond' })
|
33
|
+
email_ctx = ::Ish::EmailContext.new({
|
34
|
+
to_email: '',
|
35
|
+
subject: '',
|
36
|
+
from_email: '',
|
37
|
+
body: '',
|
38
|
+
email_template_id: email_template.id.to_s,
|
39
|
+
})
|
40
|
+
email_ctx.save!
|
41
|
+
IshManager::OfficeMailer.send_context_email( email_ctx ).deliver_later
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
|
2
|
+
##
|
3
|
+
## When I receive one.
|
4
|
+
##
|
5
|
+
class Office::EmailMessage
|
6
|
+
include Mongoid::Document
|
7
|
+
include Mongoid::Timestamps
|
8
|
+
|
9
|
+
field :raw, type: :string
|
10
|
+
field :object_key, type: :string ## aka 'filename', use with bucket name + prefix
|
11
|
+
# validates_presence_of :object_key
|
12
|
+
field :object_path, type: :string ## A routable s3 url
|
13
|
+
|
14
|
+
field :subject
|
15
|
+
field :part_txt
|
16
|
+
field :part_html
|
17
|
+
# attachments ?
|
18
|
+
|
19
|
+
field :from, type: Array, default: []
|
20
|
+
def from_str
|
21
|
+
from.join(", ")
|
22
|
+
end
|
23
|
+
|
24
|
+
field :to, type: Array, default: []
|
25
|
+
field :cc, type: Array, default: []
|
26
|
+
field :bss, type: Array, default: []
|
27
|
+
field :date, type: DateTime
|
28
|
+
def received_at
|
29
|
+
date
|
30
|
+
end
|
31
|
+
|
32
|
+
## @TODO: reimplement, look at footer instead.
|
33
|
+
def name
|
34
|
+
return 'associate'
|
35
|
+
# from[0].split('@')[0].upcase
|
36
|
+
end
|
37
|
+
|
38
|
+
def company_url
|
39
|
+
from[0].split('@')[1]
|
40
|
+
end
|
41
|
+
|
42
|
+
def process
|
43
|
+
Aws.config[:credentials] = Aws::Credentials.new(
|
44
|
+
::S3_CREDENTIALS[:access_key_id],
|
45
|
+
::S3_CREDENTIALS[:secret_access_key]
|
46
|
+
)
|
47
|
+
s3 = Aws::S3::Client.new
|
48
|
+
|
49
|
+
obj = s3.get_object({
|
50
|
+
bucket: 'ish-ses',
|
51
|
+
key: self.object_key
|
52
|
+
})
|
53
|
+
obj2 = obj.body.read
|
54
|
+
|
55
|
+
mail = Mail.read_from_string( obj2 )
|
56
|
+
self.from = mail.from
|
57
|
+
self.to = mail.to
|
58
|
+
self.subject = mail.subject
|
59
|
+
self.date = mail.date
|
60
|
+
self.raw = obj2
|
61
|
+
|
62
|
+
self.save
|
63
|
+
end
|
64
|
+
|
65
|
+
## action.match_from = '@synchrony.com'
|
66
|
+
def apply_actions
|
67
|
+
triggers = Office::Action.active.where({ channel: 'email' })
|
68
|
+
triggers.each do |trigger|
|
69
|
+
if self.from_str.match(/#{trigger.match_from}/i)
|
70
|
+
trigger.actions do |action|
|
71
|
+
Office::Action.call( action[:method], { msg: self }.merge( action[:params] ))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
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: 0.0.33.
|
4
|
+
version: 0.0.33.192
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- piousbox
|
@@ -125,6 +125,7 @@ files:
|
|
125
125
|
- lib/ish/cache_key.rb
|
126
126
|
- lib/ish/configuration.rb
|
127
127
|
- lib/ish/crawler.rb
|
128
|
+
- lib/ish/email_campaign.rb
|
128
129
|
- lib/ish/email_context.rb
|
129
130
|
- lib/ish/email_template.rb
|
130
131
|
- lib/ish/email_unsubscribe.rb
|
@@ -146,6 +147,8 @@ files:
|
|
146
147
|
- lib/mongoid/votable.rb
|
147
148
|
- lib/mongoid/voter.rb
|
148
149
|
- lib/newsitem.rb
|
150
|
+
- lib/office/action.rb
|
151
|
+
- lib/office/email_message.rb
|
149
152
|
- lib/photo.rb
|
150
153
|
- lib/report.rb
|
151
154
|
- lib/trash/app_model2.rb
|