vonage 7.29.0 → 7.30.0
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/README.md +133 -8
- data/lib/vonage/messaging/channels/messenger.rb +2 -0
- data/lib/vonage/messaging/channels/mms.rb +2 -0
- data/lib/vonage/messaging/channels/rcs.rb +2 -0
- data/lib/vonage/messaging/channels/sms.rb +2 -0
- data/lib/vonage/messaging/channels/viber.rb +3 -1
- data/lib/vonage/messaging/channels/whats_app.rb +2 -0
- data/lib/vonage/messaging/message.rb +3 -1
- data/lib/vonage/messaging.rb +11 -2
- data/lib/vonage/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b5dc7ac328458bc21d7e76e1df003d7cac348ac6aebfeddda3ed07559c296bf
|
4
|
+
data.tar.gz: 96e9dc16dcb13a0aaa67993c92b49647d7b032fa968aadfce14058d8613b47c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca7be62caf505b146ac4cec62f6ee95cdb329ca64d10d51c12ae8c0321a069fc6eaf63f8a1e8ee4c61496d2c6a656647f2c4324ed27d2dc52b7fd1afe8dbd3fb
|
7
|
+
data.tar.gz: 8ff5227e4475ffc63941c45f694779b58c41a4169b51633ff718c48be2a639035d13b9a397ee9fc621da765f42361a89ba902cce531c30b537168f8a7cd3925d
|
data/README.md
CHANGED
@@ -341,26 +341,151 @@ client.applications.list(auto_advance: false)
|
|
341
341
|
|
342
342
|
The [Vonage Messages API](https://developer.vonage.com/messages/overview) allows you to send messages over a number of different channels, and various message types within each channel. See the Vonage Developer Documentation for a [complete API reference](https://developer.vonage.com/en/api/messages) listing all the channel and message type combinations.
|
343
343
|
|
344
|
-
|
344
|
+
### Sending a Message
|
345
|
+
|
346
|
+
The Ruby SDK implements a `Messaging` object which can be accessed via a `messaging` method on the `Client` object. The `Messaging` object has a `send` method which lets you send any message type via any channel.
|
347
|
+
|
348
|
+
```ruby
|
349
|
+
response = client.messaging.send(
|
350
|
+
# message data
|
351
|
+
)
|
352
|
+
```
|
353
|
+
|
354
|
+
There are a number of ways in which you can pass the necessary message data to the method.
|
355
|
+
|
356
|
+
**Using Keyword Arguments**
|
357
|
+
|
358
|
+
You can pass the message properties and their values as keyword arguments to the method. For example:
|
359
|
+
|
360
|
+
```ruby
|
361
|
+
response = client.messaging.send(
|
362
|
+
to: '447700900000',
|
363
|
+
from: '447700900001',
|
364
|
+
channel: 'sms',
|
365
|
+
message_type: 'text',
|
366
|
+
text: 'Hello world!'
|
367
|
+
)
|
368
|
+
```
|
369
|
+
|
370
|
+
**Spread a Hash**
|
371
|
+
|
372
|
+
For more complex message structures, you can define the message as a Hash literal and then spread that Hash as keyword arguments by passing it to the `send` method using the double-splat opertator (`**`). For example:
|
345
373
|
|
346
374
|
```ruby
|
347
|
-
|
348
|
-
|
375
|
+
message = {
|
376
|
+
to: '447700900000',
|
377
|
+
from: '447700900001',
|
378
|
+
channel: 'mms',
|
379
|
+
message_type: 'image',
|
380
|
+
image: {
|
381
|
+
url: 'https://example.com/image.jpg',
|
382
|
+
caption: 'This is an image'
|
383
|
+
}
|
384
|
+
}
|
385
|
+
|
386
|
+
response = client.messaging.send(**message)
|
387
|
+
```
|
388
|
+
|
389
|
+
**Using a Combination of Keyword Arguments and Spread**
|
390
|
+
|
391
|
+
You can use a combination of the above two approaches. This might be useful in situations where you want to iteratively send the same message to multiple recipients, for example:
|
392
|
+
|
393
|
+
```ruby
|
394
|
+
message = {
|
395
|
+
from: '447700900000',
|
396
|
+
channel: 'sms',
|
397
|
+
message_type: 'text',
|
398
|
+
text: 'Hello world!'
|
399
|
+
}
|
400
|
+
|
401
|
+
['447700900001', '447700900002', '447700900003'].each do |to_number|
|
402
|
+
client.messaging.send(to: to_number, **message)
|
403
|
+
end
|
404
|
+
```
|
405
|
+
|
406
|
+
**Using Channel Convenience Methods**
|
407
|
+
|
408
|
+
The Ruby SDK provides convenience methods for each channel which return a Hash object which you can then pass to the `send` method in the same way that you would with a Hash literal. As well as a simpler interface, the convenience methods also provide some basic validation.
|
409
|
+
|
410
|
+
Other than SMS (which has only one type -- `text`), these methods require a `:type` argument, which defines the `message_type` of the message within that channel. They also require a `:message` argument, which defvines the message itself; this is a String in the case of `text` messages, and a Hash containing the appopriate properties for other message types (e.g. `image`). You can also optionally pass an `opts` arguments, the value of which should be a Hash which defines any other property that you want to include in the message.
|
411
|
+
|
412
|
+
```ruby
|
413
|
+
# Using the SMS method like this:
|
414
|
+
message = client.messaging.sms(to: "447700900000", from: "447700900001", message: "Hello world!")
|
415
|
+
|
416
|
+
# is the equivalent of using a Hash literal like this:
|
417
|
+
message = {
|
418
|
+
channel: "sms",
|
419
|
+
to: "447700900000",
|
420
|
+
from: "447700900001",
|
421
|
+
message_type: "text",
|
422
|
+
text: "Hello world!"
|
423
|
+
}
|
424
|
+
```
|
425
|
+
|
426
|
+
Once the message Hash is created, you can then pass it into the `send` method using the double-splat opertator (`**`).
|
427
|
+
|
428
|
+
```ruby
|
429
|
+
response = client.messaging.send(**message)
|
430
|
+
```
|
431
|
+
|
432
|
+
A few additional examples of using these convenience methods are shown below:
|
433
|
+
|
434
|
+
|
435
|
+
```ruby
|
436
|
+
# creating an RCS Text message
|
437
|
+
message = client.messaging.rcs(to: "447700900000", from: "RCS-Agent", type: 'text', message: 'Hello world!')
|
349
438
|
|
350
439
|
# creating a WhatsApp Text message
|
351
|
-
message =
|
440
|
+
message = client.messaging.whatsapp(to: "447700900000", from: "447700900001", type: 'text', message: 'Hello world!')
|
352
441
|
|
353
442
|
# creating a WhatsApp Image message
|
354
|
-
message =
|
443
|
+
message = client.messaging.whatsapp(to: "447700900000", from: "447700900001", type: 'image', message: { url: 'https://example.com/image.jpg' })
|
355
444
|
|
356
445
|
# creating an MMS audio message with optional properties
|
357
|
-
message =
|
446
|
+
message = client.messaging.mms(
|
447
|
+
to: "447700900000",
|
448
|
+
from: "447700900001",
|
449
|
+
type: 'audio',
|
450
|
+
message: {
|
451
|
+
url: 'https://example.com/audio.mp3'
|
452
|
+
},
|
453
|
+
opts: {
|
454
|
+
client_ref: "abc123"
|
455
|
+
}
|
456
|
+
)
|
457
|
+
```
|
458
|
+
|
459
|
+
You can choose to omit the `to` and/or `from` arguments from the convenience method calls and instead pass them in as keyword arguments during the `send` method invocation.
|
460
|
+
|
461
|
+
```ruby
|
462
|
+
message = client.messaging.sms(from: "447700900001", message: "Hello world!")
|
463
|
+
|
464
|
+
['447700900001', '447700900002', '447700900003'].each do |to_number|
|
465
|
+
client.messaging.send(to: to_number, **message)
|
466
|
+
end
|
358
467
|
```
|
359
468
|
|
360
|
-
|
469
|
+
### Sending a Message with Failover
|
470
|
+
|
471
|
+
The Messages API lets you define one or more failover messages which will be sent if the initial message is rejected. In the Ruby SDK, this feature is implemented by passing a `failover` keyword argument during the invocation of the `send` method. The value of this argument must be an Array containing one or more Hash objects representing the failover message(s). For example:
|
361
472
|
|
362
473
|
```ruby
|
363
|
-
|
474
|
+
# Sending an RCS message with failover to SMS
|
475
|
+
rcs_message = messaging.rcs(
|
476
|
+
to: '447900000000',
|
477
|
+
from: 'RCS-Agent',
|
478
|
+
type: 'text',
|
479
|
+
message: 'This is an RCS message. If you see this, RCS is working!'
|
480
|
+
)
|
481
|
+
|
482
|
+
sms_message = messaging.sms(
|
483
|
+
to: '447900000000',
|
484
|
+
from: 'Vonage',
|
485
|
+
message: 'This is a failover SMS message in case RCS fails.'
|
486
|
+
)
|
487
|
+
|
488
|
+
response = messaging.send(**rcs_message, failover: [sms_message])
|
364
489
|
```
|
365
490
|
|
366
491
|
## Verify API v2
|
@@ -7,6 +7,8 @@ module Vonage
|
|
7
7
|
attr_reader :data
|
8
8
|
|
9
9
|
def initialize(attributes = {})
|
10
|
+
@to = attributes.fetch(:to, nil)
|
11
|
+
@from = attributes.fetch(:from, nil)
|
10
12
|
@type = attributes.fetch(:type, nil)
|
11
13
|
@message = attributes.fetch(:message, nil)
|
12
14
|
@opts = attributes.fetch(:opts, {})
|
@@ -7,6 +7,8 @@ module Vonage
|
|
7
7
|
attr_reader :data
|
8
8
|
|
9
9
|
def initialize(attributes = {})
|
10
|
+
@to = attributes.fetch(:to, nil)
|
11
|
+
@from = attributes.fetch(:from, nil)
|
10
12
|
@type = attributes.fetch(:type, nil)
|
11
13
|
@message = attributes.fetch(:message, nil)
|
12
14
|
@opts = attributes.fetch(:opts, {})
|
@@ -7,6 +7,8 @@ module Vonage
|
|
7
7
|
attr_reader :data
|
8
8
|
|
9
9
|
def initialize(attributes = {})
|
10
|
+
@to = attributes.fetch(:to, nil)
|
11
|
+
@from = attributes.fetch(:from, nil)
|
10
12
|
@type = attributes.fetch(:type, nil)
|
11
13
|
@message = attributes.fetch(:message, nil)
|
12
14
|
@opts = attributes.fetch(:opts, {})
|
@@ -5,6 +5,8 @@ module Vonage
|
|
5
5
|
attr_reader :data
|
6
6
|
|
7
7
|
def initialize(attributes = {})
|
8
|
+
@to = attributes.fetch(:to, nil)
|
9
|
+
@from = attributes.fetch(:from, nil)
|
8
10
|
@type = attributes.fetch(:type, 'text')
|
9
11
|
@message = attributes.fetch(:message, nil)
|
10
12
|
@opts = attributes.fetch(:opts, {})
|
@@ -7,6 +7,8 @@ module Vonage
|
|
7
7
|
attr_reader :data
|
8
8
|
|
9
9
|
def initialize(attributes = {})
|
10
|
+
@to = attributes.fetch(:to, nil)
|
11
|
+
@from = attributes.fetch(:from, nil)
|
10
12
|
@type = attributes.fetch(:type, nil)
|
11
13
|
@message = attributes.fetch(:message, nil)
|
12
14
|
@opts = attributes.fetch(:opts, {})
|
@@ -18,7 +20,7 @@ module Vonage
|
|
18
20
|
private
|
19
21
|
|
20
22
|
def build
|
21
|
-
data[:channel] = '
|
23
|
+
data[:channel] = 'viber_service'
|
22
24
|
super
|
23
25
|
end
|
24
26
|
|
@@ -7,6 +7,8 @@ module Vonage
|
|
7
7
|
attr_reader :data
|
8
8
|
|
9
9
|
def initialize(attributes = {})
|
10
|
+
@to = attributes.fetch(:to, nil)
|
11
|
+
@from = attributes.fetch(:from, nil)
|
10
12
|
@type = attributes.fetch(:type, nil)
|
11
13
|
@message = attributes.fetch(:message, nil)
|
12
14
|
@opts = attributes.fetch(:opts, {})
|
@@ -25,7 +25,7 @@ module Vonage
|
|
25
25
|
|
26
26
|
private
|
27
27
|
|
28
|
-
attr_accessor :type, :message, :opts
|
28
|
+
attr_accessor :to, :from, :type, :message, :opts
|
29
29
|
attr_writer :data
|
30
30
|
|
31
31
|
def after_initialize!
|
@@ -35,6 +35,8 @@ module Vonage
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def build
|
38
|
+
data[:to] = to if to
|
39
|
+
data[:from] = from if from
|
38
40
|
data[:message_type] = type
|
39
41
|
data[type.to_sym] = message
|
40
42
|
data.merge!(opts)
|
data/lib/vonage/messaging.rb
CHANGED
@@ -27,8 +27,17 @@ module Vonage
|
|
27
27
|
#
|
28
28
|
# @see https://developer.vonage.com/api/messages#SendMessage
|
29
29
|
#
|
30
|
-
def send(to:, from:, **message)
|
31
|
-
|
30
|
+
def send(to:, from:, channel:, message_type:, failover: nil, **message)
|
31
|
+
params = { to: to, from: from, channel: channel, message_type: message_type }.merge(message)
|
32
|
+
|
33
|
+
if failover
|
34
|
+
raise ArgumentError.new("`failover` must be an array") unless failover.is_a?(Array)
|
35
|
+
raise ArgumentError.new("`failover` must not be empty") if failover.empty?
|
36
|
+
raise ArgumentError.new("`failover` must contain only Hashes") unless failover.all?(Hash)
|
37
|
+
params[:failover] = failover
|
38
|
+
end
|
39
|
+
|
40
|
+
request('/v1/messages', params: params, type: Post)
|
32
41
|
end
|
33
42
|
|
34
43
|
# Update a Message Object.
|
data/lib/vonage/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vonage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.
|
4
|
+
version: 7.30.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vonage
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: vonage-jwt
|
@@ -295,7 +295,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
295
295
|
- !ruby/object:Gem::Version
|
296
296
|
version: '0'
|
297
297
|
requirements: []
|
298
|
-
rubygems_version: 3.6.
|
298
|
+
rubygems_version: 3.6.7
|
299
299
|
specification_version: 4
|
300
300
|
summary: This is the Ruby Server SDK for Vonage APIs. To use it you'll need a Vonage
|
301
301
|
account. Sign up for free at https://www.vonage.com
|