talktome 1.1.2 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/talktome/app.rb +13 -9
- data/lib/talktome/client/local.rb +1 -1
- data/lib/talktome/error.rb +1 -0
- data/lib/talktome/strategy/email.rb +1 -0
- data/lib/talktome/version.rb +1 -1
- data/spec/app/test_app.rb +73 -0
- data/spec/client/test_local.rb +1 -0
- data/spec/fixtures/contact-us/email.md +13 -0
- data/spec/fixtures/multi-lingual/en/email.md +13 -0
- data/spec/fixtures/support/email.md +6 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ae24a6e1def52e8f6b89ba6dd6ade0f5dc7d41182d591a573215c1a75d49603
|
4
|
+
data.tar.gz: ad8ca169cd9619c21e0af5af7f862b65730105f95276881449ab1877626dcefb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fee101432b406429b2c8761311e9616181766cd7904db0678adba35b32ebd26c3d709cd90cc1173545ac27d6ff310ca7edf284de3fc31215d831ea4d47ed7d6b
|
7
|
+
data.tar.gz: 6827ee15c92c7d6487aaac7b7c850c2e327a2bbc95a84f213f16593fb7017219779f6163ea702cf50e8d1010c3fffa8a69181890581e8427c7c5472a19477110
|
data/lib/talktome/app.rb
CHANGED
@@ -13,36 +13,39 @@ module Talktome
|
|
13
13
|
|
14
14
|
set :raise_errors, true
|
15
15
|
set :show_exceptions, false
|
16
|
+
set :talktome, Talktome::Client::Local.new(ROOT_FOLDER/'templates')
|
16
17
|
|
17
18
|
VALIDATION_SCHEMA = ::Finitio.system(<<~FIO)
|
18
19
|
@import finitio/data
|
19
20
|
Email = String(s | s =~ /^[^@]+@[^@]+$/ )
|
20
21
|
{
|
21
|
-
to
|
22
|
-
reply_to
|
23
|
-
|
22
|
+
to :? Email
|
23
|
+
reply_to :? Email
|
24
|
+
in_reply_to :? String
|
25
|
+
... : .Object
|
24
26
|
}
|
25
27
|
FIO
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
-
post %r{/([a-z-]+)/} do |action|
|
29
|
+
post %r{/([a-z-]+([\/][a-z-]+)*)/} do |action, _|
|
30
30
|
begin
|
31
31
|
as_array = info.map{|k,v| {'key' => k.capitalize, 'value' => v}}
|
32
32
|
subject = Talktome.env('TALKTOME_EMAIL_SUBJECT', 'Someone wants to reach you!')
|
33
33
|
footer = Talktome.env('TALKTOME_EMAIL_FOOTER', "Truly yours,\n
|
34
34
|
Sent by [Enspirit.be](https://enspirit.be/), contact us if you need help with any IT task.")
|
35
35
|
user = load_user_from_info!
|
36
|
-
|
36
|
+
settings.talktome.talktome(action, user, info.merge(allvars: as_array, subject: subject, footer: footer), [:email]){|email|
|
37
37
|
email.reply_to = info[:reply_to] if info.has_key?(:reply_to)
|
38
|
+
email.in_reply_to = info[:in_reply_to] if info.has_key?(:in_reply_to)
|
38
39
|
}
|
39
40
|
[ 200, { "Content-Type" => "text/plain"}, ["Ok"] ]
|
40
41
|
rescue JSON::ParserError
|
41
42
|
fail!("Invalid data")
|
42
43
|
rescue Finitio::Error => ex
|
43
44
|
fail!(ex.message)
|
44
|
-
rescue ::Talktome::InvalidEmailError
|
45
|
+
rescue ::Talktome::InvalidEmailError
|
45
46
|
fail!("Invalid email address")
|
47
|
+
rescue ::Talktome::TemplateNotFoundError
|
48
|
+
fail!("No such template", 404)
|
46
49
|
end
|
47
50
|
end
|
48
51
|
|
@@ -55,7 +58,8 @@ module Talktome
|
|
55
58
|
end
|
56
59
|
|
57
60
|
def load_user_from_info!
|
58
|
-
|
61
|
+
protected_fields = [:to, :in_reply_to]
|
62
|
+
if (info.keys & protected_fields).any?
|
59
63
|
secret = Talktome.env('TALKTOME_BEARER_SECRET')
|
60
64
|
fail!("Missing secret", 400) unless secret
|
61
65
|
fail!("Invalid secret", 401) unless "Bearer #{secret}" == env["HTTP_AUTHORIZATION"]
|
@@ -17,7 +17,7 @@ module Talktome
|
|
17
17
|
|
18
18
|
def load_message!(identifier, strategies)
|
19
19
|
folder = self.folder/identifier
|
20
|
-
raise
|
20
|
+
raise TemplateNotFoundError, "No such message `#{identifier}`" unless folder.exists?
|
21
21
|
raise InvalidMessageError, "Message `#{identifier}` should be a folder" unless folder.directory?
|
22
22
|
strategies.each do |s|
|
23
23
|
if (file = folder.glob("#{s}.*").first) && file.file?
|
data/lib/talktome/error.rb
CHANGED
data/lib/talktome/version.rb
CHANGED
data/spec/app/test_app.rb
CHANGED
@@ -9,6 +9,7 @@ module Talktome
|
|
9
9
|
}
|
10
10
|
|
11
11
|
before(:each) do
|
12
|
+
Talktome::App.set :talktome, Talktome::Client::Local.new(Path.dir.parent/'fixtures')
|
12
13
|
ENV['TALKTOME_EMAIL_DEFAULT_TO'] = "to@talktome.com"
|
13
14
|
ENV['TALKTOME_EMAIL_DEFAULT_FROM'] = "from@talktome.com"
|
14
15
|
Mail::TestMailer.deliveries.clear
|
@@ -162,5 +163,77 @@ module Talktome
|
|
162
163
|
end
|
163
164
|
end
|
164
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 /multi-lingual/en/' do
|
206
|
+
|
207
|
+
it 'works' do
|
208
|
+
post "/multi-lingual/en/", {
|
209
|
+
reply_to: 'hello@visitor.com',
|
210
|
+
message: 'Hello from visitor',
|
211
|
+
key: 'value',
|
212
|
+
}.to_json, { "CONTENT_TYPE" => "application/json" }
|
213
|
+
expect(last_response.status).to eql(200)
|
214
|
+
expect(last_response).to be_ok
|
215
|
+
expect(Mail::TestMailer.deliveries.length).to eql(1)
|
216
|
+
expect(Mail::TestMailer.deliveries.first.to).to eql(["to@talktome.com"])
|
217
|
+
expect(Mail::TestMailer.deliveries.first.from).to eql(["from@talktome.com"])
|
218
|
+
expect(Mail::TestMailer.deliveries.first.subject).to eql("Someone wants to reach you!")
|
219
|
+
expect(Mail::TestMailer.deliveries.first.html_part.body).to include("<li>Key: value</li>")
|
220
|
+
expect(Mail::TestMailer.deliveries.first.html_part.body).to include("Truly yours")
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
context 'POST /xxx when the template does not exist' do
|
225
|
+
|
226
|
+
it 'return a 404 error when the template doesn\'t exist' do
|
227
|
+
post "/multi-lingual/fr/", {
|
228
|
+
reply_to: 'hello@visitor.com',
|
229
|
+
message: 'Hello from visitor',
|
230
|
+
key: 'value',
|
231
|
+
}.to_json, { "CONTENT_TYPE" => "application/json" }
|
232
|
+
|
233
|
+
expect(last_response.status).to eql(404)
|
234
|
+
expect(last_response.body).to match(/No such template/)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
165
238
|
end
|
166
239
|
end
|
data/spec/client/test_local.rb
CHANGED
@@ -74,6 +74,7 @@ module Talktome
|
|
74
74
|
client.talktome("welcome", user, tpldata, [:email])
|
75
75
|
expect(strategy.last.message.to_html).to eql("<html><title>Hello Test user</title><body><h1>Hello Test user</h1>\n\n<p>Welcome to this email example!</p>\n\n<h3>Test user</h3>\n</body></html>\n")
|
76
76
|
end
|
77
|
+
|
77
78
|
end
|
78
79
|
|
79
80
|
end
|
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: 1.
|
4
|
+
version: 1.3.2
|
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-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -191,7 +191,10 @@ files:
|
|
191
191
|
- lib/talktome/version.rb
|
192
192
|
- spec/app/test_app.rb
|
193
193
|
- spec/client/test_local.rb
|
194
|
+
- spec/fixtures/contact-us/email.md
|
194
195
|
- spec/fixtures/layouts/email.html
|
196
|
+
- spec/fixtures/multi-lingual/en/email.md
|
197
|
+
- spec/fixtures/support/email.md
|
195
198
|
- spec/fixtures/welcome/email.md
|
196
199
|
- spec/fixtures/welcome/footer.mustache
|
197
200
|
- spec/message/test_initialize.rb
|
@@ -220,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
220
223
|
- !ruby/object:Gem::Version
|
221
224
|
version: '0'
|
222
225
|
requirements: []
|
223
|
-
rubygems_version: 3.2.
|
226
|
+
rubygems_version: 3.2.32
|
224
227
|
signing_key:
|
225
228
|
specification_version: 4
|
226
229
|
summary: Talktome helps you talk to users by email, messaging, sms, etc.
|