talktome 1.3.1 → 2.0.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/README.md +2 -2
- data/lib/talktome/app.rb +18 -4
- data/lib/talktome/strategy/email.rb +2 -0
- data/lib/talktome/version.rb +3 -3
- data/spec/app/test_app.rb +98 -0
- data/spec/fixtures/support/email.md +6 -0
- metadata +22 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a152ca28790d2d33a6e07329113e3b0c112fabb92e9713fad915e9ac80449e08
|
4
|
+
data.tar.gz: fdd0b125b604058bb01d3bc2ef883ccf4ed600e438a76a0077b064f61f6c45a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 295acd1285168e1beff58e15f43b3f10fc38b46c0dd02726a9b059bde9cf45cee2349492d67a90114b2860583bf57695457e53d79329f64619656f706fbb54c9
|
7
|
+
data.tar.gz: d74897e75e3e241aac8f4dcf554fe901264a6970efd4bee0a91f62bd087f8e09089763dc1ec6aabe553c7971e3f1c1a6dca8e4567fbd6ef260e1d946707184ec
|
data/README.md
CHANGED
@@ -30,7 +30,7 @@ a reusable backend for contact forms.
|
|
30
30
|
|
31
31
|
```
|
32
32
|
docker run \
|
33
|
-
-
|
33
|
+
-p 3000:3000 \
|
34
34
|
-e TALKTOME_EMAIL_DEFAULT_FROM=info@mydomain.com
|
35
35
|
-e TALKTOME_EMAIL_DEFAULT_TO=support@mydomain.com
|
36
36
|
enspirit/talktome
|
@@ -42,7 +42,7 @@ Send an contact-us email through the web api using curl, as follows:
|
|
42
42
|
curl -XPOST \
|
43
43
|
-H'Content-Type: application/json' \
|
44
44
|
-d'{"reply_to": "someone@foo.bar", "message": "Hello"}' \
|
45
|
-
http://127.0.0.1:
|
45
|
+
http://127.0.0.1:3000/contact-us/
|
46
46
|
```
|
47
47
|
|
48
48
|
This web API does not allow specifying `from` and `to` as input data to avoid
|
data/lib/talktome/app.rb
CHANGED
@@ -17,11 +17,20 @@ module Talktome
|
|
17
17
|
|
18
18
|
VALIDATION_SCHEMA = ::Finitio.system(<<~FIO)
|
19
19
|
@import finitio/data
|
20
|
+
Attachment = {
|
21
|
+
mime_type : String
|
22
|
+
content : .Object
|
23
|
+
encoding :? String
|
24
|
+
}
|
20
25
|
Email = String(s | s =~ /^[^@]+@[^@]+$/ )
|
21
26
|
{
|
22
|
-
to
|
23
|
-
reply_to
|
24
|
-
|
27
|
+
to :? Email
|
28
|
+
reply_to :? Email
|
29
|
+
in_reply_to :? String
|
30
|
+
attachments :? {
|
31
|
+
... : Attachment
|
32
|
+
}
|
33
|
+
... : .Object
|
25
34
|
}
|
26
35
|
FIO
|
27
36
|
|
@@ -34,6 +43,10 @@ module Talktome
|
|
34
43
|
user = load_user_from_info!
|
35
44
|
settings.talktome.talktome(action, user, info.merge(allvars: as_array, subject: subject, footer: footer), [:email]){|email|
|
36
45
|
email.reply_to = info[:reply_to] if info.has_key?(:reply_to)
|
46
|
+
email.in_reply_to = info[:in_reply_to] if info.has_key?(:in_reply_to)
|
47
|
+
(info[:attachments] || {}).each do |name, att|
|
48
|
+
email.attachments[name.to_s] = att
|
49
|
+
end
|
37
50
|
}
|
38
51
|
[ 200, { "Content-Type" => "text/plain"}, ["Ok"] ]
|
39
52
|
rescue JSON::ParserError
|
@@ -56,7 +69,8 @@ module Talktome
|
|
56
69
|
end
|
57
70
|
|
58
71
|
def load_user_from_info!
|
59
|
-
|
72
|
+
protected_fields = [:to, :in_reply_to, :attachments]
|
73
|
+
if (info.keys & protected_fields).any?
|
60
74
|
secret = Talktome.env('TALKTOME_BEARER_SECRET')
|
61
75
|
fail!("Missing secret", 400) unless secret
|
62
76
|
fail!("Invalid secret", 401) unless "Bearer #{secret}" == env["HTTP_AUTHORIZATION"]
|
data/lib/talktome/version.rb
CHANGED
data/spec/app/test_app.rb
CHANGED
@@ -163,6 +163,104 @@ module Talktome
|
|
163
163
|
end
|
164
164
|
end
|
165
165
|
|
166
|
+
context 'POST /support/, regarding the In-Reply-To' do
|
167
|
+
class ::Talktome::Message::Template
|
168
|
+
def raise_on_context_miss?
|
169
|
+
false
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'forbids the usage of :in_reply_to unless a secret is provided' do
|
174
|
+
post "/support/", {
|
175
|
+
in_reply_to: '<F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@company.com>',
|
176
|
+
}.to_json, { "CONTENT_TYPE" => "application/json" }
|
177
|
+
expect(last_response.status).to eql(400)
|
178
|
+
expect(Mail::TestMailer.deliveries.length).to eql(0)
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'does not allow setting the :in_reply_to without a valid AUTH token' do
|
182
|
+
Talktome.set_env('TALKTOME_BEARER_SECRET', "Invalid secret") do
|
183
|
+
post "/support/", {
|
184
|
+
in_reply_to: '<F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@company.com>',
|
185
|
+
}.to_json, { "CONTENT_TYPE" => "application/json" }
|
186
|
+
expect(last_response.status).to eql(401)
|
187
|
+
expect(Mail::TestMailer.deliveries.length).to eql(0)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
it "lets override it by passing a inReplyTo field" do
|
192
|
+
Talktome.set_env('TALKTOME_BEARER_SECRET', "Some secret") do
|
193
|
+
header 'Authorization', 'Bearer Some secret'
|
194
|
+
post "/support/", {
|
195
|
+
to: 'client@company.com',
|
196
|
+
in_reply_to: '<F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@company.com>',
|
197
|
+
}.to_json, { "CONTENT_TYPE" => "application/json" }
|
198
|
+
expect(last_response).to be_ok
|
199
|
+
expect(Mail::TestMailer.deliveries.length).to eql(1)
|
200
|
+
expect(Mail::TestMailer.deliveries.first.in_reply_to).to eql('F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@company.com')
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
context 'POST /support/, regarding the attachments' do
|
206
|
+
class ::Talktome::Message::Template
|
207
|
+
def raise_on_context_miss?
|
208
|
+
false
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'forbids the usage of :attachments unless a secret is provided' do
|
213
|
+
post "/support/", {
|
214
|
+
:to => 'client@company.com',
|
215
|
+
:attachments => {
|
216
|
+
"plain.txt" => {
|
217
|
+
"mime_type" => "plain/text",
|
218
|
+
"content" => Base64.encode64('Some plain/text attachment')
|
219
|
+
}
|
220
|
+
}
|
221
|
+
}.to_json, { "CONTENT_TYPE" => "application/json" }
|
222
|
+
expect(last_response.status).to eql(400)
|
223
|
+
expect(Mail::TestMailer.deliveries.length).to eql(0)
|
224
|
+
end
|
225
|
+
|
226
|
+
it 'does not allow setting the :attachments without a valid AUTH token' do
|
227
|
+
Talktome.set_env('TALKTOME_BEARER_SECRET', "Invalid secret") do
|
228
|
+
post "/support/", {
|
229
|
+
:to => 'client@company.com',
|
230
|
+
:attachments => {
|
231
|
+
"plain.txt" => {
|
232
|
+
"mime_type" => "plain/text",
|
233
|
+
"content" => Base64.encode64('Some plain/text attachment')
|
234
|
+
}
|
235
|
+
}
|
236
|
+
}.to_json, { "CONTENT_TYPE" => "application/json" }
|
237
|
+
expect(last_response.status).to eql(401)
|
238
|
+
expect(Mail::TestMailer.deliveries.length).to eql(0)
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
it "lets customize attachments by passing an array" do
|
243
|
+
Talktome.set_env('TALKTOME_BEARER_SECRET', "Some secret") do
|
244
|
+
header 'Authorization', 'Bearer Some secret'
|
245
|
+
post "/support/", {
|
246
|
+
:to => 'client@company.com',
|
247
|
+
:attachments => {
|
248
|
+
"plain.txt" => {
|
249
|
+
"mime_type" => "plain/text",
|
250
|
+
"content" => Base64.encode64('Some plain/text attachment')
|
251
|
+
}
|
252
|
+
}
|
253
|
+
}.to_json, { "CONTENT_TYPE" => "application/json" }
|
254
|
+
expect(last_response).to be_ok
|
255
|
+
expect(Mail::TestMailer.deliveries.length).to eql(1)
|
256
|
+
mail = Mail::TestMailer.deliveries.first
|
257
|
+
expect(mail.attachments['plain.txt']).to be_a_kind_of(Mail::Part)
|
258
|
+
file = mail.attachments['plain.txt']
|
259
|
+
expect(file).to be_a_kind_of(Mail::Part)
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
166
264
|
context 'POST /multi-lingual/en/' do
|
167
265
|
|
168
266
|
it 'works' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: talktome
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernard Lambeau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -75,7 +75,7 @@ dependencies:
|
|
75
75
|
version: '2'
|
76
76
|
- - ">="
|
77
77
|
- !ruby/object:Gem::Version
|
78
|
-
version: 2.
|
78
|
+
version: 2.7.1
|
79
79
|
type: :runtime
|
80
80
|
prerelease: false
|
81
81
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -85,7 +85,7 @@ dependencies:
|
|
85
85
|
version: '2'
|
86
86
|
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: 2.
|
88
|
+
version: 2.7.1
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
90
|
name: mustache
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,7 +120,7 @@ dependencies:
|
|
120
120
|
requirements:
|
121
121
|
- - ">="
|
122
122
|
- !ruby/object:Gem::Version
|
123
|
-
version: '2.
|
123
|
+
version: '2.1'
|
124
124
|
- - "<"
|
125
125
|
- !ruby/object:Gem::Version
|
126
126
|
version: '3.0'
|
@@ -130,7 +130,7 @@ dependencies:
|
|
130
130
|
requirements:
|
131
131
|
- - ">="
|
132
132
|
- !ruby/object:Gem::Version
|
133
|
-
version: '2.
|
133
|
+
version: '2.1'
|
134
134
|
- - "<"
|
135
135
|
- !ruby/object:Gem::Version
|
136
136
|
version: '3.0'
|
@@ -168,6 +168,20 @@ dependencies:
|
|
168
168
|
- - "~>"
|
169
169
|
- !ruby/object:Gem::Version
|
170
170
|
version: '1.1'
|
171
|
+
- !ruby/object:Gem::Dependency
|
172
|
+
name: puma
|
173
|
+
requirement: !ruby/object:Gem::Requirement
|
174
|
+
requirements:
|
175
|
+
- - ">="
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: '5.5'
|
178
|
+
type: :runtime
|
179
|
+
prerelease: false
|
180
|
+
version_requirements: !ruby/object:Gem::Requirement
|
181
|
+
requirements:
|
182
|
+
- - ">="
|
183
|
+
- !ruby/object:Gem::Version
|
184
|
+
version: '5.5'
|
171
185
|
description: Talktome helps you talk to users by email, messaging, sms, etc. It abstracts
|
172
186
|
the messaging mechanisms and lets you manage message templates easily.
|
173
187
|
email: blambeau@gmail.com
|
@@ -194,6 +208,7 @@ files:
|
|
194
208
|
- spec/fixtures/contact-us/email.md
|
195
209
|
- spec/fixtures/layouts/email.html
|
196
210
|
- spec/fixtures/multi-lingual/en/email.md
|
211
|
+
- spec/fixtures/support/email.md
|
197
212
|
- spec/fixtures/welcome/email.md
|
198
213
|
- spec/fixtures/welcome/footer.mustache
|
199
214
|
- spec/message/test_initialize.rb
|
@@ -222,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
237
|
- !ruby/object:Gem::Version
|
223
238
|
version: '0'
|
224
239
|
requirements: []
|
225
|
-
rubygems_version: 3.2.
|
240
|
+
rubygems_version: 3.2.32
|
226
241
|
signing_key:
|
227
242
|
specification_version: 4
|
228
243
|
summary: Talktome helps you talk to users by email, messaging, sms, etc.
|