stealth-twilio 0.10.2 → 1.3.1
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/Gemfile +5 -0
- data/Gemfile.lock +53 -44
- data/VERSION +1 -1
- data/lib/stealth/services/twilio/client.rb +36 -5
- data/lib/stealth/services/twilio/message_handler.rb +1 -0
- data/lib/stealth/services/twilio/reply_handler.rb +63 -5
- data/lib/stealth/services/twilio/setup.rb +4 -1
- data/stealth-twilio.gemspec +1 -1
- metadata +10 -12
- data/LICENSE +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e58ea195cdd02ebe016c6a3b734b8328dbe401451c44f0cc025ee756433c8ed8
|
4
|
+
data.tar.gz: 35b65726eda6979d2924473431b496612f0cc1ff917cfd40e6325a91f9cf133f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae36604edc20f7a4117d5deb12e2c09443f5052b990ba7a318353de20207b34cbb7f483f2109001b58c110130b5fee7929b892ebd47b6c0bb1e27a6db149aa96
|
7
|
+
data.tar.gz: 768f4f5406f69f2fbb785a6d24e1b6842b05d5b8e5a8046699b1e71fc10ef4ea27093fe474853aa887cb6d98c5a25318dd2764691f3c198971a8e5a1d3491628
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,80 +1,88 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
stealth-twilio (
|
5
|
-
stealth (
|
4
|
+
stealth-twilio (1.3.1)
|
5
|
+
stealth (~> 2.2)
|
6
6
|
twilio-ruby (~> 5.5)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
|
+
remote: https://EBQGt-IDpU8vpliiVe76xe1CJ8OOuu48w@gem.fury.io/whoisblackops/
|
10
11
|
specs:
|
11
|
-
activesupport (
|
12
|
+
activesupport (6.0.2.2)
|
12
13
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
14
|
i18n (>= 0.7, < 2)
|
14
15
|
minitest (~> 5.1)
|
15
16
|
tzinfo (~> 1.1)
|
16
|
-
|
17
|
+
zeitwerk (~> 2.2)
|
18
|
+
concurrent-ruby (1.1.6)
|
17
19
|
connection_pool (2.2.2)
|
18
20
|
diff-lcs (1.3)
|
19
|
-
faraday (0.
|
21
|
+
faraday (1.0.1)
|
20
22
|
multipart-post (>= 1.2, < 3)
|
21
|
-
i18n (1.2
|
23
|
+
i18n (1.8.2)
|
22
24
|
concurrent-ruby (~> 1.0)
|
23
|
-
jwt (2.1
|
25
|
+
jwt (2.2.1)
|
24
26
|
mini_portile2 (2.4.0)
|
25
|
-
minitest (5.
|
26
|
-
multi_json (1.
|
27
|
-
multipart-post (2.
|
28
|
-
mustermann (1.
|
29
|
-
|
27
|
+
minitest (5.14.0)
|
28
|
+
multi_json (1.14.1)
|
29
|
+
multipart-post (2.1.1)
|
30
|
+
mustermann (1.1.1)
|
31
|
+
ruby2_keywords (~> 0.0.1)
|
32
|
+
nio4r (2.5.2)
|
33
|
+
nokogiri (1.10.9)
|
30
34
|
mini_portile2 (~> 2.4.0)
|
31
|
-
puma (3.
|
32
|
-
|
33
|
-
rack
|
35
|
+
puma (4.3.3)
|
36
|
+
nio4r (~> 2.0)
|
37
|
+
rack (2.2.2)
|
38
|
+
rack-protection (2.0.8.1)
|
34
39
|
rack
|
35
40
|
rack-test (1.1.0)
|
36
41
|
rack (>= 1.0, < 3)
|
37
|
-
redis (4.1.
|
38
|
-
rspec (3.
|
39
|
-
rspec-core (~> 3.
|
40
|
-
rspec-expectations (~> 3.
|
41
|
-
rspec-mocks (~> 3.
|
42
|
-
rspec-core (3.
|
43
|
-
rspec-support (~> 3.
|
44
|
-
rspec-expectations (3.
|
42
|
+
redis (4.1.3)
|
43
|
+
rspec (3.9.0)
|
44
|
+
rspec-core (~> 3.9.0)
|
45
|
+
rspec-expectations (~> 3.9.0)
|
46
|
+
rspec-mocks (~> 3.9.0)
|
47
|
+
rspec-core (3.9.1)
|
48
|
+
rspec-support (~> 3.9.1)
|
49
|
+
rspec-expectations (3.9.1)
|
45
50
|
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
-
rspec-support (~> 3.
|
47
|
-
rspec-mocks (3.
|
51
|
+
rspec-support (~> 3.9.0)
|
52
|
+
rspec-mocks (3.9.1)
|
48
53
|
diff-lcs (>= 1.2.0, < 2.0)
|
49
|
-
rspec-support (~> 3.
|
50
|
-
rspec-support (3.
|
54
|
+
rspec-support (~> 3.9.0)
|
55
|
+
rspec-support (3.9.2)
|
51
56
|
rspec_junit_formatter (0.4.1)
|
52
57
|
rspec-core (>= 2, < 4, != 2.12.0)
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
+
ruby2_keywords (0.0.2)
|
59
|
+
sidekiq (6.0.6)
|
60
|
+
connection_pool (>= 2.2.2)
|
61
|
+
rack (~> 2.0)
|
62
|
+
rack-protection (>= 2.0.0)
|
63
|
+
redis (>= 4.1.0)
|
64
|
+
sinatra (2.0.8.1)
|
58
65
|
mustermann (~> 1.0)
|
59
66
|
rack (~> 2.0)
|
60
|
-
rack-protection (= 2.0.
|
67
|
+
rack-protection (= 2.0.8.1)
|
61
68
|
tilt (~> 2.0)
|
62
|
-
stealth (
|
63
|
-
activesupport (~>
|
69
|
+
stealth (2.4.0)
|
70
|
+
activesupport (~> 6.0)
|
64
71
|
multi_json (~> 1.12)
|
65
|
-
puma (
|
66
|
-
sidekiq (~>
|
72
|
+
puma (>= 4.2, < 5.0)
|
73
|
+
sidekiq (~> 6.0)
|
67
74
|
sinatra (~> 2.0)
|
68
|
-
thor (~> 0
|
69
|
-
thor (0.
|
75
|
+
thor (~> 1.0)
|
76
|
+
thor (1.0.1)
|
70
77
|
thread_safe (0.3.6)
|
71
|
-
tilt (2.0.
|
72
|
-
twilio-ruby (5.
|
73
|
-
faraday (~> 0.
|
78
|
+
tilt (2.0.10)
|
79
|
+
twilio-ruby (5.33.0)
|
80
|
+
faraday (~> 1.0.0)
|
74
81
|
jwt (>= 1.5, <= 2.5)
|
75
82
|
nokogiri (>= 1.6, < 2.0)
|
76
|
-
tzinfo (1.2.
|
83
|
+
tzinfo (1.2.7)
|
77
84
|
thread_safe (~> 0.1)
|
85
|
+
zeitwerk (2.3.0)
|
78
86
|
|
79
87
|
PLATFORMS
|
80
88
|
ruby
|
@@ -83,7 +91,8 @@ DEPENDENCIES
|
|
83
91
|
rack-test (~> 1.1)
|
84
92
|
rspec (~> 3.6)
|
85
93
|
rspec_junit_formatter (~> 0.3)
|
94
|
+
stealth (~> 2.2)!
|
86
95
|
stealth-twilio!
|
87
96
|
|
88
97
|
BUNDLED WITH
|
89
|
-
1.
|
98
|
+
2.1.4
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
1.3.1
|
@@ -10,7 +10,6 @@ require 'stealth/services/twilio/setup'
|
|
10
10
|
module Stealth
|
11
11
|
module Services
|
12
12
|
module Twilio
|
13
|
-
|
14
13
|
class Client < Stealth::Services::BaseClient
|
15
14
|
|
16
15
|
attr_reader :twilio_client, :reply
|
@@ -18,20 +17,52 @@ module Stealth
|
|
18
17
|
def initialize(reply:)
|
19
18
|
@reply = reply
|
20
19
|
account_sid = Stealth.config.twilio.account_sid
|
20
|
+
api_key = Stealth.config.twilio.api_key
|
21
21
|
auth_token = Stealth.config.twilio.auth_token
|
22
|
-
|
22
|
+
|
23
|
+
if api_key.present?
|
24
|
+
@twilio_client = ::Twilio::REST::Client.new(
|
25
|
+
api_key, auth_token, account_sid
|
26
|
+
)
|
27
|
+
else
|
28
|
+
@twilio_client = ::Twilio::REST::Client.new(account_sid, auth_token)
|
29
|
+
end
|
23
30
|
end
|
24
31
|
|
25
32
|
def transmit
|
26
33
|
# Don't transmit anything for delays
|
27
34
|
return true if reply.blank?
|
28
35
|
|
29
|
-
|
30
|
-
|
36
|
+
begin
|
37
|
+
response = twilio_client.messages.create(reply)
|
38
|
+
rescue ::Twilio::REST::RestError => e
|
39
|
+
case e.message
|
40
|
+
when /21610/ # Attempt to send to unsubscribed recipient
|
41
|
+
raise Stealth::Errors::UserOptOut
|
42
|
+
when /21612/ # 'To' phone number is not currently reachable via SMS
|
43
|
+
raise Stealth::Errors::UserOptOut
|
44
|
+
when /21614/ # 'To' number is not a valid mobile number
|
45
|
+
raise Stealth::Errors::UserOptOut
|
46
|
+
when /30004/ # Message blocked
|
47
|
+
raise Stealth::Errors::UserOptOut
|
48
|
+
when /21211/ # Invalid 'To' Phone Number
|
49
|
+
raise Stealth::Errors::InvalidSessionID
|
50
|
+
when /30003/ # Unreachable destination handset
|
51
|
+
raise Stealth::Errors::InvalidSessionID
|
52
|
+
when /30005/ # Unknown destination handset
|
53
|
+
raise Stealth::Errors::InvalidSessionID
|
54
|
+
else
|
55
|
+
raise
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
Stealth::Logger.l(
|
60
|
+
topic: "twilio",
|
61
|
+
message: "Transmitting. Response: #{response.status}: #{response.error_message}"
|
62
|
+
)
|
31
63
|
end
|
32
64
|
|
33
65
|
end
|
34
|
-
|
35
66
|
end
|
36
67
|
end
|
37
68
|
end
|
@@ -4,9 +4,10 @@
|
|
4
4
|
module Stealth
|
5
5
|
module Services
|
6
6
|
module Twilio
|
7
|
-
|
8
7
|
class ReplyHandler < Stealth::Services::BaseReplyHandler
|
9
8
|
|
9
|
+
ALPHA_ORDINALS = ('A'..'Z').to_a.freeze
|
10
|
+
|
10
11
|
attr_reader :recipient_id, :reply
|
11
12
|
|
12
13
|
def initialize(recipient_id: nil, reply: nil)
|
@@ -17,7 +18,35 @@ module Stealth
|
|
17
18
|
def text
|
18
19
|
check_text_length
|
19
20
|
|
20
|
-
|
21
|
+
translated_reply = reply['text']
|
22
|
+
|
23
|
+
suggestions = generate_suggestions(suggestions: reply['suggestions'])
|
24
|
+
buttons = generate_buttons(buttons: reply['buttons'])
|
25
|
+
|
26
|
+
if suggestions.present?
|
27
|
+
translated_reply = [
|
28
|
+
translated_reply,
|
29
|
+
'Reply with:'
|
30
|
+
].join("\n\n")
|
31
|
+
|
32
|
+
suggestions.each_with_index do |suggestion, i|
|
33
|
+
translated_reply = [
|
34
|
+
translated_reply,
|
35
|
+
"\"#{ALPHA_ORDINALS[i]}\" for #{suggestion}"
|
36
|
+
].join("\n")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
if buttons.present?
|
41
|
+
buttons.each do |button|
|
42
|
+
translated_reply = [
|
43
|
+
translated_reply,
|
44
|
+
button
|
45
|
+
].join("\n\n")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
format_response({ body: translated_reply })
|
21
50
|
end
|
22
51
|
|
23
52
|
def image
|
@@ -52,17 +81,46 @@ module Stealth
|
|
52
81
|
|
53
82
|
def check_text_length
|
54
83
|
if reply['text'].present? && reply['text'].size > 1600
|
55
|
-
raise(ArgumentError,
|
84
|
+
raise(ArgumentError, 'Text messages must be 1600 characters or less.')
|
56
85
|
end
|
57
86
|
end
|
58
87
|
|
59
88
|
def format_response(response)
|
60
|
-
sender_info = {
|
89
|
+
sender_info = {
|
90
|
+
from: Stealth.config.twilio.from_phone,
|
91
|
+
to: recipient_id
|
92
|
+
}
|
61
93
|
response.merge(sender_info)
|
62
94
|
end
|
63
95
|
|
64
|
-
|
96
|
+
def generate_suggestions(suggestions:)
|
97
|
+
return if suggestions.blank?
|
98
|
+
|
99
|
+
mf = suggestions.collect do |suggestion|
|
100
|
+
suggestion['text']
|
101
|
+
end.compact
|
102
|
+
end
|
103
|
+
|
104
|
+
def generate_buttons(buttons:)
|
105
|
+
return if buttons.blank?
|
106
|
+
|
107
|
+
sms_buttons = buttons.map do |button|
|
108
|
+
case button['type']
|
109
|
+
when 'url'
|
110
|
+
"#{button['text']}: #{button['url']}"
|
111
|
+
when 'payload'
|
112
|
+
"To #{button['text'].downcase}: Text #{button['payload'].upcase}"
|
113
|
+
when 'call'
|
114
|
+
"#{button['text']}: #{button['phone_number']}"
|
115
|
+
else # Don't raise for unsupported buttons
|
116
|
+
next
|
117
|
+
end
|
118
|
+
end.compact
|
119
|
+
|
120
|
+
sms_buttons
|
121
|
+
end
|
65
122
|
|
123
|
+
end
|
66
124
|
end
|
67
125
|
end
|
68
126
|
end
|
data/stealth-twilio.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.author = 'Mauricio Gomes'
|
13
13
|
s.email = 'mauricio@edge14.com'
|
14
14
|
|
15
|
-
s.add_dependency 'stealth', '
|
15
|
+
s.add_dependency 'stealth', '~> 2'
|
16
16
|
s.add_dependency 'twilio-ruby', '~> 5.5'
|
17
17
|
|
18
18
|
s.add_development_dependency 'rspec', '~> 3.6'
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stealth-twilio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mauricio Gomes
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: stealth
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2
|
19
|
+
version: '2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '2
|
26
|
+
version: '2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: twilio-ruby
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -90,7 +90,6 @@ files:
|
|
90
90
|
- ".gitignore"
|
91
91
|
- Gemfile
|
92
92
|
- Gemfile.lock
|
93
|
-
- LICENSE
|
94
93
|
- README.md
|
95
94
|
- VERSION
|
96
95
|
- lib/stealth-twilio.rb
|
@@ -107,7 +106,7 @@ homepage: https://github.com/hellostealth/stealth-twilio
|
|
107
106
|
licenses:
|
108
107
|
- MIT
|
109
108
|
metadata: {}
|
110
|
-
post_install_message:
|
109
|
+
post_install_message:
|
111
110
|
rdoc_options: []
|
112
111
|
require_paths:
|
113
112
|
- lib
|
@@ -122,9 +121,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
121
|
- !ruby/object:Gem::Version
|
123
122
|
version: '0'
|
124
123
|
requirements: []
|
125
|
-
|
126
|
-
|
127
|
-
signing_key:
|
124
|
+
rubygems_version: 3.1.2
|
125
|
+
signing_key:
|
128
126
|
specification_version: 4
|
129
127
|
summary: Stealth Twilio SMS driver
|
130
128
|
test_files:
|
data/LICENSE
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright (c) 2017 Mauricio Gomes, Black Ops Bureau
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|