ish_models 0.0.33.191 → 0.0.33.193
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/iro/option_price_item.rb +6 -0
- data/lib/ish/email_campaign.rb +68 -0
- data/lib/ish/email_context.rb +9 -5
- data/lib/ish_models.rb +8 -2
- data/lib/office/action.rb +44 -0
- data/lib/office/email_message.rb +77 -0
- metadata +33 -2
- data/lib/ish/input_error.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3fc895b3cb92cc734e59ab08fba5811a59ca160946065f741548a9d6cad80be6
|
4
|
+
data.tar.gz: 10d141e79f4b95490f217751152f117801b5ffb3543457f890ba89d3fe29b059
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e867c1540b0759257d40f318f0636dff5f537b1a4c3d727c83b0d8f905c12966c485885c60e48b23ebce496309a9c500b05800eb322712d10a59095fe09a168
|
7
|
+
data.tar.gz: cdca53cb93a7925c869a690347313040023ca6c0b840d934f8a3e6f40d344f2f15cd7df3477844b3751d3e062d87366e8fd712156f0f1b7889be1977a0a80e54
|
@@ -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
@@ -8,12 +8,14 @@ require 'kaminari/mongoid'
|
|
8
8
|
|
9
9
|
class Gameui; end
|
10
10
|
|
11
|
+
module Iro; end
|
12
|
+
class Ish::InputError < RuntimeError; end
|
11
13
|
module Ish; end
|
12
14
|
|
13
15
|
# I need this thing for permissions???
|
14
16
|
class Manager; end
|
15
17
|
|
16
|
-
module
|
18
|
+
module Office; end
|
17
19
|
|
18
20
|
module IshModels
|
19
21
|
|
@@ -44,12 +46,12 @@ 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'
|
50
53
|
require 'ish/gallery_name'
|
51
54
|
require 'ish/image_asset'
|
52
|
-
require 'ish/input_error'
|
53
55
|
require 'ish/invoice'
|
54
56
|
require 'ish/lorem_ipsum'
|
55
57
|
require 'ish/meeting'
|
@@ -63,6 +65,10 @@ require 'photo'
|
|
63
65
|
require 'report'
|
64
66
|
require 'video'
|
65
67
|
|
68
|
+
require 'office/action'
|
69
|
+
require 'office/email_message'
|
70
|
+
|
71
|
+
|
66
72
|
|
67
73
|
|
68
74
|
|
@@ -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.193
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- piousbox
|
@@ -108,6 +108,34 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: mysql2
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.5.4
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.5.4
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rails
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 6.1.0
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 6.1.0
|
111
139
|
description: models of ish
|
112
140
|
email: victor@wasya.co
|
113
141
|
executables: []
|
@@ -122,15 +150,16 @@ files:
|
|
122
150
|
- lib/gameui/map_bookmark.rb
|
123
151
|
- lib/gameui/marker.rb
|
124
152
|
- lib/gameui/premium_purchase.rb
|
153
|
+
- lib/iro/option_price_item.rb
|
125
154
|
- lib/ish/cache_key.rb
|
126
155
|
- lib/ish/configuration.rb
|
127
156
|
- lib/ish/crawler.rb
|
157
|
+
- lib/ish/email_campaign.rb
|
128
158
|
- lib/ish/email_context.rb
|
129
159
|
- lib/ish/email_template.rb
|
130
160
|
- lib/ish/email_unsubscribe.rb
|
131
161
|
- lib/ish/gallery_name.rb
|
132
162
|
- lib/ish/image_asset.rb
|
133
|
-
- lib/ish/input_error.rb
|
134
163
|
- lib/ish/invoice.rb
|
135
164
|
- lib/ish/lorem_ipsum.rb
|
136
165
|
- lib/ish/meeting.rb
|
@@ -146,6 +175,8 @@ files:
|
|
146
175
|
- lib/mongoid/votable.rb
|
147
176
|
- lib/mongoid/voter.rb
|
148
177
|
- lib/newsitem.rb
|
178
|
+
- lib/office/action.rb
|
179
|
+
- lib/office/email_message.rb
|
149
180
|
- lib/photo.rb
|
150
181
|
- lib/report.rb
|
151
182
|
- lib/trash/app_model2.rb
|
data/lib/ish/input_error.rb
DELETED