plivo 4.57.0 → 4.58.0

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
  SHA1:
3
- metadata.gz: a90c7167882dbe60104e0ff29cf88e4b4df1d762
4
- data.tar.gz: e52148f05ce9e96049b63ea1453f9c050932c303
3
+ metadata.gz: dcdea3382ce47522a95bff0850bcc67a582ebb54
4
+ data.tar.gz: 77652b31e99304dc2166f94fa9e7b5384d0c5fe6
5
5
  SHA512:
6
- metadata.gz: 418f3f2d85ea8482e99314de098c8719dae66581a5f9ea9d470ecb7f3820b3829a0348ea704810928d73a513b3704fcce6b3c2058eab247c63fd7bcb6b2916cb
7
- data.tar.gz: 7f69bf8b16f6d7408d0767b58f8b041fe89eb66c2360b8a0fbafd2cb3b6c517118875b19204f3c7259210e98dce611113814771d78f6ed5d82451597e2177e2c
6
+ metadata.gz: dda1d4228d6a950a364da677d7fc561a090e79cf83991c4a14659bf1f37f56229c029fd3f12a1f0e8e6dfc3d3a38237d54dca200095c0e7873025d924285e9ec
7
+ data.tar.gz: e7e0832bb62f63262843787afc5a2107474c4e1133e3ef8b6cb088b8e0d32b15eb3de8afa2731b243af720fc26a908946539051140f8f134f9516c5027d130d1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Change Log
2
2
 
3
+ ## [4.58.0](https://github.com/plivo/plivo-ruby/tree/v4.58.0) (2023-05-17)
4
+ **Feature - Adding support for location whatsapp messages**
5
+ - Added new param `location` to [send message API](https://www.plivo.com/docs/sms/api/message#send-a-message) to support location `whatsapp` messages
6
+ - Added new param `location` in templates to support location based templated messages
7
+
3
8
  ## [4.57.0](https://github.com/plivo/plivo-ruby/tree/v4.57.0) (2023-05-07)
4
9
  **Feature - Adding support for interactive whatsapp messages**
5
10
  - Added new param `interactive` to [send message API](https://www.plivo.com/docs/sms/api/message#send-a-message) to support interactive `whatsapp` messages
data/README.md CHANGED
@@ -9,7 +9,7 @@ The Plivo Ruby SDK makes it simpler to integrate communications into your Ruby a
9
9
  Add this line to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
- gem 'plivo', '>= 4.57.0'
12
+ gem 'plivo', '>= 4.58.0'
13
13
  ```
14
14
 
15
15
  And then execute:
@@ -168,6 +168,354 @@ begin
168
168
  end
169
169
  ```
170
170
 
171
+
172
+ ## WhatsApp Messaging
173
+ Plivo's WhatsApp API allows you to send different types of messages over WhatsApp, including templated messages, free form messages and interactive messages. Below are some examples on how to use the Plivo Go SDK to send these types of messages.
174
+
175
+ ### Templated Messages
176
+ Templated messages are a crucial to your WhatsApp messaging experience, as businesses can only initiate WhatsApp conversation with their customers using templated messages.
177
+
178
+ WhatsApp templates support 4 components: `header` , `body`, `footer` and `button`. At the point of sending messages, the template object you see in the code acts as a way to pass the dynamic values within these components. `header` can accomodate `text` or `media` (images, video, documents) content. `body` can accomodate text content. `button` can support dynamic values in a `url` button or to specify a developer-defined payload which will be returned when the WhatsApp user clicks on the `quick_reply` button. `footer` cannot have any dynamic variables.
179
+
180
+ Example 1:
181
+ ```ruby
182
+ require "plivo"
183
+ include Plivo
184
+
185
+ api = RestClient.new("<auth_id>","<auth_token>")
186
+
187
+ template={
188
+ "name": "template_name",
189
+ "language": "en_US",
190
+ "components": [
191
+ {
192
+ "type": "header",
193
+ "parameters": [
194
+ {
195
+ "type": "media",
196
+ "media": "https://xyz.com/s3/img.jpg"
197
+ }
198
+ ]
199
+ },
200
+ {
201
+ "type": "body",
202
+ "parameters": [
203
+ {
204
+ "type": "text",
205
+ "text": "WA-Text"
206
+ }
207
+ ]
208
+ }
209
+ ]
210
+ }
211
+
212
+ response = api.messages.create(
213
+ src: "+14156667778",
214
+ dst:"+14156667777",
215
+ type:"whatsapp",
216
+ template:template,
217
+ url: "https://<yourdomain>.com/whatsapp_status/",
218
+ )
219
+ puts response
220
+ ```
221
+
222
+ Example 2:
223
+ ```ruby
224
+ require "plivo"
225
+ require "plivo/template"
226
+ include Plivo
227
+
228
+ api = RestClient.new("<auth_id>","<auth_token>")
229
+
230
+ header_media_param = Parameter.new(type: "media", media: "https://xyz.com/s3/img.jpg")
231
+ body_text_params = [ Parameter.new(type: "text", text: "WA-Text") ]
232
+
233
+ header_component = Component.new(type: "header", parameters: [header_media_param])
234
+ body_component = Component.new(type: "body", parameters: body_text_params)
235
+
236
+ template = Template.new(name: "template_name", language: "en_US", components: [header_component, body_component])
237
+
238
+ response = api.messages.create(
239
+ src: "+14156667778",
240
+ dst:"+14156667777",
241
+ type:"whatsapp",
242
+ template:template,
243
+ url: "https://<yourdomain>.com/whatsapp_status/",
244
+ )
245
+ puts response
246
+ ```
247
+ > Note: It is also possible to create and manage objects directly within the SDK for whatsapp, providing a structured approach to message creation.
248
+
249
+ ### Free Form Messages
250
+ Non-templated or Free Form WhatsApp messages can be sent as a reply to a user-initiated conversation (Service conversation) or if there is an existing ongoing conversation created previously by sending a templated WhatsApp message.
251
+
252
+ #### Free Form Text Message
253
+ Example:
254
+ ```ruby
255
+ require "plivo"
256
+ include Plivo
257
+
258
+ api = RestClient.new("<auth_id>","<auth_token>")
259
+ response = api.messages.create(
260
+ src: "+14156667778",
261
+ dst:"+14156667777",
262
+ type:"whatsapp",
263
+ text:"Hello, this is sample text",
264
+ url: "https://<yourdomain>.com/whatsapp_status/",
265
+ )
266
+ puts response
267
+ ```
268
+
269
+ #### Free Form Media Message
270
+ Example:
271
+ ```ruby
272
+ require "plivo"
273
+ include Plivo
274
+
275
+ api = RestClient.new("<auth_id>","<auth_token>")
276
+ response = api.messages.create(
277
+ src: "+14156667778",
278
+ dst:"+14156667777",
279
+ type:"whatsapp",
280
+ text:"Hello, this is sample text",
281
+ media_urls:["https://sample-videos.com/img/Sample-png-image-1mb.png"],
282
+ url: "https://<yourdomain>.com/wa_status/",
283
+ )
284
+ puts response
285
+ ```
286
+
287
+ ### Interactive Messages
288
+ This guide shows how to send non-templated interactive messages to recipients using Plivo’s APIs.
289
+
290
+ #### Quick Reply Buttons
291
+ Quick reply buttons allow customers to quickly respond to your message with predefined options.
292
+
293
+ Example:
294
+ ```ruby
295
+ require "rubygems"
296
+ require "/usr/src/app/lib/plivo.rb"
297
+ include Plivo
298
+
299
+ api = RestClient.new("<auth_id>","<auth_token>")
300
+
301
+ interactive= {
302
+ "type": "button",
303
+ "header": {
304
+ "type": "media",
305
+ "media": "https://xyz.com/s3/img.jpg"
306
+ },
307
+ "body": {
308
+ "text": "Make your selection"
309
+ },
310
+ "action": {
311
+ "buttons": [
312
+ {
313
+ "title": "Click here",
314
+ "id": "bt1"
315
+ },
316
+ {
317
+ "title": "Know More",
318
+ "id": "bt2"
319
+ },
320
+ {
321
+ "title": "Request Callback",
322
+ "id": "bt3"
323
+ }
324
+ ]
325
+ }
326
+ }
327
+
328
+ response = api.messages.create(
329
+ src: "+14156667778",
330
+ dst:"+14156667777",
331
+ type:"whatsapp",
332
+ interactive:interactive
333
+ )
334
+ puts response
335
+ ```
336
+
337
+ #### Interactive Lists
338
+ Interactive lists allow you to present customers with a list of options.
339
+
340
+ Example:
341
+ ```ruby
342
+ require "rubygems"
343
+ require "/usr/src/app/lib/plivo.rb"
344
+ include Plivo
345
+
346
+ api = RestClient.new("<auth_id>","<auth_token>")
347
+
348
+ interactive= {
349
+ "type": "list",
350
+ "header": {
351
+ "type": "text",
352
+ "text": "Welcome to Plivo"
353
+ },
354
+ "body": {
355
+ "text": "You can review the list of rewards we offer"
356
+ },
357
+ "footer": {
358
+ "text": "Yours Truly"
359
+ },
360
+ "action": {
361
+ "buttons": [{
362
+ "title": "Click here"
363
+ }],
364
+ "sections": [
365
+ {
366
+ "title": "SECTION_1_TITLE",
367
+ "rows": [
368
+ {
369
+ "id": "SECTION_1_ROW_1_ID",
370
+ "title": "SECTION_1_ROW_1_TITLE",
371
+ "description": "SECTION_1_ROW_1_DESCRIPTION"
372
+ },
373
+ {
374
+ "id": "SECTION_1_ROW_2_ID",
375
+ "title": "SECTION_1_ROW_2_TITLE",
376
+ "description": "SECTION_1_ROW_2_DESCRIPTION"
377
+ }
378
+ ]
379
+ },
380
+ {
381
+ "title": "SECTION_2_TITLE",
382
+ "rows": [
383
+ {
384
+ "id": "SECTION_2_ROW_1_ID",
385
+ "title": "SECTION_2_ROW_1_TITLE",
386
+ "description": "SECTION_2_ROW_1_DESCRIPTION"
387
+ },
388
+ {
389
+ "id": "SECTION_2_ROW_2_ID",
390
+ "title": "SECTION_2_ROW_2_TITLE",
391
+ "description": "SECTION_2_ROW_2_DESCRIPTION"
392
+ }
393
+ ]
394
+ }
395
+ ]
396
+ }
397
+ }
398
+
399
+ response = api.messages.create(
400
+ src: "+14156667778",
401
+ dst:"+14156667777",
402
+ type:"whatsapp",
403
+ interactive:interactive
404
+ )
405
+ puts response
406
+ ```
407
+
408
+ #### Interactive CTA URLs
409
+ CTA URL messages allow you to send links and call-to-action buttons.
410
+
411
+ Example:
412
+ ```ruby
413
+ require "rubygems"
414
+ require "/usr/src/app/lib/plivo.rb"
415
+ include Plivo
416
+
417
+ api = RestClient.new("<auth_id>","<auth_token>")
418
+
419
+ interactive= {
420
+ "type": "cta_url",
421
+ "header": {
422
+ "type": "media",
423
+ "media": "https://xyz.com/s3/img.jpg"
424
+ },
425
+ "body": {
426
+ "text": "Know More"
427
+ },
428
+ "footer": {
429
+ "text": "Plivo"
430
+ },
431
+ "action": {
432
+ "buttons": [
433
+ {
434
+ "title": "Click here",
435
+ "cta_url": "https:plivo.com"
436
+ }
437
+ ]
438
+ }
439
+ }
440
+
441
+ response = api.messages.create(
442
+ src: "+14156667778",
443
+ dst:"+14156667777",
444
+ type:"whatsapp",
445
+ interactive:interactive
446
+ )
447
+ puts response
448
+ ```
449
+
450
+ ### Location Messages
451
+ This guide shows how to send templated and non-templated location messages to recipients using Plivo’s APIs.
452
+
453
+ #### Templated Location Messages
454
+ Example:
455
+ ```ruby
456
+ require "rubygems"
457
+ require "/usr/src/app/lib/plivo.rb"
458
+ require "/usr/src/app/lib/plivo/template.rb"
459
+ include Plivo
460
+
461
+ api = RestClient.new("<auth_id>","<auth_token>")
462
+
463
+ template= {
464
+ "name": "plivo_order_pickup",
465
+ "language": "en_US",
466
+ "components": [
467
+ {
468
+ "type": "header",
469
+ "parameters": [
470
+ {
471
+ "type": "location",
472
+ "location": {
473
+ "longitude": "122.148981",
474
+ "latitude": "37.483307",
475
+ "name": "Pablo Morales",
476
+ "address": "1 Hacker Way, Menlo Park, CA 94025"
477
+ }
478
+ }
479
+ ]
480
+ }
481
+ ]
482
+ }
483
+
484
+ response = api.messages.create(
485
+ src: "+14156667778",
486
+ dst:"+14156667777",
487
+ type:"whatsapp",
488
+ template:template
489
+ )
490
+ puts response
491
+ ```
492
+
493
+ #### Non-Templated Location Messages
494
+ Example:
495
+ ```ruby
496
+ require "rubygems"
497
+ require "/usr/src/app/lib/plivo.rb"
498
+ require "/usr/src/app/lib/plivo/location.rb"
499
+ include Plivo
500
+
501
+ api = RestClient.new("<auth_id>","<auth_token>")
502
+
503
+ location= {
504
+ "longitude": "122.148981",
505
+ "latitude": "37.483307",
506
+ "name": "Pablo Morales",
507
+ "address": "1 Hacker Way, Menlo Park, CA 94025"
508
+ }
509
+
510
+ response = api.messages.create(
511
+ src: "+14156667778",
512
+ dst:"+14156667777",
513
+ type:"whatsapp",
514
+ location:location
515
+ )
516
+ puts response
517
+ ```
518
+
171
519
  ### More examples
172
520
  More examples are available [here](https://github.com/plivo/plivo-examples-ruby). Also refer to the [guides for configuring the Rails server to run various scenarios](https://www.plivo.com/docs/sms/quickstart/ruby-rails/) & use it to test out your integration in under 5 minutes.
173
521
 
@@ -0,0 +1,22 @@
1
+ module Plivo
2
+ class Location
3
+ attr_accessor :latitude, :longitude, :name, :address
4
+
5
+ def initialize(latitude: nil, longitude: nil, name: nil, address: nil)
6
+ @latitude = latitude
7
+ @longitude = longitude
8
+ @name = name
9
+ @address = address
10
+ end
11
+
12
+ def to_hash
13
+ {
14
+ latitude: @latitude,
15
+ longitude: @longitude,
16
+ name: @name,
17
+ address: @address
18
+ }.reject { |_, v| v.nil? }
19
+ end
20
+ end
21
+ end
22
+
@@ -93,6 +93,7 @@ module Plivo
93
93
  # @option options [String] :dlt_template_category This is the DLT template category passed in the message request.
94
94
  # @option options [Hash] :template This is the template used in the whatsapp message request. It can handle both JSON and String.
95
95
  # @option options [Hash] :interactive This is the interactive parameter used in the whatsapp message request. It can handle both JSON and String.
96
+ # @option options [Hash] :location This is the location parameter used in the whatsapp message request. It can handle both JSON and String.
96
97
 
97
98
  def create(src = nil, dst = nil, text = nil, options = nil, powerpack_uuid = nil)
98
99
  #All params in One HASH
@@ -251,6 +252,25 @@ module Plivo
251
252
  end
252
253
  end
253
254
 
255
+ if value.is_a?(Hash) && !value[:location].nil?
256
+ if value.key?(:location)
257
+ if value[:location].is_a?(String)
258
+ begin
259
+ json_location = JSON.parse(value[:location])
260
+ params[:location] = json_location
261
+ rescue JSON::ParserError => e
262
+ raise InvalidRequestError, 'failed to parse location as JSON'
263
+ end
264
+ elsif value[:location].is_a?(Hash)
265
+ params[:location] = value[:location]
266
+ elsif value[:location].is_a?(Plivo::Location)
267
+ params[:location] = value[:location].to_hash
268
+ else
269
+ raise InvalidRequestError, 'invalid location format'
270
+ end
271
+ end
272
+ end
273
+
254
274
  #legacy code compatibility
255
275
  else
256
276
  valid_param?(:src, src, [Integer, String, Symbol], false)
@@ -415,6 +435,25 @@ module Plivo
415
435
  end
416
436
  end
417
437
 
438
+ if options.is_a?(Hash) && !options[:location].nil?
439
+ if options.key?(:location)
440
+ if options[:location].is_a?(String)
441
+ begin
442
+ json_location = JSON.parse(options[:location])
443
+ params[:location] = json_location
444
+ rescue JSON::ParserError => e
445
+ raise InvalidRequestError, 'failed to parse location as JSON'
446
+ end
447
+ elsif options[:location].is_a?(Hash)
448
+ params[:location] = options[:location]
449
+ elsif options[:location].is_a?(Plivo::Location)
450
+ params[:location] = options[:location].to_hash
451
+ else
452
+ raise InvalidRequestError, 'invalid location format'
453
+ end
454
+ end
455
+ end
456
+
418
457
  end
419
458
  perform_create(params)
420
459
  end
@@ -1,6 +1,7 @@
1
1
  require_relative "resources"
2
2
  require_relative "base_client"
3
3
  require_relative "base"
4
+ require_relative "location"
4
5
  module Plivo
5
6
  class Template
6
7
  attr_accessor :name, :language, :components
@@ -41,15 +42,16 @@ module Plivo
41
42
  end
42
43
 
43
44
  class Parameter
44
- attr_accessor :type, :text, :media, :payload, :currency, :date_time
45
+ attr_accessor :type, :text, :media, :payload, :currency, :date_time, :location
45
46
 
46
- def initialize(type: nil, text: nil, media: nil, payload: nil, currency: nil, date_time: nil)
47
+ def initialize(type: nil, text: nil, media: nil, payload: nil, currency: nil, date_time: nil, location: nil)
47
48
  @type = type
48
49
  @text = text
49
50
  @media = media
50
51
  @payload = payload
51
52
  @currency = currency
52
53
  @date_time = date_time
54
+ @location = location
53
55
  end
54
56
 
55
57
  def to_hash
@@ -59,7 +61,8 @@ module Plivo
59
61
  media: @media,
60
62
  payload: @payload,
61
63
  currency: @currency&.to_hash,
62
- date_time: @date_time&.to_hash
64
+ date_time: @date_time&.to_hash,
65
+ location: @location&.to_hash
63
66
  }.reject { |_, v| v.nil? }
64
67
  end
65
68
  end
data/lib/plivo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Plivo
2
- VERSION = "4.57.0".freeze
2
+ VERSION = "4.58.0".freeze
3
3
  end
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.57.0
4
+ version: 4.58.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: 2024-05-07 00:00:00.000000000 Z
11
+ date: 2024-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -168,6 +168,7 @@ files:
168
168
  - lib/plivo/exceptions.rb
169
169
  - lib/plivo/interactive.rb
170
170
  - lib/plivo/jwt.rb
171
+ - lib/plivo/location.rb
171
172
  - lib/plivo/phlo_client.rb
172
173
  - lib/plivo/resources.rb
173
174
  - lib/plivo/resources/accounts.rb