plivo 4.49.0 → 4.50.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +1 -1
- data/lib/plivo/resources/messages.rb +90 -7
- data/lib/plivo/template.rb +97 -0
- data/lib/plivo/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 606070046bb7d420278f8016104051f8ebfb3cda
|
4
|
+
data.tar.gz: 365eb4acf62fcbffa1f0ef649aa8ba4676726e36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7eed6b78d2112388c6c6b63169c28875a0b312682a97b25beba7e0e00f55659720894b53c162bdb87c896cb65d5030d07608eaae3cb987b31aa5c112ce7d184b
|
7
|
+
data.tar.gz: da6d8623e7a30512ab5890aed8ce1953b4d864a28c50184b49e61e828981664d0529e88bbd68a7672ff752ee72fbaaf20077108d68fd623fe95620c496462400
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,10 @@
|
|
1
1
|
# Change Log
|
2
|
+
|
3
|
+
## [4.50.0](https://github.com/plivo/plivo-ruby/tree/v4.50.0) (2023-10-13)
|
4
|
+
**Feature - WhatsApp message support**
|
5
|
+
- Added new params `template` and new message_type `whatsapp` to [send message API](https://www.plivo.com/docs/sms/api/message#send-a-message)
|
6
|
+
- Added new `message_state` (`read`), `message_type`(`whatsapp`), `conversation_id`, `conversation_origin`, `conversation_expiration_timestamp` in [list all messages API](https://www.plivo.com/docs/sms/api/message#list-all-messages) and [get message details API](https://www.plivo.com/docs/sms/api/message#retrieve-a-message) response
|
7
|
+
|
2
8
|
## [4.49.0](https://github.com/plivo/plivo-ruby/tree/v4.49.0) (2023-09-13)
|
3
9
|
**Removing the faraday_middleware dependency and upgrade to farady latest version
|
4
10
|
|
data/README.md
CHANGED
@@ -42,7 +42,10 @@ module Plivo
|
|
42
42
|
dlt_template_category: @dlt_template_category,
|
43
43
|
destination_network: @destination_network,
|
44
44
|
carrier_fees_rate: @carrier_fees_rate,
|
45
|
-
carrier_fees: @carrier_fees
|
45
|
+
carrier_fees: @carrier_fees,
|
46
|
+
conversation_id: @conversation_id,
|
47
|
+
conversation_origin: @conversation_origin,
|
48
|
+
conversation_expiration_timestamp: @conversation_expiration_timestamp
|
46
49
|
}.to_s
|
47
50
|
end
|
48
51
|
end
|
@@ -64,7 +67,7 @@ module Plivo
|
|
64
67
|
# @param [Array] dst
|
65
68
|
# @param [String] text
|
66
69
|
# @param [Hash] options
|
67
|
-
# @option options [String] :type The type of message. Should be `sms` or `mms`. Defaults to `sms`.
|
70
|
+
# @option options [String] :type The type of message. Should be `sms` or `mms` or `whatsapp`. Defaults to `sms`.
|
68
71
|
# @option options [String] :url The URL to which with the status of the message is sent. The following parameters are sent to the URL:
|
69
72
|
# - To - Phone number of the recipient
|
70
73
|
# - From - Phone number of the sender
|
@@ -87,13 +90,14 @@ module Plivo
|
|
87
90
|
# @option options [String] :dlt_entity_id This is the DLT entity id passed in the message request.
|
88
91
|
# @option options [String] :dlt_template_id This is the DLT template id passed in the message request.
|
89
92
|
# @option options [String] :dlt_template_category This is the DLT template category passed in the message request.
|
93
|
+
# @option options [Hash] :template This is the template used in the whatsapp message request. It can handle both JSON and String.
|
90
94
|
|
91
95
|
def create(src = nil, dst = nil, text = nil, options = nil, powerpack_uuid = nil)
|
92
96
|
#All params in One HASH
|
93
97
|
value = src
|
94
98
|
if(value.is_a?(Hash))
|
95
99
|
valid_param?(:src, value[:src], [Integer, String, Symbol], false)
|
96
|
-
valid_param?(:text, value[:text], [String, Symbol],
|
100
|
+
valid_param?(:text, value[:text], [String, Symbol], false)
|
97
101
|
valid_param?(:dst, value[:dst], [String, Array], true)
|
98
102
|
valid_param?(:powerpack_uuid, value[:powerpack_uuid], [String, Symbol], false)
|
99
103
|
|
@@ -128,7 +132,7 @@ module Plivo
|
|
128
132
|
end
|
129
133
|
|
130
134
|
#Handling optional params in One HASH
|
131
|
-
if value.key?(:type) && valid_param?(:type, value[:type],String, true, %w[sms mms])
|
135
|
+
if value.key?(:type) && valid_param?(:type, value[:type],String, true, %w[sms mms whatsapp])
|
132
136
|
params[:type] = value[:type]
|
133
137
|
end
|
134
138
|
|
@@ -182,10 +186,44 @@ module Plivo
|
|
182
186
|
params[:dlt_template_category] = value[:dlt_template_category]
|
183
187
|
end
|
184
188
|
|
189
|
+
# handling whatsapp cases
|
190
|
+
if value.key?(:template) && value.key?(:type) && (value[:type] != "whatsapp")
|
191
|
+
raise InvalidRequestError, 'template parameter is only applicable when type is whatsapp'
|
192
|
+
end
|
193
|
+
|
194
|
+
if value.is_a?(Hash) && !value[:template].nil?
|
195
|
+
if value.key?(:template)
|
196
|
+
if value[:template].is_a?(String)
|
197
|
+
begin
|
198
|
+
json_template = JSON.parse(value[:template])
|
199
|
+
params[:template] = json_template
|
200
|
+
rescue JSON::ParserError => e
|
201
|
+
raise InvalidRequestError, 'failed to parse template as JSON'
|
202
|
+
end
|
203
|
+
elsif value[:template].is_a?(Hash)
|
204
|
+
params[:template] = value[:template]
|
205
|
+
elsif value[:template].is_a?(Plivo::Template)
|
206
|
+
params[:template] = value[:template].to_hash
|
207
|
+
else
|
208
|
+
raise InvalidRequestError, 'invalid template format'
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
if !params[:template].nil? && value[:template].is_a?(String)
|
214
|
+
if params.dig(:template, "name").to_s.empty? || params.dig(:template, "language").to_s.empty?
|
215
|
+
raise InvalidRequestError, 'template name and language must not be null or empty'
|
216
|
+
end
|
217
|
+
else
|
218
|
+
if !params[:template].nil? && (params.dig(:template, :name).to_s.empty? || params.dig(:template, :language).to_s.empty?)
|
219
|
+
raise InvalidRequestError, 'template name and language must not be null or empty'
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
185
223
|
#legacy code compatibility
|
186
224
|
else
|
187
225
|
valid_param?(:src, src, [Integer, String, Symbol], false)
|
188
|
-
valid_param?(:text, text, [String, Symbol],
|
226
|
+
valid_param?(:text, text, [String, Symbol], false)
|
189
227
|
valid_param?(:dst, dst, [String, Array], true)
|
190
228
|
valid_param?(:powerpack_uuid, powerpack_uuid, [String, Symbol], false)
|
191
229
|
dst.each do |dst_num|
|
@@ -223,7 +261,7 @@ module Plivo
|
|
223
261
|
valid_param?(:options, options, Hash, true)
|
224
262
|
|
225
263
|
if options.key?(:type) &&
|
226
|
-
valid_param?(:type, options[:type], String, true, %w[sms mms])
|
264
|
+
valid_param?(:type, options[:type], String, true, %w[sms mms whatsapp])
|
227
265
|
params[:type] = options[:type]
|
228
266
|
end
|
229
267
|
|
@@ -286,6 +324,41 @@ module Plivo
|
|
286
324
|
valid_param?(:dlt_template_category, options[:dlt_template_category], String, true)
|
287
325
|
params[:dlt_template_category] = options[:dlt_template_category]
|
288
326
|
end
|
327
|
+
|
328
|
+
# handling whatsapp cases
|
329
|
+
if options.key?(:template) && options.key?(:type) && (options[:type] != "whatsapp")
|
330
|
+
raise InvalidRequestError, 'template parameter is only applicable when type is whatsapp'
|
331
|
+
end
|
332
|
+
|
333
|
+
if options.is_a?(Hash) && !options[:template].nil?
|
334
|
+
if options.key?(:template)
|
335
|
+
if options[:template].is_a?(String)
|
336
|
+
begin
|
337
|
+
json_template = JSON.parse(options[:template])
|
338
|
+
params[:template] = json_template
|
339
|
+
rescue JSON::ParserError => e
|
340
|
+
raise InvalidRequestError, 'failed to parse template as JSON'
|
341
|
+
end
|
342
|
+
elsif options[:template].is_a?(Hash)
|
343
|
+
params[:template] = options[:template]
|
344
|
+
elsif options[:template].is_a?(Plivo::Template)
|
345
|
+
params[:template] = options[:template].to_hash
|
346
|
+
else
|
347
|
+
raise InvalidRequestError, 'invalid template format'
|
348
|
+
end
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
if !options[:template].nil? && options[:template].is_a?(String)
|
353
|
+
if options.dig(:template, "name").to_s.empty? || options.dig(:template, "language").to_s.empty?
|
354
|
+
raise InvalidRequestError, 'template name and language must not be null or empty'
|
355
|
+
end
|
356
|
+
else
|
357
|
+
if !options[:template].nil? && (options.dig(:template, :name).to_s.empty? || options.dig(:template, :language).to_s.empty?)
|
358
|
+
raise InvalidRequestError, 'template name and language must not be null or empty'
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
289
362
|
end
|
290
363
|
perform_create(params)
|
291
364
|
end
|
@@ -293,6 +366,7 @@ module Plivo
|
|
293
366
|
# @param [Hash] options
|
294
367
|
# @option options [String] :subaccount The id of the subaccount, if message details of the subaccount is needed.
|
295
368
|
# @option options [String] :message_direction Filter the results by message direction. The valid inputs are inbound and outbound.
|
369
|
+
# @option options [String] :message_type Filter the results by message type. The valid inputs are sms mms and whatsapp.
|
296
370
|
# @option options [String] :message_time Filter out messages according to the time of completion. The filter can be used in the following five forms:
|
297
371
|
# - message_time: The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. Eg:- To get all messages that were sent/received at 2012-03-21 11:47[:30], use message_time=2012-03-21 11:47[:30]
|
298
372
|
# - message_time\__gt: gt stands for greater than. The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. Eg:- To get all messages that were sent/received after 2012-03-21 11:47, use message_time\__gt=2012-03-21 11:47
|
@@ -310,6 +384,8 @@ module Plivo
|
|
310
384
|
# @option options [string]: tendlc_campaign_id - exact tendlc campaign id search
|
311
385
|
# @option options [string]:destination_country_iso2 - valid 2 character country_iso2
|
312
386
|
# @option options [string] : tendlc_registration_status - registered or unregistered enum allowed
|
387
|
+
# @option options [string] : conversation_id - The id of the conversation for whatsapp messages
|
388
|
+
# @option options [string] : conversartion_origin - The type of the conversation for whatsapp messages
|
313
389
|
def list(options = nil)
|
314
390
|
return perform_list if options.nil?
|
315
391
|
valid_param?(:options, options, Hash, true)
|
@@ -318,6 +394,7 @@ module Plivo
|
|
318
394
|
params_expected = %i[
|
319
395
|
subaccount message_time message_time__gt message_time__gte
|
320
396
|
message_time__lt message_time__lte error_code powerpack_id tendlc_campaign_id tendlc_registration_status destination_country_iso2
|
397
|
+
message_type conversation_id conversartion_origin
|
321
398
|
]
|
322
399
|
params_expected.each do |param|
|
323
400
|
if options.key?(param) &&
|
@@ -341,11 +418,17 @@ module Plivo
|
|
341
418
|
|
342
419
|
if options.key?(:message_state) &&
|
343
420
|
valid_param?(:message_state, options[:message_state],
|
344
|
-
[String, Symbol], true, %w[queued sent failed delivered
|
421
|
+
[String, Symbol], true, %w[queued sent failed delivered read
|
345
422
|
undelivered rejected])
|
346
423
|
params[:message_state] = options[:message_state]
|
347
424
|
end
|
348
425
|
|
426
|
+
if options.key?(:message_type) &&
|
427
|
+
valid_param?(:message_type, options[:message_type],
|
428
|
+
[String, Symbol], true, %w[sms mms whatsapp])
|
429
|
+
params[:message_type] = options[:message_type]
|
430
|
+
end
|
431
|
+
|
349
432
|
if options.key?(:limit) &&
|
350
433
|
(options[:limit] > 20 || options[:limit] <= 0)
|
351
434
|
raise_invalid_request('The maximum number of results that can be '\
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require_relative "resources"
|
2
|
+
require_relative "base_client"
|
3
|
+
require_relative "base"
|
4
|
+
module Plivo
|
5
|
+
class Template
|
6
|
+
attr_accessor :name, :language, :components
|
7
|
+
|
8
|
+
def initialize(name: nil, language: nil, components: nil)
|
9
|
+
@name = name
|
10
|
+
@language = language
|
11
|
+
@components = components
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_hash
|
15
|
+
{
|
16
|
+
name: @name,
|
17
|
+
language: @language,
|
18
|
+
components: @components&.map(&:to_hash)&.reject { |h| h.values.all?(&:nil?) }
|
19
|
+
}.reject { |_, v| v.nil? }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Component
|
24
|
+
attr_accessor :type, :sub_type, :index, :parameters
|
25
|
+
|
26
|
+
def initialize(type: nil, sub_type: nil, index: nil, parameters: nil)
|
27
|
+
@type = type
|
28
|
+
@sub_type = sub_type
|
29
|
+
@index = index
|
30
|
+
@parameters = parameters
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_hash
|
34
|
+
{
|
35
|
+
type: @type,
|
36
|
+
sub_type: @sub_type,
|
37
|
+
index: @index,
|
38
|
+
parameters: @parameters&.map(&:to_hash)&.reject { |h| h.values.all?(&:nil?) }
|
39
|
+
}.reject { |_, v| v.nil? }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class Parameter
|
44
|
+
attr_accessor :type, :text, :media, :currency, :date_time
|
45
|
+
|
46
|
+
def initialize(type: nil, text: nil, media: nil, currency: nil, date_time: nil)
|
47
|
+
@type = type
|
48
|
+
@text = text
|
49
|
+
@media = media
|
50
|
+
@currency = currency
|
51
|
+
@date_time = date_time
|
52
|
+
end
|
53
|
+
|
54
|
+
def to_hash
|
55
|
+
{
|
56
|
+
type: @type,
|
57
|
+
text: @text,
|
58
|
+
media: @media,
|
59
|
+
currency: @currency&.to_hash,
|
60
|
+
date_time: @date_time&.to_hash
|
61
|
+
}.reject { |_, v| v.nil? }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class Currency
|
66
|
+
attr_accessor :fallback_value, :currency_code, :amount_1000
|
67
|
+
|
68
|
+
def initialize(fallback_value: nil, currency_code: nil, amount_1000: nil)
|
69
|
+
@fallback_value = fallback_value
|
70
|
+
@currency_code = currency_code
|
71
|
+
@amount_1000 = amount_1000
|
72
|
+
end
|
73
|
+
|
74
|
+
def to_hash
|
75
|
+
{
|
76
|
+
fallback_value: @fallback_value,
|
77
|
+
currency_code: @currency_code,
|
78
|
+
amount_1000: @amount_1000
|
79
|
+
}.reject { |_, v| v.nil? }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class DateTime
|
84
|
+
attr_accessor :fallback_value
|
85
|
+
|
86
|
+
def initialize(fallback_value: nil)
|
87
|
+
@fallback_value = fallback_value
|
88
|
+
end
|
89
|
+
|
90
|
+
def to_hash
|
91
|
+
{
|
92
|
+
fallback_value: @fallback_value
|
93
|
+
}.reject { |_, v| v.nil? }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
data/lib/plivo/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plivo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.50.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Plivo SDKs Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -193,6 +193,7 @@ files:
|
|
193
193
|
- lib/plivo/resources/regulatory_compliance.rb
|
194
194
|
- lib/plivo/resources/token.rb
|
195
195
|
- lib/plivo/rest_client.rb
|
196
|
+
- lib/plivo/template.rb
|
196
197
|
- lib/plivo/utils.rb
|
197
198
|
- lib/plivo/version.rb
|
198
199
|
- lib/plivo/xml.rb
|