vonage 7.28.0 → 8.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +89 -476
- 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 -11
- data/lib/vonage/logger.rb +3 -5
- data/lib/vonage/messaging/channels/viber.rb +1 -8
- data/lib/vonage/messaging/channels/whats_app.rb +1 -3
- data/lib/vonage/messaging/message.rb +0 -1
- data/lib/vonage/messaging.rb +4 -34
- 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 +53 -18
- 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 +9 -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 -42
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e003a6ed3211d3eace84884bf3fb03d21b81f097b13aba079f1906daf95380ff
|
4
|
+
data.tar.gz: 956c6921b50df45aaf2f1901b08ccd3cb164c2553b23d8e45570f63dcdf6f960
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1500879cd4a974009f6510cf12ea15b4ce60a9163f916b8a5e07fe785323c24c6909134163b21e29afc9c251550fd36a9e348c2ff7eac3b18b45f0e4ef7e1be1
|
7
|
+
data.tar.gz: fe368d23b897a7f1b2b9ba473c993a351ffb1233ef80304c16ec69ed28692c93e422c7a453f8d0da14b6e038424c215026a945d7ccee9b4a26412e3ecbe5435f
|
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
|
-
|
150
|
-
For certain legacy API products, such as the [SMS API](https://developer.vonage.com/en/messaging/sms/overview), [Verify v1 API](https://developer.vonage.com/en/verify/verify-v1/overview) and [Number Insight v1 API](https://developer.vonage.com/en/number-insight/overview), a `200` response is received even in situations where there is an API-related error. For exceptions raised in these situation, rather than a `Net::HTTPResponse` object, a `Vonage::Response` object will be made available as a property of the exception via a `response` getter method. The properties on this object will depend on the response data provided by the API endpoint. For example:
|
151
83
|
|
152
|
-
|
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,166 +95,108 @@ 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
98
|
|
208
|
-
|
99
|
+
## JWT authentication
|
209
100
|
|
210
|
-
|
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.
|
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:
|
217
103
|
|
218
|
-
|
104
|
+
```ruby
|
105
|
+
client = Vonage::Client.new(application_id: application_id, private_key: private_key)
|
106
|
+
```
|
219
107
|
|
220
|
-
|
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.
|
221
112
|
|
222
|
-
|
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:
|
223
116
|
|
224
117
|
```ruby
|
225
|
-
|
118
|
+
claims = {
|
119
|
+
application_id: application_id,
|
120
|
+
private_key: 'path/to/private.key',
|
121
|
+
nbf: 1483315200,
|
122
|
+
ttl: 800
|
123
|
+
}
|
226
124
|
|
227
|
-
|
228
|
-
webhook_params: params,
|
229
|
-
signature_secret: 'secret',
|
230
|
-
signature_method: 'sha512'
|
231
|
-
) # => returns true if the signature is valid, false otherwise
|
232
|
-
```
|
125
|
+
token = Vonage::JWT.generate(claims)
|
233
126
|
|
234
|
-
|
127
|
+
client = Vonage::Client.new(token: token)
|
128
|
+
````
|
235
129
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
signature_method: 'sha512'
|
240
|
-
)
|
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.
|
241
133
|
|
242
|
-
|
243
|
-
```
|
134
|
+
## Webhook signatures
|
244
135
|
|
245
|
-
|
136
|
+
To check webhook signatures you'll also need to specify the `signature_secret` option. For example:
|
246
137
|
|
247
138
|
```ruby
|
248
139
|
client = Vonage::Client.new
|
249
140
|
client.config.signature_secret = 'secret'
|
250
141
|
client.config.signature_method = 'sha512'
|
251
142
|
|
252
|
-
client.
|
253
|
-
|
254
|
-
|
255
|
-
|
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
|
-
|
267
|
-
The [Voice API](https://developer.vonage.com/en/voice/voice-api/overview) and [Messages API](https://developer.vonage.com/en/messages/overview) both include an `Authorization` header in their webhook requests. The value of this header includes a JSON Web Token (JWT) signed using the Signature Secret associated with your Vonage account.
|
268
|
-
|
269
|
-
The `Vonage::Voice` and `Vonage::Messaging` classes both define a `verify_webhook_token` method which can be used to verify the JWT received in the webhook `Authorization` header.
|
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:
|
272
|
-
|
273
|
-
```ruby
|
274
|
-
"Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE1OTUyN" # remainder of token omitted for brevity
|
143
|
+
if client.signature.check(request.GET)
|
144
|
+
# valid signature
|
145
|
+
else
|
146
|
+
# invalid signature
|
147
|
+
end
|
275
148
|
```
|
276
149
|
|
277
|
-
|
150
|
+
Alternatively you can set the `VONAGE_SIGNATURE_SECRET` environment variable.
|
278
151
|
|
279
|
-
|
152
|
+
Note: you'll need to contact support@nexmo.com to enable message signing on your account.
|
280
153
|
|
281
|
-
|
154
|
+
## Pagination
|
282
155
|
|
283
|
-
|
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.
|
284
157
|
|
285
|
-
|
286
|
-
client = Vonage::Client.new
|
158
|
+
The `auto_advance` parameter is set to a default of `true` for the following APIs:
|
287
159
|
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
```
|
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)
|
293
164
|
|
294
|
-
|
165
|
+
To modify the `auto_advance` behavior you can specify it in your method:
|
295
166
|
|
296
167
|
```ruby
|
297
|
-
client
|
298
|
-
signature_secret: 'secret'
|
299
|
-
)
|
300
|
-
|
301
|
-
client.voice.verify_webhook_token(token: extracted_token) # => returns true if the token is valid, false otherwise
|
168
|
+
client.applications.list(auto_advance: false)
|
302
169
|
```
|
303
170
|
|
304
|
-
|
171
|
+
## NCCO Builder
|
305
172
|
|
306
|
-
|
307
|
-
client = Vonage::Client.new
|
308
|
-
client.config.signature_secret = 'secret'
|
309
|
-
client.config.signature_method = 'sha512'
|
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.
|
310
174
|
|
311
|
-
|
312
|
-
```
|
175
|
+
The SDK includes an NCCO builder that you can use to build NCCOs for your Voice API methods.
|
313
176
|
|
314
|
-
|
177
|
+
For example, to build `talk` and `input` NCCO actions and then combine them into a single NCCO you would do the following:
|
315
178
|
|
316
179
|
```ruby
|
317
|
-
|
180
|
+
talk = Vonage::Voice::Ncco.talk(text: 'Hello World!')
|
181
|
+
input = Vonage::Voice::Ncco.input(type: ['dtmf'], dtmf: { bargeIn: true })
|
182
|
+
ncco = Vonage::Voice::Ncco.build(talk, input)
|
318
183
|
|
319
|
-
|
184
|
+
# => [{:action=>"talk", :text=>"Hello World!"}, {:action=>"input", :type=>["dtmf"], :dtmf=>{:bargeIn=>true}}]
|
320
185
|
```
|
321
186
|
|
322
|
-
|
323
|
-
|
324
|
-
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
|
-
|
326
|
-
The `auto_advance` parameter is set to a default of `true` for the following APIs:
|
327
|
-
|
328
|
-
* [Account API](https://developer.vonage.com/api/developer/account)
|
329
|
-
* [Application API](https://developer.vonage.com/api/application.v2)
|
330
|
-
* [Conversation API](https://developer.vonage.com/api/conversation)
|
331
|
-
* [Voice API](https://developer.vonage.com/api/voice)
|
332
|
-
|
333
|
-
To modify the `auto_advance` behavior you can specify it in your method:
|
187
|
+
Once you have the constructed NCCO you can then use it in a Voice API request:
|
334
188
|
|
335
189
|
```ruby
|
336
|
-
client.
|
190
|
+
response = client.voice.create({
|
191
|
+
to: [{type: 'phone', number: '14843331234'}],
|
192
|
+
from: {type: 'phone', number: '14843335555'},
|
193
|
+
ncco: ncco
|
194
|
+
})
|
337
195
|
```
|
338
196
|
|
339
|
-
|
340
197
|
## Messages API
|
341
198
|
|
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/
|
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.
|
343
200
|
|
344
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.
|
345
202
|
|
@@ -363,273 +220,39 @@ Once the message data is created, you can then send the message.
|
|
363
220
|
response = client.messaging.send(to: "447700900000", from: "447700900001", **message)
|
364
221
|
```
|
365
222
|
|
366
|
-
## Verify API v2
|
367
|
-
|
368
|
-
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.
|
369
|
-
|
370
|
-
The Ruby SDK provides two methods for interacting with the Verify v2 API:
|
371
|
-
|
372
|
-
- `Verify2#start_verification`: starts a new verification request. Here you can specify options for the request and the workflow to be used.
|
373
|
-
- `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.
|
374
|
-
|
375
|
-
### Creating a Verify2 Object
|
376
|
-
|
377
|
-
```ruby
|
378
|
-
verify = client.verify2
|
379
|
-
```
|
380
|
-
|
381
|
-
### Making a verification request
|
382
|
-
|
383
|
-
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.
|
384
|
-
|
385
|
-
Example with the required `:brand` and `:workflow` arguments:
|
386
|
-
|
387
|
-
```ruby
|
388
|
-
verification_request = verify.start_verification(
|
389
|
-
brand: 'Acme',
|
390
|
-
workflow: [{channel: 'sms', to: '447000000000'}]
|
391
|
-
)
|
392
|
-
```
|
393
|
-
|
394
|
-
Example with the required `:brand` and `:workflow` arguments, and an optional `code_length`:
|
395
|
-
|
396
|
-
```ruby
|
397
|
-
verification_request = verify.start_verification(
|
398
|
-
brand: 'Acme',
|
399
|
-
workflow: [{channel: 'sms', to: '447000000000'}],
|
400
|
-
code_length: 6
|
401
|
-
)
|
402
|
-
```
|
403
|
-
|
404
|
-
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`:
|
405
|
-
|
406
|
-
#### Create options using StartVerificationOptions object
|
407
|
-
|
408
|
-
```ruby
|
409
|
-
opts = verify.start_verification_options(
|
410
|
-
locale: 'fr-fr',
|
411
|
-
code_length: 6,
|
412
|
-
client_ref: 'abc-123'
|
413
|
-
).to_h
|
414
|
-
|
415
|
-
verification_request = verify.start_verification(
|
416
|
-
brand: 'Acme',
|
417
|
-
workflow: [{channel: 'email', to: 'alice.example.com'}],
|
418
|
-
**opts
|
419
|
-
)
|
420
|
-
```
|
421
|
-
|
422
|
-
#### Create workflow using Workflow and Channel objects
|
423
|
-
|
424
|
-
```ruby
|
425
|
-
# Instantiate a Workflow object
|
426
|
-
workflow = verify.workflow
|
427
|
-
|
428
|
-
# Add channels to the workflow
|
429
|
-
workflow << workflow.sms(to: '447000000000')
|
430
|
-
workflow << workflow.email(to: 'alice.example.com')
|
431
|
-
|
432
|
-
# Channel data is encpsulated in channel objects stored in the Workflow list array
|
433
|
-
workflow.list
|
434
|
-
# => [ #<Vonage::Verify2::Channels::SMS:0x0000561474a74778 @channel="sms", @to="447000000000">,
|
435
|
-
#<Vonage::Verify2::Channels::Email:0x0000561474c51a28 @channel="email", @to="alice.example.com">]
|
436
|
-
|
437
|
-
# To use the list as the value for `:workflow` in a `start_verification` request call,
|
438
|
-
# the objects must be hashified
|
439
|
-
workflow_list = workflow.hashified_list
|
440
|
-
# => [{:channel=>"sms", :to=>"447000000000"}, {:channel=>"email", :to=>"alice.example.com"}]
|
441
|
-
|
442
|
-
verification_request = verify.start_verification(brand: 'Acme', workflow: workflow_list)
|
443
|
-
```
|
444
|
-
|
445
|
-
#### Create a workflow using the WorkflowBuilder
|
446
|
-
|
447
|
-
```ruby
|
448
|
-
workflow = verify.workflow_builder.build do |builder|
|
449
|
-
builder.add_voice(to: '447000000001')
|
450
|
-
builder.add_whatsapp(to: '447000000000')
|
451
|
-
end
|
452
|
-
|
453
|
-
workflow_list = workflow.hashified_list
|
454
|
-
# => [{:channel=>"voice", :to=>"447000000001"}, {:channel=>"whatsapp", :to=>"447000000000"}]
|
455
|
-
|
456
|
-
verification_request = verify.start_verification(brand: 'Acme', workflow: workflow_list)
|
457
|
-
```
|
458
|
-
|
459
|
-
### Cancelling a request
|
460
|
-
|
461
|
-
You can cancel in in-progress verification request
|
462
|
-
|
463
|
-
```ruby
|
464
|
-
# Get the `request_id` from the Vonage#Response object returned by the `start_verification` method call
|
465
|
-
request_id = verification_request.request_id
|
466
|
-
|
467
|
-
verify.cancel_verification_request(request_id: request_id)
|
468
|
-
```
|
469
|
-
|
470
|
-
### Checking a code
|
471
|
-
|
472
|
-
```ruby
|
473
|
-
# Get the `request_id` from the Vonage#Response object returned by the `start_verification` method call
|
474
|
-
request_id = verification_request.request_id
|
475
|
-
|
476
|
-
# Get the one-time code via user input
|
477
|
-
# e.g. from params in a route handler or controller action for a form input
|
478
|
-
code = params[:code]
|
479
|
-
|
480
|
-
begin
|
481
|
-
code_check = verify.check_code(request_id: request_id, code: code)
|
482
|
-
rescue => error
|
483
|
-
# an invalid code will raise an exception of type Vonage::ClientError
|
484
|
-
end
|
485
|
-
|
486
|
-
if code_check.http_response.code == '200'
|
487
|
-
# code is valid
|
488
|
-
end
|
489
|
-
```
|
490
|
-
|
491
|
-
### Working with Verify Custom Templates and Template Fragments
|
492
|
-
|
493
|
-
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.
|
494
|
-
|
495
|
-
#### Templates
|
496
|
-
|
497
|
-
```ruby
|
498
|
-
# Get a list of all templates
|
499
|
-
template_list = verify.templates.list
|
500
|
-
|
501
|
-
# Get details of a specific template
|
502
|
-
template = verify.templates.info(template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9')
|
503
|
-
|
504
|
-
# Create a new template
|
505
|
-
verify.templates.create(name: 'my-template')
|
506
|
-
|
507
|
-
# Update an existing template
|
508
|
-
verify.templates.update(
|
509
|
-
template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9',
|
510
|
-
name: 'my-updated-template'
|
511
|
-
)
|
512
|
-
|
513
|
-
# Delete a template
|
514
|
-
verify.templates.delete(template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9')
|
515
|
-
```
|
516
|
-
|
517
|
-
#### Template Fragments
|
518
|
-
|
519
|
-
```ruby
|
520
|
-
# Get a list of template fragments for a specific template
|
521
|
-
template_fragment_list = verify.template_fragments.list(template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9')
|
522
|
-
|
523
|
-
# Get details of a specific template fragment
|
524
|
-
template_fragment = verify.template_fragments.info(
|
525
|
-
template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9',
|
526
|
-
template_fragment_id: 'c70f446e-997a-4313-a081-60a02a31dc19'
|
527
|
-
)
|
528
|
-
|
529
|
-
# Create a new template fragement
|
530
|
-
verify.template_fragments.create(
|
531
|
-
template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9',
|
532
|
-
channel: 'sms',
|
533
|
-
locale: 'en-gb',
|
534
|
-
text: 'Your code is: ${code}'
|
535
|
-
)
|
536
|
-
|
537
|
-
# Update an existing template fragment
|
538
|
-
verify.template_fragments.update(
|
539
|
-
template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9',
|
540
|
-
template_fragment_id: 'c70f446e-997a-4313-a081-60a02a31dc1',
|
541
|
-
text: 'Your one-time code is: ${code}'
|
542
|
-
)
|
543
|
-
|
544
|
-
# Delete a template fragment
|
545
|
-
verify.template_fragments.delete(
|
546
|
-
template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9',
|
547
|
-
template_fragment_id: 'c70f446e-997a-4313-a081-60a02a31dc19'
|
548
|
-
)
|
549
|
-
```
|
550
|
-
|
551
|
-
## Voice API
|
552
|
-
|
553
|
-
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.
|
554
|
-
|
555
|
-
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:
|
556
|
-
|
557
|
-
```ruby
|
558
|
-
response = client.voice.create(
|
559
|
-
to: [{
|
560
|
-
type: 'phone',
|
561
|
-
number: '447700900000'
|
562
|
-
}],
|
563
|
-
from: {
|
564
|
-
type: 'phone',
|
565
|
-
number: '447700900001'
|
566
|
-
},
|
567
|
-
answer_url: [
|
568
|
-
'https://raw.githubusercontent.com/nexmo-community/ncco-examples/gh-pages/text-to-speech.json'
|
569
|
-
]
|
570
|
-
)
|
571
|
-
```
|
572
|
-
|
573
|
-
### NCCO Builder
|
574
|
-
|
575
|
-
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.
|
576
|
-
|
577
|
-
The SDK includes an NCCO builder that you can use to build NCCOs for your Voice API methods.
|
578
|
-
|
579
|
-
For example, to build `talk` and `input` NCCO actions and then combine them into a single NCCO you would do the following:
|
580
|
-
|
581
|
-
```ruby
|
582
|
-
talk = Vonage::Voice::Ncco.talk(text: 'Hello World!')
|
583
|
-
input = Vonage::Voice::Ncco.input(type: ['dtmf'], dtmf: { bargeIn: true })
|
584
|
-
ncco = Vonage::Voice::Ncco.build(talk, input)
|
585
|
-
|
586
|
-
# => [{:action=>"talk", :text=>"Hello World!"}, {:action=>"input", :type=>["dtmf"], :dtmf=>{:bargeIn=>true}}]
|
587
|
-
```
|
588
|
-
|
589
|
-
Once you have the constructed NCCO you can then use it in a Voice API request:
|
590
|
-
|
591
|
-
```ruby
|
592
|
-
response = client.voice.create({
|
593
|
-
to: [{type: 'phone', number: '14843331234'}],
|
594
|
-
from: {type: 'phone', number: '14843335555'},
|
595
|
-
ncco: ncco
|
596
|
-
})
|
597
|
-
```
|
598
|
-
|
599
223
|
## Documentation
|
600
224
|
|
601
|
-
Vonage Ruby
|
225
|
+
Vonage Ruby documentation: https://www.rubydoc.info/github/Vonage/vonage-ruby-sdk
|
602
226
|
|
603
|
-
Vonage Ruby
|
227
|
+
Vonage Ruby code examples: https://github.com/Nexmo/nexmo-ruby-code-snippets
|
604
228
|
|
605
|
-
Vonage APIs API reference: https://developer.
|
606
|
-
|
607
|
-
## Supported APIs
|
229
|
+
Vonage APIs API reference: https://developer.nexmo.com/api
|
608
230
|
|
609
|
-
|
231
|
+
## Frequently Asked Questions
|
610
232
|
|
611
|
-
|
612
|
-
* [Application API](https://developer.vonage.com/en/application/overview)
|
613
|
-
* [Conversation API](https://developer.vonage.com/en/conversation/overview)
|
614
|
-
* [Meetings API](https://developer.vonage.com/en/meetings/overview)
|
615
|
-
* [Messages API](https://developer.vonage.com/en/messages/overview)
|
616
|
-
* [Network Number Verification API](https://developer.vonage.com/en/number-verification/overview)
|
617
|
-
* [Network SIM Swap API](https://developer.vonage.com/en/sim-swap/overview)
|
618
|
-
* [Number Insight API](https://developer.vonage.com/en/number-insight/overview)
|
619
|
-
* [Numbers API](https://developer.vonage.com/en/numbers/overview)
|
620
|
-
* [Proactive Connect API](https://developer.vonage.com/en/proactive-connect/overview) *
|
621
|
-
* [Redact API](https://developer.vonage.com/en/redact/overview)
|
622
|
-
* [SMS API](https://developer.vonage.com/en/messaging/sms/overview)
|
623
|
-
* [Subaccounts API](https://developer.vonage.com/en/account/subaccounts/overview)
|
624
|
-
* [Verify API](https://developer.vonage.com/en/verify/overview)
|
625
|
-
* [Voice API](https://developer.vonage.com/en/verify/overview)
|
626
|
-
|
627
|
-
\* The Proactive Connect API is partially supported in the SDK. Specifically, the Events, Items, and Lists endpoints are supported.
|
628
|
-
|
629
|
-
## Other SDKs and Tools
|
630
|
-
|
631
|
-
You can find information about other Vonage SDKs and Tooling on our [Developer Portal](https://developer.vonage.com/en/tools).
|
233
|
+
## Supported APIs
|
632
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 |✅|
|
633
256
|
|
634
257
|
## License
|
635
258
|
|
@@ -637,13 +260,3 @@ This library is released under the [Apache 2.0 License][license]
|
|
637
260
|
|
638
261
|
[signup]: https://dashboard.nexmo.com/sign-up?utm_source=DEV_REL&utm_medium=github&utm_campaign=ruby-client-library
|
639
262
|
[license]: LICENSE.txt
|
640
|
-
|
641
|
-
## Contribute!
|
642
|
-
|
643
|
-
_We :heart: contributions to this library!_
|
644
|
-
|
645
|
-
It is a good idea to [talk to us](https://developer.vonage.com/community/slack)
|
646
|
-
first if you plan to add any new functionality.
|
647
|
-
Otherwise, [bug reports](https://github.com/Vonage/vonage-ruby-sdk/issues),
|
648
|
-
[bug fixes](https://github.com/Vonage/vonage-ruby-sdk/pulls) and feedback on the
|
649
|
-
library are always appreciated.
|