stealth-twilio 0.9.7 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3db80948b7de5320c1df8a43395c3f7733423b7da0dd9d82b7fd1b2882a2998d
4
- data.tar.gz: c93024094e9966e3f7e9ecc75508b7fdb5e3552d81cad88df7bc5196354ff551
3
+ metadata.gz: 8cd3e1257a74bec3f87f2dca0aff9f7ebb2510ab55898e2b717a1d6708aeb3f4
4
+ data.tar.gz: 661be0309e9f7d584bcf4273f2897ab8d2e14cce01ac8a3f96cbbfe0be17deff
5
5
  SHA512:
6
- metadata.gz: 21c82b2def97e193e5edae4b6586af40620adb880cef853b67567e529573e29927b4a46e1ce0fe8b50f5ffc7fb4d826796c877b7d596e820db0cf927d8241d3c
7
- data.tar.gz: 25a203255e492ce09d5dc8da20f14cb2dfdb34d00942cc450ecf881c91b2d049dde7f2f0714d280b1689fd5548dcad47d1fa05724a22ae7319fbeba8b82fd265
6
+ metadata.gz: 43242bb2f3081f380065421f0408cd1239fa00dd1156bf20a74bf71bc0f47dae4ee3efb20090b45bb0d5b2a14bbc4d2e353aed1fe38b0d2004462c3306f13496
7
+ data.tar.gz: 1e28285592fb11d9cd4398fcc7d7f22521fa36799fb5b80e81d09c8ccb40b57ac69198cdab0cc9c000073212d88cbb1600f6eed5949bf2906b63eb5374f119ae
data/Gemfile CHANGED
@@ -1,2 +1,7 @@
1
1
  source 'https://rubygems.org'
2
+
3
+ source 'https://EBQGt-IDpU8vpliiVe76xe1CJ8OOuu48w@gem.fury.io/whoisblackops/' do
4
+ gem 'stealth', '~> 2.2'
5
+ end
6
+
2
7
  gemspec
@@ -1,121 +1,87 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stealth-twilio (0.9.5)
5
- stealth (< 2.0)
4
+ stealth-twilio (1.3.2)
5
+ stealth (~> 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
- actionpack (5.2.1)
12
- actionview (= 5.2.1)
13
- activesupport (= 5.2.1)
14
- rack (~> 2.0)
15
- rack-test (>= 0.6.3)
16
- rails-dom-testing (~> 2.0)
17
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
18
- actionview (5.2.1)
19
- activesupport (= 5.2.1)
20
- builder (~> 3.1)
21
- erubi (~> 1.4)
22
- rails-dom-testing (~> 2.0)
23
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
24
- activemodel (5.2.1)
25
- activesupport (= 5.2.1)
26
- activerecord (5.2.1)
27
- activemodel (= 5.2.1)
28
- activesupport (= 5.2.1)
29
- arel (>= 9.0)
30
- activesupport (5.2.1)
12
+ activesupport (6.0.3.3)
31
13
  concurrent-ruby (~> 1.0, >= 1.0.2)
32
14
  i18n (>= 0.7, < 2)
33
15
  minitest (~> 5.1)
34
16
  tzinfo (~> 1.1)
35
- arel (9.0.0)
36
- builder (3.2.3)
37
- concurrent-ruby (1.0.5)
38
- connection_pool (2.2.2)
39
- crass (1.0.4)
40
- diff-lcs (1.3)
41
- erubi (1.7.1)
42
- faraday (0.15.3)
17
+ zeitwerk (~> 2.2, >= 2.2.2)
18
+ concurrent-ruby (1.1.7)
19
+ connection_pool (2.2.3)
20
+ diff-lcs (1.4.4)
21
+ faraday (1.0.1)
43
22
  multipart-post (>= 1.2, < 3)
44
- i18n (1.1.1)
23
+ i18n (1.8.5)
45
24
  concurrent-ruby (~> 1.0)
46
- jwt (2.1.0)
47
- loofah (2.2.3)
48
- crass (~> 1.0.2)
49
- nokogiri (>= 1.5.9)
50
- method_source (0.9.0)
51
- mini_portile2 (2.3.0)
52
- minitest (5.11.3)
53
- multi_json (1.13.1)
54
- multipart-post (2.0.0)
55
- mustermann (1.0.3)
56
- nokogiri (1.8.5)
57
- mini_portile2 (~> 2.3.0)
58
- puma (3.12.0)
59
- rack (2.0.6)
60
- rack-protection (2.0.4)
25
+ jwt (2.2.2)
26
+ mini_portile2 (2.4.0)
27
+ minitest (5.14.2)
28
+ multi_json (1.15.0)
29
+ multipart-post (2.1.1)
30
+ mustermann (1.1.1)
31
+ ruby2_keywords (~> 0.0.1)
32
+ nio4r (2.5.4)
33
+ nokogiri (1.10.10)
34
+ mini_portile2 (~> 2.4.0)
35
+ puma (4.3.6)
36
+ nio4r (~> 2.0)
37
+ rack (2.2.3)
38
+ rack-protection (2.1.0)
61
39
  rack
62
40
  rack-test (1.1.0)
63
41
  rack (>= 1.0, < 3)
64
- rails-dom-testing (2.0.3)
65
- activesupport (>= 4.2.0)
66
- nokogiri (>= 1.6)
67
- rails-html-sanitizer (1.0.4)
68
- loofah (~> 2.2, >= 2.2.2)
69
- railties (5.2.1)
70
- actionpack (= 5.2.1)
71
- activesupport (= 5.2.1)
72
- method_source
73
- rake (>= 0.8.7)
74
- thor (>= 0.19.0, < 2.0)
75
- rake (12.3.1)
76
- redis (4.0.2)
77
- rspec (3.8.0)
78
- rspec-core (~> 3.8.0)
79
- rspec-expectations (~> 3.8.0)
80
- rspec-mocks (~> 3.8.0)
81
- rspec-core (3.8.0)
82
- rspec-support (~> 3.8.0)
83
- rspec-expectations (3.8.1)
42
+ redis (4.2.2)
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.2)
48
+ rspec-support (~> 3.9.3)
49
+ rspec-expectations (3.9.2)
84
50
  diff-lcs (>= 1.2.0, < 2.0)
85
- rspec-support (~> 3.8.0)
86
- rspec-mocks (3.8.0)
51
+ rspec-support (~> 3.9.0)
52
+ rspec-mocks (3.9.1)
87
53
  diff-lcs (>= 1.2.0, < 2.0)
88
- rspec-support (~> 3.8.0)
89
- rspec-support (3.8.0)
54
+ rspec-support (~> 3.9.0)
55
+ rspec-support (3.9.3)
90
56
  rspec_junit_formatter (0.4.1)
91
57
  rspec-core (>= 2, < 4, != 2.12.0)
92
- sidekiq (5.2.2)
93
- connection_pool (~> 2.2, >= 2.2.2)
94
- rack-protection (>= 1.5.0)
95
- redis (>= 3.3.5, < 5)
96
- sinatra (2.0.4)
97
- mustermann (~> 1.0)
58
+ ruby2_keywords (0.0.2)
59
+ sidekiq (6.1.2)
60
+ connection_pool (>= 2.2.2)
98
61
  rack (~> 2.0)
99
- rack-protection (= 2.0.4)
62
+ redis (>= 4.2.0)
63
+ sinatra (2.1.0)
64
+ mustermann (~> 1.0)
65
+ rack (~> 2.2)
66
+ rack-protection (= 2.1.0)
100
67
  tilt (~> 2.0)
101
- stealth (1.0.4)
102
- activerecord (~> 5.2)
103
- activesupport (~> 5.2)
68
+ stealth (2.5.3)
69
+ activesupport (~> 6.0)
104
70
  multi_json (~> 1.12)
105
- puma (~> 3.10)
106
- railties (~> 5.2)
107
- sidekiq (~> 5.0)
71
+ puma (>= 4.2, < 5.0)
72
+ sidekiq (~> 6.0)
108
73
  sinatra (~> 2.0)
109
- thor (~> 0.20)
110
- thor (0.20.0)
74
+ thor (~> 1.0)
75
+ thor (1.0.1)
111
76
  thread_safe (0.3.6)
112
- tilt (2.0.8)
113
- twilio-ruby (5.15.2)
114
- faraday (~> 0.9)
77
+ tilt (2.0.10)
78
+ twilio-ruby (5.40.2)
79
+ faraday (>= 0.9, < 2.0)
115
80
  jwt (>= 1.5, <= 2.5)
116
81
  nokogiri (>= 1.6, < 2.0)
117
- tzinfo (1.2.5)
82
+ tzinfo (1.2.7)
118
83
  thread_safe (~> 0.1)
84
+ zeitwerk (2.4.0)
119
85
 
120
86
  PLATFORMS
121
87
  ruby
@@ -124,7 +90,8 @@ DEPENDENCIES
124
90
  rack-test (~> 1.1)
125
91
  rspec (~> 3.6)
126
92
  rspec_junit_formatter (~> 0.3)
93
+ stealth (~> 2.2)!
127
94
  stealth-twilio!
128
95
 
129
96
  BUNDLED WITH
130
- 1.16.3
97
+ 2.1.4
data/README.md CHANGED
@@ -10,9 +10,10 @@ The [Stealth](https://github.com/hellostealth/stealth) Twilio SMS driver adds th
10
10
  * Image
11
11
  * Audio
12
12
  * Video
13
+ * File
13
14
  * Delay
14
15
 
15
- Image, Audio, and Video reply types will leverage the MMS protocol. It is recommended by Twilio that
16
+ Image, Audio, Video, and File reply types will leverage the MMS protocol. It is recommended by Twilio that
16
17
  the content is limited to images, however, this is the full list of supported content types: https://www.twilio.com/docs/api/messaging/accepted-mime-types.
17
18
 
18
-
19
+ If you store your files on S3, please make sure you have set the `content-type` appropriately or Twilio might reject your media.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.7
1
+ 1.3.2
@@ -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
- @twilio_client = ::Twilio::REST::Client.new(account_sid, auth_token)
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
- response = twilio_client.messages.create(reply)
30
- Stealth::Logger.l(topic: "twilio", message: "Transmitting. Response: #{response.status}: #{response.error_message}")
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,7 @@
4
4
  module Stealth
5
5
  module Services
6
6
  module Twilio
7
-
8
7
  class MessageHandler < Stealth::Services::BaseMessageHandler
9
-
10
8
  attr_reader :service_message, :params, :headers
11
9
 
12
10
  def initialize(params:, headers:)
@@ -15,7 +13,11 @@ module Stealth
15
13
  end
16
14
 
17
15
  def coordinate
18
- Stealth::Services::HandleMessageJob.perform_async('twilio', params, {})
16
+ Stealth::Services::HandleMessageJob.perform_async(
17
+ 'twilio',
18
+ params,
19
+ headers
20
+ )
19
21
 
20
22
  # Relay our acceptance
21
23
  [204, 'No Content']
@@ -24,23 +26,17 @@ module Stealth
24
26
  def process
25
27
  @service_message = ServiceMessage.new(service: 'twilio')
26
28
  service_message.sender_id = params['From']
29
+ service_message.target_id = params['To']
27
30
  service_message.message = params['Body']
28
31
 
29
32
  # Check for media attachments
30
- attachment_count = 0
31
- begin
32
- attachment_count = Integer(params['NumMedia'])
33
- rescue ArgumentError
34
-
35
- end
33
+ attachment_count = params['NumMedia'].to_i
36
34
 
37
- if attachment_count > 0
38
- for i in (0..attachment_count) do
39
- service_message.attachments << {
40
- type: params["MediaContentType#{i}"],
41
- url: params["MediaUrl#{i}"]
42
- }
43
- end
35
+ attachment_count.times do |i|
36
+ service_message.attachments << {
37
+ type: params["MediaContentType#{i}"],
38
+ url: params["MediaUrl#{i}"]
39
+ }
44
40
  end
45
41
 
46
42
  service_message
@@ -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
- format_response({ body: reply['text'] })
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
@@ -38,6 +67,12 @@ module Stealth
38
67
  format_response({ body: reply['text'], media_url: reply['video_url'] })
39
68
  end
40
69
 
70
+ def file
71
+ check_text_length
72
+
73
+ format_response({ body: reply['text'], media_url: reply['file_url'] })
74
+ end
75
+
41
76
  def delay
42
77
 
43
78
  end
@@ -46,17 +81,46 @@ module Stealth
46
81
 
47
82
  def check_text_length
48
83
  if reply['text'].present? && reply['text'].size > 1600
49
- raise(ArgumentError, "Text messages must be 1600 characters or less.")
84
+ raise(ArgumentError, 'Text messages must be 1600 characters or less.')
50
85
  end
51
86
  end
52
87
 
53
88
  def format_response(response)
54
- sender_info = { from: Stealth.config.twilio.from_phone, to: recipient_id }
89
+ sender_info = {
90
+ from: Stealth.config.twilio.from_phone,
91
+ to: recipient_id
92
+ }
55
93
  response.merge(sender_info)
56
94
  end
57
95
 
58
- end
96
+ def generate_suggestions(suggestions:)
97
+ return if suggestions.blank?
59
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
122
+
123
+ end
60
124
  end
61
125
  end
62
126
  end
@@ -11,7 +11,10 @@ module Stealth
11
11
 
12
12
  class << self
13
13
  def trigger
14
- Stealth::Logger.l(topic: "twilio", message: "There is no setup needed!")
14
+ Stealth::Logger.l(
15
+ topic: "twilio",
16
+ message: "There is no setup needed!"
17
+ )
15
18
  end
16
19
  end
17
20
 
@@ -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', '< 2.0'
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: 0.9.7
4
+ version: 1.3.2
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: 2018-11-06 00:00:00.000000000 Z
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.0'
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.0'
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
- rubyforge_project:
126
- rubygems_version: 2.7.7
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.