vonage 7.30.0 → 8.0.0.beta
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 +92 -604
- data/lib/vonage/applications.rb +4 -12
- data/lib/vonage/basic.rb +1 -1
- data/lib/vonage/bearer_token.rb +1 -1
- data/lib/vonage/client.rb +0 -65
- data/lib/vonage/client_error.rb +1 -1
- data/lib/vonage/config.rb +1 -9
- data/lib/vonage/conversations/events.rb +0 -12
- data/lib/vonage/conversations/legs.rb +0 -6
- data/lib/vonage/conversations/members.rb +0 -15
- data/lib/vonage/conversations/users.rb +0 -15
- data/lib/vonage/conversations.rb +0 -30
- data/lib/vonage/errors.rb +20 -37
- data/lib/vonage/gsm7.rb +1 -1
- data/lib/vonage/http.rb +3 -3
- data/lib/vonage/jwt.rb +0 -17
- data/lib/vonage/key_secret_params.rb +2 -3
- data/lib/vonage/keys.rb +1 -14
- data/lib/vonage/logger.rb +3 -5
- data/lib/vonage/messaging/channels/messenger.rb +0 -2
- data/lib/vonage/messaging/channels/mms.rb +0 -2
- data/lib/vonage/messaging/channels/sms.rb +0 -2
- data/lib/vonage/messaging/channels/viber.rb +2 -11
- data/lib/vonage/messaging/channels/whats_app.rb +1 -5
- data/lib/vonage/messaging/message.rb +1 -4
- data/lib/vonage/messaging.rb +3 -42
- data/lib/vonage/namespace.rb +68 -137
- data/lib/vonage/numbers.rb +17 -40
- data/lib/vonage/server_error.rb +1 -1
- data/lib/vonage/signature.rb +5 -5
- data/lib/vonage/sms.rb +20 -20
- data/lib/vonage/version.rb +1 -1
- data/lib/vonage/video/archives.rb +58 -25
- data/lib/vonage/video/list_response.rb +11 -0
- data/lib/vonage/video/moderation.rb +22 -7
- data/lib/vonage/video/signals.rb +9 -4
- data/lib/vonage/video/streams.rb +12 -6
- data/lib/vonage/video.rb +13 -50
- data/lib/vonage/voice/actions/connect.rb +5 -34
- data/lib/vonage/voice/actions/conversation.rb +4 -10
- data/lib/vonage/voice/actions/input.rb +3 -19
- data/lib/vonage/voice/actions/notify.rb +3 -8
- data/lib/vonage/voice/actions/pay.rb +107 -0
- data/lib/vonage/voice/actions/record.rb +4 -52
- data/lib/vonage/voice/actions/stream.rb +4 -48
- data/lib/vonage/voice/actions/talk.rb +4 -54
- data/lib/vonage/voice/talk.rb +1 -11
- data/lib/vonage/voice.rb +0 -24
- data/lib/vonage.rb +0 -4
- data/vonage.gemspec +1 -3
- metadata +12 -108
- data/lib/vonage/api_error.rb +0 -33
- data/lib/vonage/conversation/event/list_response.rb +0 -11
- data/lib/vonage/conversation/event.rb +0 -108
- data/lib/vonage/conversation/list_response.rb +0 -11
- data/lib/vonage/conversation/member/list_response.rb +0 -11
- data/lib/vonage/conversation/member.rb +0 -134
- data/lib/vonage/conversation/user/conversations_list_response.rb +0 -11
- data/lib/vonage/conversation/user/sessions_list_response.rb +0 -11
- data/lib/vonage/conversation/user.rb +0 -67
- data/lib/vonage/conversation.rb +0 -164
- data/lib/vonage/meetings/applications.rb +0 -28
- data/lib/vonage/meetings/dial_in_numbers/list_response.rb +0 -11
- data/lib/vonage/meetings/dial_in_numbers.rb +0 -26
- data/lib/vonage/meetings/recordings.rb +0 -42
- data/lib/vonage/meetings/rooms/list_response.rb +0 -11
- data/lib/vonage/meetings/rooms.rb +0 -167
- data/lib/vonage/meetings/sessions/list_response.rb +0 -11
- data/lib/vonage/meetings/sessions.rb +0 -31
- data/lib/vonage/meetings/themes/list_response.rb +0 -11
- data/lib/vonage/meetings/themes.rb +0 -239
- data/lib/vonage/meetings.rb +0 -50
- data/lib/vonage/messaging/channels/rcs.rb +0 -44
- data/lib/vonage/network_authentication/client_authentication.rb +0 -39
- data/lib/vonage/network_authentication/server_authentication.rb +0 -47
- data/lib/vonage/network_authentication.rb +0 -22
- data/lib/vonage/network_number_verification.rb +0 -92
- data/lib/vonage/network_sim_swap.rb +0 -84
- data/lib/vonage/number_insight_2.rb +0 -36
- data/lib/vonage/proactive_connect/events/list_response.rb +0 -11
- data/lib/vonage/proactive_connect/events.rb +0 -71
- data/lib/vonage/proactive_connect/item.rb +0 -116
- data/lib/vonage/proactive_connect/items/file_response.rb +0 -32
- data/lib/vonage/proactive_connect/items/list_response.rb +0 -11
- data/lib/vonage/proactive_connect/items.rb +0 -116
- data/lib/vonage/proactive_connect/list.rb +0 -186
- data/lib/vonage/proactive_connect/lists/list_response.rb +0 -11
- data/lib/vonage/proactive_connect/lists.rb +0 -38
- data/lib/vonage/proactive_connect.rb +0 -43
- data/lib/vonage/subaccounts/balance_transfers/list_response.rb +0 -11
- data/lib/vonage/subaccounts/credit_transfers/list_response.rb +0 -11
- data/lib/vonage/subaccounts/list_response.rb +0 -15
- data/lib/vonage/subaccounts.rb +0 -203
- data/lib/vonage/users/list_response.rb +0 -11
- data/lib/vonage/users.rb +0 -156
- data/lib/vonage/verify2/channels/email.rb +0 -36
- data/lib/vonage/verify2/channels/silent_auth.rb +0 -45
- data/lib/vonage/verify2/channels/sms.rb +0 -63
- data/lib/vonage/verify2/channels/voice.rb +0 -32
- data/lib/vonage/verify2/channels/whats_app.rb +0 -39
- data/lib/vonage/verify2/channels/whats_app_interactive.rb +0 -32
- data/lib/vonage/verify2/start_verification_options.rb +0 -63
- data/lib/vonage/verify2/template_fragments/list_response.rb +0 -11
- data/lib/vonage/verify2/template_fragments.rb +0 -125
- data/lib/vonage/verify2/templates/list_response.rb +0 -11
- data/lib/vonage/verify2/templates.rb +0 -86
- data/lib/vonage/verify2/workflow.rb +0 -39
- data/lib/vonage/verify2/workflow_builder.rb +0 -25
- data/lib/vonage/verify2.rb +0 -112
- data/lib/vonage/video/archives/list_response.rb +0 -11
- data/lib/vonage/video/broadcasts/list_response.rb +0 -11
- data/lib/vonage/video/broadcasts.rb +0 -75
- data/lib/vonage/video/captions.rb +0 -67
- data/lib/vonage/video/renders/list_response.rb +0 -11
- data/lib/vonage/video/renders.rb +0 -107
- data/lib/vonage/video/sip.rb +0 -48
- data/lib/vonage/video/streams/list_response.rb +0 -11
- data/lib/vonage/video/web_socket.rb +0 -61
data/README.md
CHANGED
@@ -12,21 +12,15 @@ need a Vonage account. Sign up [for free at vonage.com][signup].
|
|
12
12
|
* [Installation](#installation)
|
13
13
|
* [Usage](#usage)
|
14
14
|
* [Logging](#logging)
|
15
|
-
* [Exceptions](#exceptions)
|
16
15
|
* [Overriding the default hosts](#overriding-the-default-hosts)
|
17
|
-
* [HTTP Client Configuration](#http-client-configuration)
|
18
16
|
* [JWT authentication](#jwt-authentication)
|
19
17
|
* [Webhook signatures](#webhook-signatures)
|
20
18
|
* [Pagination](#pagination)
|
21
|
-
* [
|
22
|
-
* [Verify API v2](#verify-api-v2)
|
23
|
-
* [Voice API](#voice-api)
|
24
|
-
* [NCCO Builder](#ncco-builder)
|
19
|
+
* [NCCO Builder](#ncco-builder)
|
25
20
|
* [Documentation](#documentation)
|
26
|
-
* [
|
27
|
-
* [
|
21
|
+
* [Frequently Asked Questions](#frequently-asked-questions)
|
22
|
+
* [Supported APIs](#supported-apis)
|
28
23
|
* [License](#license)
|
29
|
-
* [Contribute](#contribute)
|
30
24
|
|
31
25
|
|
32
26
|
## Requirements
|
@@ -69,47 +63,8 @@ For production you can specify the `VONAGE_API_KEY` and `VONAGE_API_SECRET`
|
|
69
63
|
environment variables instead of specifying the key and secret explicitly,
|
70
64
|
keeping your credentials out of source control.
|
71
65
|
|
72
|
-
For APIs which use a JWT for authentication you'll need to pass `application_id` and `private_key` arguments to the
|
73
|
-
`Client` constructor as well as or instead of `api_key` and `api_secret`. See [JWT Authentication](#jwt-authentication).
|
74
66
|
|
75
|
-
|
76
|
-
|
77
|
-
### JWT authentication
|
78
|
-
|
79
|
-
To call newer endpoints that support JWT authentication such as the Voice API and Messages API you'll
|
80
|
-
also need to specify the `application_id` and `private_key` options. For example:
|
81
|
-
|
82
|
-
```ruby
|
83
|
-
client = Vonage::Client.new(application_id: application_id, private_key: private_key)
|
84
|
-
```
|
85
|
-
|
86
|
-
Both arguments should have string values corresponding to the `id` and `private_key`
|
87
|
-
values returned in a ["create an application"](https://developer.vonage.com/api/application.v2#createApplication)
|
88
|
-
response. These credentials can be stored in a datastore, in environment variables,
|
89
|
-
on disk outside of source control, or in some kind of key management infrastructure.
|
90
|
-
|
91
|
-
By default the library generates a short lived JWT per request. To generate a long lived
|
92
|
-
JWT for multiple requests or to specify JWT claims directly use `Vonage::JWT.generate` and
|
93
|
-
the token option. For example:
|
94
|
-
|
95
|
-
```ruby
|
96
|
-
claims = {
|
97
|
-
application_id: application_id,
|
98
|
-
private_key: 'path/to/private.key',
|
99
|
-
nbf: 1483315200,
|
100
|
-
ttl: 800
|
101
|
-
}
|
102
|
-
|
103
|
-
token = Vonage::JWT.generate(claims)
|
104
|
-
|
105
|
-
client = Vonage::Client.new(token: token)
|
106
|
-
```
|
107
|
-
|
108
|
-
Documentation for the Vonage Ruby JWT generator gem can be found at: https://www.rubydoc.info/gems/vonage-jwt
|
109
|
-
|
110
|
-
The documentation outlines all the possible parameters you can use to customize and build a token with.
|
111
|
-
|
112
|
-
### Logging
|
67
|
+
## Logging
|
113
68
|
|
114
69
|
Use the logger option to specify a logger. For example:
|
115
70
|
|
@@ -125,48 +80,8 @@ By default the library sets the logger to `Rails.logger` if it is defined.
|
|
125
80
|
|
126
81
|
To disable logging set the logger to `nil`.
|
127
82
|
|
128
|
-
### Exceptions
|
129
|
-
|
130
|
-
Where exceptions result from an error response from the Vonage API (HTTP responses that aren't ion the range `2xx` or `3xx`), the `Net::HTTPResponse` object will be available as a property of the `Exception` object via a `http_response` getter method (where there is no `Net::HTTPResponse` object associated with the exception, the value of `http_response` will be `nil`).
|
131
|
-
|
132
|
-
You can rescue the the exception to access the `http_response`, as well as use other getters provided for specific parts of the response. For example:
|
133
|
-
|
134
|
-
```ruby
|
135
|
-
begin
|
136
|
-
verification_request = client.verify2.start_verification(
|
137
|
-
brand: 'Acme',
|
138
|
-
workflow: [{channel: 'sms', to: '44700000000'}]
|
139
|
-
)
|
140
|
-
rescue Vonage::APIError => error
|
141
|
-
if error.http_response
|
142
|
-
error.http_response # => #<Net::HTTPUnauthorized 401 Unauthorized readbody=true>
|
143
|
-
error.http_response_code # => "401"
|
144
|
-
error.http_response_headers # => {"date"=>["Sun, 24 Sep 2023 11:08:47 GMT"], ...rest of headers}
|
145
|
-
error.http_response_body # => {"title"=>"Unauthorized", ...rest of body}
|
146
|
-
end
|
147
|
-
end
|
148
|
-
```
|
149
83
|
|
150
|
-
|
151
|
-
|
152
|
-
```ruby
|
153
|
-
begin
|
154
|
-
sms = client.sms.send(
|
155
|
-
from: 'Vonage',
|
156
|
-
to: '44700000000',
|
157
|
-
text: 'Hello World!'
|
158
|
-
)
|
159
|
-
rescue Vonage::Error => error
|
160
|
-
if error.is_a? Vonage::ServiceError
|
161
|
-
error.response # => #<Vonage::Response:0x0000555b2e49d4f8>
|
162
|
-
error.response.messages.first.status # => "4"
|
163
|
-
error.response.messages.first.error_text # => "Bad Credentials"
|
164
|
-
error.response.http_response # => #<Net::HTTPOK 200 OK readbody=true>
|
165
|
-
end
|
166
|
-
end
|
167
|
-
```
|
168
|
-
|
169
|
-
### Overriding the default hosts
|
84
|
+
## Overriding the default hosts
|
170
85
|
|
171
86
|
To override the default hosts that the SDK uses for HTTP requests, you need to
|
172
87
|
specify the `api_host`, `rest_host` or both in the client configuration. For example:
|
@@ -180,155 +95,72 @@ client = Vonage::Client.new(
|
|
180
95
|
|
181
96
|
By default the hosts are set to `api.nexmo.com` and `rest.nexmo.com`, respectively.
|
182
97
|
|
183
|
-
### HTTP Client Configuration
|
184
|
-
|
185
|
-
It is possible to set configuration options on the HTTP client. This can be don in a couple of ways.
|
186
|
-
|
187
|
-
1. Using an `:http` key during `Vonage::Client` instantiation, for example:
|
188
|
-
```ruby
|
189
|
-
client = Vonage::Client.new(
|
190
|
-
api_key: 'YOUR-API-KEY',
|
191
|
-
api_secret: 'YOUR-API-SECRET',
|
192
|
-
http: {
|
193
|
-
max_retries: 1
|
194
|
-
}
|
195
|
-
)
|
196
|
-
```
|
197
|
-
|
198
|
-
2. By using the `http=` setter on the `Vonage::Config` object, for example:
|
199
|
-
```ruby
|
200
|
-
client = Vonage::Client.new(
|
201
|
-
api_key: 'YOUR-API-KEY',
|
202
|
-
api_secret: 'YOUR-API-SECRET'
|
203
|
-
)
|
204
|
-
|
205
|
-
client.config.http = { max_retries: 1 }
|
206
|
-
```
|
207
|
-
|
208
|
-
The Vonage Ruby SDK uses the [`Net::HTTP::Persistent` library](https://github.com/drbrain/net-http-persistent) as an HTTP client. For available configuration options see [the documentation for that library](https://www.rubydoc.info/gems/net-http-persistent/3.0.0/Net/HTTP/Persistent).
|
209
|
-
|
210
|
-
### Webhook signatures
|
211
|
-
|
212
|
-
Certain Vonage APIs provide signed [webhooks](https://developer.vonage.com/en/getting-started/concepts/webhooks) as a means of verifying the origin of the webhooks. The exact signing mechanism varies depending on the API.
|
213
|
-
|
214
|
-
#### Signature in Request Body
|
215
|
-
|
216
|
-
The [SMS API](https://developer.vonage.com/en/messaging/sms/overview) signs the webhook request using a hash digest. This is assigned to a `sig` parameter in the request body.
|
217
|
-
|
218
|
-
You can verify the webhook request using the `Vonage::SMS#verify_webhook_sig` method. As well as the **request params** from the received webhook, the method also needs access to the signature secret associated with the Vonage account (available from the [Vonage Dashboard](https://dashboard.nexmo.com/settings)), and the signature method used for signing (e.g. `sha512`), again this is based on thes setting in the Dashboard.
|
219
|
-
|
220
|
-
There are a few different ways of providing these values to the method:
|
221
|
-
|
222
|
-
1. Pass all values to the method invocation.
|
223
|
-
|
224
|
-
```ruby
|
225
|
-
client = Vonage::Client.new
|
226
|
-
|
227
|
-
client.sms.verify_webhook_sig(
|
228
|
-
webhook_params: params,
|
229
|
-
signature_secret: 'secret',
|
230
|
-
signature_method: 'sha512'
|
231
|
-
) # => returns true if the signature is valid, false otherwise
|
232
|
-
```
|
233
|
-
|
234
|
-
2. Set `signature_secret` and `signature_method` at `Client` instantiation.
|
235
|
-
|
236
|
-
```ruby
|
237
|
-
client = Vonage::Client.new(
|
238
|
-
signature_secret: 'secret',
|
239
|
-
signature_method: 'sha512'
|
240
|
-
)
|
241
|
-
|
242
|
-
client.sms.verify_webhook_sig(webhook_params: params) # => returns true if the signature is valid, false otherwise
|
243
|
-
```
|
244
|
-
|
245
|
-
3. Set `signature_secret` and `signature_method` on the `Config` object.
|
246
|
-
|
247
|
-
```ruby
|
248
|
-
client = Vonage::Client.new
|
249
|
-
client.config.signature_secret = 'secret'
|
250
|
-
client.config.signature_method = 'sha512'
|
251
|
-
|
252
|
-
client.sms.verify_webhook_sig(webhook_params: params) # => returns true if the signature is valid, false otherwise
|
253
|
-
```
|
254
|
-
|
255
|
-
4. Set `signature_secret` and `signature_method` as environment variables named `VONAGE_SIGNATURE_SECRET` and `VONAGE_SIGNATURE_METHOD`
|
256
|
-
|
257
|
-
```ruby
|
258
|
-
client = Vonage::Client.new
|
259
|
-
|
260
|
-
client.sms.verify_webhook_sig(webhook_params: params) # => returns true if the signature is valid, false otherwise
|
261
|
-
```
|
262
|
-
|
263
|
-
**Note:** Webhook signing for the SMS API is not switched on by default. You'll need to contact support@vonage.com to enable message signing on your account.
|
264
|
-
|
265
|
-
#### Signed JWT in Header
|
266
98
|
|
267
|
-
|
99
|
+
## JWT authentication
|
268
100
|
|
269
|
-
|
270
|
-
|
271
|
-
To verify the JWT, you'll first need to extract it from the `Authorization` header. The header value will look something like the following:
|
101
|
+
To call newer endpoints that support JWT authentication such as the Voice API and Messages API you'll
|
102
|
+
also need to specify the `application_id` and `private_key` options. For example:
|
272
103
|
|
273
104
|
```ruby
|
274
|
-
|
105
|
+
client = Vonage::Client.new(application_id: application_id, private_key: private_key)
|
275
106
|
```
|
276
107
|
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
The method also needs access to the the method also needs access to the signature secret associated with the Vonage account (available from the [Vonage Dashboard](https://dashboard.nexmo.com/settings)). There are a few different ways of providing this value to the method:
|
108
|
+
Both arguments should have string values corresponding to the `id` and `private_key`
|
109
|
+
values returned in a ["create an application"](https://developer.nexmo.com/api/application.v2#createApplication)
|
110
|
+
response. These credentials can be stored in a datastore, in environment variables,
|
111
|
+
on disk outside of source control, or in some kind of key management infrastructure.
|
282
112
|
|
283
|
-
|
113
|
+
By default the library generates a short lived JWT per request. To generate a long lived
|
114
|
+
JWT for multiple requests or to specify JWT claims directly use `Vonage::JWT.generate` and
|
115
|
+
the token option. For example:
|
284
116
|
|
285
117
|
```ruby
|
286
|
-
|
118
|
+
claims = {
|
119
|
+
application_id: application_id,
|
120
|
+
private_key: 'path/to/private.key',
|
121
|
+
nbf: 1483315200,
|
122
|
+
ttl: 800
|
123
|
+
}
|
287
124
|
|
288
|
-
|
289
|
-
token: extracted_token,
|
290
|
-
signature_secret: 'secret'
|
291
|
-
) # => returns true if the token is valid, false otherwise
|
292
|
-
```
|
125
|
+
token = Vonage::JWT.generate(claims)
|
293
126
|
|
294
|
-
|
127
|
+
client = Vonage::Client.new(token: token)
|
128
|
+
````
|
295
129
|
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
)
|
130
|
+
Documentation for the Vonage Ruby JWT generator gem can be found at
|
131
|
+
[https://www.rubydoc.info/github/nexmo/nexmo-jwt-ruby](https://www.rubydoc.info/github/nexmo/nexmo-jwt-ruby).
|
132
|
+
The documentation outlines all the possible parameters you can use to customize and build a token with.
|
300
133
|
|
301
|
-
|
302
|
-
```
|
134
|
+
## Webhook signatures
|
303
135
|
|
304
|
-
|
136
|
+
To check webhook signatures you'll also need to specify the `signature_secret` option. For example:
|
305
137
|
|
306
138
|
```ruby
|
307
139
|
client = Vonage::Client.new
|
308
140
|
client.config.signature_secret = 'secret'
|
309
141
|
client.config.signature_method = 'sha512'
|
310
142
|
|
311
|
-
client.
|
143
|
+
if client.signature.check(request.GET)
|
144
|
+
# valid signature
|
145
|
+
else
|
146
|
+
# invalid signature
|
147
|
+
end
|
312
148
|
```
|
313
149
|
|
314
|
-
|
150
|
+
Alternatively you can set the `VONAGE_SIGNATURE_SECRET` environment variable.
|
315
151
|
|
316
|
-
|
317
|
-
client = Vonage::Client.new
|
318
|
-
|
319
|
-
client.voice.verify_webhook_token(token: extracted_token) # => returns true if the token is valid, false otherwise
|
320
|
-
```
|
152
|
+
Note: you'll need to contact support@nexmo.com to enable message signing on your account.
|
321
153
|
|
322
|
-
|
154
|
+
## Pagination
|
323
155
|
|
324
156
|
Vonage APIs paginate list requests. This means that if a collection is requested that is larger than the API default, the API will return the first page of items in the collection. The Ruby SDK provides an `auto_advance` parameter that will traverse through the pages and return all the results in one response object.
|
325
157
|
|
326
158
|
The `auto_advance` parameter is set to a default of `true` for the following APIs:
|
327
159
|
|
328
|
-
* [Account API](https://developer.
|
329
|
-
* [Application API](https://developer.
|
330
|
-
* [Conversation API](https://developer.
|
331
|
-
* [Voice API](https://developer.
|
160
|
+
* [Account API](https://developer.nexmo.com/api/developer/account)
|
161
|
+
* [Application API](https://developer.nexmo.com/api/application.v2)
|
162
|
+
* [Conversation API](https://developer.nexmo.com/api/conversation)
|
163
|
+
* [Voice API](https://developer.nexmo.com/api/voice)
|
332
164
|
|
333
165
|
To modify the `auto_advance` behavior you can specify it in your method:
|
334
166
|
|
@@ -336,366 +168,7 @@ To modify the `auto_advance` behavior you can specify it in your method:
|
|
336
168
|
client.applications.list(auto_advance: false)
|
337
169
|
```
|
338
170
|
|
339
|
-
|
340
|
-
## Messages API
|
341
|
-
|
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
|
-
|
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:
|
373
|
-
|
374
|
-
```ruby
|
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!')
|
438
|
-
|
439
|
-
# creating a WhatsApp Text message
|
440
|
-
message = client.messaging.whatsapp(to: "447700900000", from: "447700900001", type: 'text', message: 'Hello world!')
|
441
|
-
|
442
|
-
# creating a WhatsApp Image message
|
443
|
-
message = client.messaging.whatsapp(to: "447700900000", from: "447700900001", type: 'image', message: { url: 'https://example.com/image.jpg' })
|
444
|
-
|
445
|
-
# creating an MMS audio message with optional properties
|
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
|
467
|
-
```
|
468
|
-
|
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:
|
472
|
-
|
473
|
-
```ruby
|
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])
|
489
|
-
```
|
490
|
-
|
491
|
-
## Verify API v2
|
492
|
-
|
493
|
-
The [Vonage Verify API v2](https://developer.vonage.com/en/verify/verify-v2/overview) allows you to manage 2FA verification workflows over a number of different channels such as SMS, WhatsApp, WhatsApp Interactive, Voice, Email, and Silent Authentication, either individually or in combination with each other. See the Vonage Developer Documentation for a [complete API reference](https://developer.vonage.com/en/api/verify.v2) listing all the channels, verification options, and callback types.
|
494
|
-
|
495
|
-
The Ruby SDK provides two methods for interacting with the Verify v2 API:
|
496
|
-
|
497
|
-
- `Verify2#start_verification`: starts a new verification request. Here you can specify options for the request and the workflow to be used.
|
498
|
-
- `Verify2#check_code`: for channels where the end-user is sent a one-time code, this method is used to verify the code against the `request_id` of the verification request created by the `start_verification` method.
|
499
|
-
|
500
|
-
### Creating a Verify2 Object
|
501
|
-
|
502
|
-
```ruby
|
503
|
-
verify = client.verify2
|
504
|
-
```
|
505
|
-
|
506
|
-
### Making a verification request
|
507
|
-
|
508
|
-
For simple requests, you may prefer to manually set the value for `workflow` (an array of one or more hashes containing the settings for a particular channel) and any optional params.
|
509
|
-
|
510
|
-
Example with the required `:brand` and `:workflow` arguments:
|
511
|
-
|
512
|
-
```ruby
|
513
|
-
verification_request = verify.start_verification(
|
514
|
-
brand: 'Acme',
|
515
|
-
workflow: [{channel: 'sms', to: '447000000000'}]
|
516
|
-
)
|
517
|
-
```
|
518
|
-
|
519
|
-
Example with the required `:brand` and `:workflow` arguments, and an optional `code_length`:
|
520
|
-
|
521
|
-
```ruby
|
522
|
-
verification_request = verify.start_verification(
|
523
|
-
brand: 'Acme',
|
524
|
-
workflow: [{channel: 'sms', to: '447000000000'}],
|
525
|
-
code_length: 6
|
526
|
-
)
|
527
|
-
```
|
528
|
-
|
529
|
-
For more complex requests (e.g. with mutliple workflow channels or addtional options), or to take advantage of built-in input validation, you can use the `StartVerificationOptions` object and the `Workflow` and various channel objects or the `WorkflowBuilder`:
|
530
|
-
|
531
|
-
#### Create options using StartVerificationOptions object
|
532
|
-
|
533
|
-
```ruby
|
534
|
-
opts = verify.start_verification_options(
|
535
|
-
locale: 'fr-fr',
|
536
|
-
code_length: 6,
|
537
|
-
client_ref: 'abc-123'
|
538
|
-
).to_h
|
539
|
-
|
540
|
-
verification_request = verify.start_verification(
|
541
|
-
brand: 'Acme',
|
542
|
-
workflow: [{channel: 'email', to: 'alice.example.com'}],
|
543
|
-
**opts
|
544
|
-
)
|
545
|
-
```
|
546
|
-
|
547
|
-
#### Create workflow using Workflow and Channel objects
|
548
|
-
|
549
|
-
```ruby
|
550
|
-
# Instantiate a Workflow object
|
551
|
-
workflow = verify.workflow
|
552
|
-
|
553
|
-
# Add channels to the workflow
|
554
|
-
workflow << workflow.sms(to: '447000000000')
|
555
|
-
workflow << workflow.email(to: 'alice.example.com')
|
556
|
-
|
557
|
-
# Channel data is encpsulated in channel objects stored in the Workflow list array
|
558
|
-
workflow.list
|
559
|
-
# => [ #<Vonage::Verify2::Channels::SMS:0x0000561474a74778 @channel="sms", @to="447000000000">,
|
560
|
-
#<Vonage::Verify2::Channels::Email:0x0000561474c51a28 @channel="email", @to="alice.example.com">]
|
561
|
-
|
562
|
-
# To use the list as the value for `:workflow` in a `start_verification` request call,
|
563
|
-
# the objects must be hashified
|
564
|
-
workflow_list = workflow.hashified_list
|
565
|
-
# => [{:channel=>"sms", :to=>"447000000000"}, {:channel=>"email", :to=>"alice.example.com"}]
|
566
|
-
|
567
|
-
verification_request = verify.start_verification(brand: 'Acme', workflow: workflow_list)
|
568
|
-
```
|
569
|
-
|
570
|
-
#### Create a workflow using the WorkflowBuilder
|
571
|
-
|
572
|
-
```ruby
|
573
|
-
workflow = verify.workflow_builder.build do |builder|
|
574
|
-
builder.add_voice(to: '447000000001')
|
575
|
-
builder.add_whatsapp(to: '447000000000')
|
576
|
-
end
|
577
|
-
|
578
|
-
workflow_list = workflow.hashified_list
|
579
|
-
# => [{:channel=>"voice", :to=>"447000000001"}, {:channel=>"whatsapp", :to=>"447000000000"}]
|
580
|
-
|
581
|
-
verification_request = verify.start_verification(brand: 'Acme', workflow: workflow_list)
|
582
|
-
```
|
583
|
-
|
584
|
-
### Cancelling a request
|
585
|
-
|
586
|
-
You can cancel in in-progress verification request
|
587
|
-
|
588
|
-
```ruby
|
589
|
-
# Get the `request_id` from the Vonage#Response object returned by the `start_verification` method call
|
590
|
-
request_id = verification_request.request_id
|
591
|
-
|
592
|
-
verify.cancel_verification_request(request_id: request_id)
|
593
|
-
```
|
594
|
-
|
595
|
-
### Checking a code
|
596
|
-
|
597
|
-
```ruby
|
598
|
-
# Get the `request_id` from the Vonage#Response object returned by the `start_verification` method call
|
599
|
-
request_id = verification_request.request_id
|
600
|
-
|
601
|
-
# Get the one-time code via user input
|
602
|
-
# e.g. from params in a route handler or controller action for a form input
|
603
|
-
code = params[:code]
|
604
|
-
|
605
|
-
begin
|
606
|
-
code_check = verify.check_code(request_id: request_id, code: code)
|
607
|
-
rescue => error
|
608
|
-
# an invalid code will raise an exception of type Vonage::ClientError
|
609
|
-
end
|
610
|
-
|
611
|
-
if code_check.http_response.code == '200'
|
612
|
-
# code is valid
|
613
|
-
end
|
614
|
-
```
|
615
|
-
|
616
|
-
### Working with Verify Custom Templates and Template Fragments
|
617
|
-
|
618
|
-
Verify custom templates allow you to customize the message sent to deliver an OTP to your users, rather than using the default Vonage templates. See the [Template Management Guide document](https://developer.vonage.com/en/verify/guides/custom-templates) for more information.
|
619
|
-
|
620
|
-
#### Templates
|
621
|
-
|
622
|
-
```ruby
|
623
|
-
# Get a list of all templates
|
624
|
-
template_list = verify.templates.list
|
625
|
-
|
626
|
-
# Get details of a specific template
|
627
|
-
template = verify.templates.info(template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9')
|
628
|
-
|
629
|
-
# Create a new template
|
630
|
-
verify.templates.create(name: 'my-template')
|
631
|
-
|
632
|
-
# Update an existing template
|
633
|
-
verify.templates.update(
|
634
|
-
template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9',
|
635
|
-
name: 'my-updated-template'
|
636
|
-
)
|
637
|
-
|
638
|
-
# Delete a template
|
639
|
-
verify.templates.delete(template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9')
|
640
|
-
```
|
641
|
-
|
642
|
-
#### Template Fragments
|
643
|
-
|
644
|
-
```ruby
|
645
|
-
# Get a list of template fragments for a specific template
|
646
|
-
template_fragment_list = verify.template_fragments.list(template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9')
|
647
|
-
|
648
|
-
# Get details of a specific template fragment
|
649
|
-
template_fragment = verify.template_fragments.info(
|
650
|
-
template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9',
|
651
|
-
template_fragment_id: 'c70f446e-997a-4313-a081-60a02a31dc19'
|
652
|
-
)
|
653
|
-
|
654
|
-
# Create a new template fragement
|
655
|
-
verify.template_fragments.create(
|
656
|
-
template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9',
|
657
|
-
channel: 'sms',
|
658
|
-
locale: 'en-gb',
|
659
|
-
text: 'Your code is: ${code}'
|
660
|
-
)
|
661
|
-
|
662
|
-
# Update an existing template fragment
|
663
|
-
verify.template_fragments.update(
|
664
|
-
template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9',
|
665
|
-
template_fragment_id: 'c70f446e-997a-4313-a081-60a02a31dc1',
|
666
|
-
text: 'Your one-time code is: ${code}'
|
667
|
-
)
|
668
|
-
|
669
|
-
# Delete a template fragment
|
670
|
-
verify.template_fragments.delete(
|
671
|
-
template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9',
|
672
|
-
template_fragment_id: 'c70f446e-997a-4313-a081-60a02a31dc19'
|
673
|
-
)
|
674
|
-
```
|
675
|
-
|
676
|
-
## Voice API
|
677
|
-
|
678
|
-
The [Vonage Voice API](The [Vonage Verify API v2](https://developer.vonage.com/en/verify/verify-v2/overview) allows you to automate voice interactions by creating calls, streaming audio, playing text to speech, playing DTMF tones, and other actions. See the Vonage Developer Documentation for a [complete API reference](https://developer.vonage.com/en/api/voice) listing all the Voice API capabilities.
|
679
|
-
|
680
|
-
The Ruby SDK provides numerous methods for interacting with the Voice v2 API. Here's an example of using the `create` method to make an outbound text-to-speech call:
|
681
|
-
|
682
|
-
```ruby
|
683
|
-
response = client.voice.create(
|
684
|
-
to: [{
|
685
|
-
type: 'phone',
|
686
|
-
number: '447700900000'
|
687
|
-
}],
|
688
|
-
from: {
|
689
|
-
type: 'phone',
|
690
|
-
number: '447700900001'
|
691
|
-
},
|
692
|
-
answer_url: [
|
693
|
-
'https://raw.githubusercontent.com/nexmo-community/ncco-examples/gh-pages/text-to-speech.json'
|
694
|
-
]
|
695
|
-
)
|
696
|
-
```
|
697
|
-
|
698
|
-
### NCCO Builder
|
171
|
+
## NCCO Builder
|
699
172
|
|
700
173
|
The Vonage Voice API accepts instructions via JSON objects called NCCOs. Each NCCO can be made up multiple actions that are executed in the order they are written. The Vonage API Developer Portal contains an [NCCO Reference](https://developer.vonage.com/voice/voice-api/ncco-reference) with instructions and information on all the parameters possible.
|
701
174
|
|
@@ -721,40 +194,65 @@ response = client.voice.create({
|
|
721
194
|
})
|
722
195
|
```
|
723
196
|
|
724
|
-
##
|
197
|
+
## Messages API
|
725
198
|
|
726
|
-
Vonage
|
199
|
+
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/api/messages-olympus) listing all the channel and message type combinations.
|
727
200
|
|
728
|
-
|
201
|
+
The Ruby SDK allows you to construct message data for specific messaging channels. Other than SMS (which has only one type -- text), you need to pass the message `:type` as well as the `:message` itself as arguments to the appropriate messages method, along with any optional properties if needed.
|
729
202
|
|
730
|
-
|
203
|
+
```ruby
|
204
|
+
# creating an SMS message
|
205
|
+
message = Vonage::Messaging::Message.sms(message: 'Hello world!')
|
731
206
|
|
732
|
-
|
207
|
+
# creating a WhatsApp Text message
|
208
|
+
message = Vonage::Messaging::Message.whatsapp(type: 'text', message: 'Hello world!')
|
209
|
+
|
210
|
+
# creating a WhatsApp Image message
|
211
|
+
message = Vonage::Messaging::Message.whatsapp(type: 'image', message: { url: 'https://example.com/image.jpg' })
|
212
|
+
|
213
|
+
# creating an MMS audio message with optional properties
|
214
|
+
message = Vonage::Messaging::Message.mms(type: 'audio', message: { url: 'https://example.com/audio.mp3' }, opts: {client_ref: "abc123"})
|
215
|
+
```
|
216
|
+
|
217
|
+
Once the message data is created, you can then send the message.
|
733
218
|
|
734
|
-
|
219
|
+
```ruby
|
220
|
+
response = client.messaging.send(to: "447700900000", from: "447700900001", **message)
|
221
|
+
```
|
735
222
|
|
736
|
-
|
737
|
-
* [Application API](https://developer.vonage.com/en/application/overview)
|
738
|
-
* [Conversation API](https://developer.vonage.com/en/conversation/overview)
|
739
|
-
* [Meetings API](https://developer.vonage.com/en/meetings/overview)
|
740
|
-
* [Messages API](https://developer.vonage.com/en/messages/overview)
|
741
|
-
* [Network Number Verification API](https://developer.vonage.com/en/number-verification/overview)
|
742
|
-
* [Network SIM Swap API](https://developer.vonage.com/en/sim-swap/overview)
|
743
|
-
* [Number Insight API](https://developer.vonage.com/en/number-insight/overview)
|
744
|
-
* [Numbers API](https://developer.vonage.com/en/numbers/overview)
|
745
|
-
* [Proactive Connect API](https://developer.vonage.com/en/proactive-connect/overview) *
|
746
|
-
* [Redact API](https://developer.vonage.com/en/redact/overview)
|
747
|
-
* [SMS API](https://developer.vonage.com/en/messaging/sms/overview)
|
748
|
-
* [Subaccounts API](https://developer.vonage.com/en/account/subaccounts/overview)
|
749
|
-
* [Verify API](https://developer.vonage.com/en/verify/overview)
|
750
|
-
* [Voice API](https://developer.vonage.com/en/verify/overview)
|
223
|
+
## Documentation
|
751
224
|
|
752
|
-
|
225
|
+
Vonage Ruby documentation: https://www.rubydoc.info/github/Vonage/vonage-ruby-sdk
|
753
226
|
|
754
|
-
|
227
|
+
Vonage Ruby code examples: https://github.com/Nexmo/nexmo-ruby-code-snippets
|
755
228
|
|
756
|
-
|
229
|
+
Vonage APIs API reference: https://developer.nexmo.com/api
|
757
230
|
|
231
|
+
## Frequently Asked Questions
|
232
|
+
|
233
|
+
## Supported APIs
|
234
|
+
|
235
|
+
The following is a list of Vonage APIs and whether the Ruby SDK provides support for them:
|
236
|
+
|
237
|
+
| API | API Release Status | Supported?
|
238
|
+
|----------|:---------:|:-------------:|
|
239
|
+
| Account API | General Availability |✅|
|
240
|
+
| Alerts API | General Availability |✅|
|
241
|
+
| Application API | General Availability |✅|
|
242
|
+
| Audit API | Beta |❌|
|
243
|
+
| Conversation API | Beta |❌|
|
244
|
+
| Dispatch API | Beta |❌|
|
245
|
+
| External Accounts API | Beta |❌|
|
246
|
+
| Media API | Beta | ❌|
|
247
|
+
| Messages API | General Availability |✅|
|
248
|
+
| Number Insight API | General Availability |✅|
|
249
|
+
| Number Management API | General Availability |✅|
|
250
|
+
| Pricing API | General Availability |✅|
|
251
|
+
| Redact API | Developer Preview |✅|
|
252
|
+
| Reports API | Beta |❌|
|
253
|
+
| SMS API | General Availability |✅|
|
254
|
+
| Verify API | General Availability |✅|
|
255
|
+
| Voice API | General Availability |✅|
|
758
256
|
|
759
257
|
## License
|
760
258
|
|
@@ -762,13 +260,3 @@ This library is released under the [Apache 2.0 License][license]
|
|
762
260
|
|
763
261
|
[signup]: https://dashboard.nexmo.com/sign-up?utm_source=DEV_REL&utm_medium=github&utm_campaign=ruby-client-library
|
764
262
|
[license]: LICENSE.txt
|
765
|
-
|
766
|
-
## Contribute!
|
767
|
-
|
768
|
-
_We :heart: contributions to this library!_
|
769
|
-
|
770
|
-
It is a good idea to [talk to us](https://developer.vonage.com/community/slack)
|
771
|
-
first if you plan to add any new functionality.
|
772
|
-
Otherwise, [bug reports](https://github.com/Vonage/vonage-ruby-sdk/issues),
|
773
|
-
[bug fixes](https://github.com/Vonage/vonage-ruby-sdk/pulls) and feedback on the
|
774
|
-
library are always appreciated.
|