notifications-ruby-client 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3bb224294830c1d0d4c4d776597d7ce144ca14fb993500f432275188914ab4cb
4
+ data.tar.gz: 94b010994127fbb3bcea06a408ec33587b3dbef34b8eaf404f6ece05d26eaf5b
5
+ SHA512:
6
+ metadata.gz: 3c9f30f36f38523e8c36a784b9780f434f3cc798b9e6824dcbfa06dd2fcb96802dff67c9dd2affe7c294243929ab734da477aea8c89dc39aa9646aba8e815966
7
+ data.tar.gz: cd81acb5965952e29c3e5c26c6c5c6144b8a8eca2b60ee6e2a40e81789f839c2d7876dd7f2b492c157585e16f19f184b8bef0eb6aa23eb502bee89d53a2a6885
@@ -0,0 +1,12 @@
1
+ <!--Thanks for contributing to GOV.UK Notify. Using this template to write your pull request message will help get it merged as soon as possible. -->
2
+
3
+ ## What problem does the pull request solve?
4
+ <!--- Describe why you’re making this change -->
5
+
6
+ ## Checklist
7
+
8
+ <!--- All of the following are normally needed. Don’t worry if you haven’t done them or don’t know how – someone from the Notify team will be able to help. -->
9
+ - [x] I’ve used the pull request template
10
+ - [ ] I’ve written unit tests for these changes
11
+ - [ ] I’ve updated the documentation (in `DOCUMENTATION.md`)
12
+ - [ ] I’ve bumped the version number (in `lib/notifications/client/version.rb`)
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .DS_Store
11
+ /vendor
12
+ environment.sh
13
+ docker.env
14
+ /.idea/
15
+ /.idea/vcs.xml
16
+ docker.env
17
+ vendor
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,2 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
@@ -0,0 +1,100 @@
1
+ ## 4.0.0
2
+
3
+ * `RequestError.message` now returns a string, not an array of hashes – see https://github.com/alphagov/notifications-ruby-client/pull/72
4
+
5
+ ## 3.1.0
6
+
7
+ * Added `html` field to the TemplatePreview response, so users can see
8
+ the rendered HTML of their email templates.
9
+
10
+ ## 3.0.0
11
+
12
+ * Changed response class for `send_precompiled_letter` request from `ResponseNotification` to a new response class: `ResponsePrecompiledLetter`. This may affect users sending precompiled letters.
13
+ * Added an optional `postage` argument to `send_precompiled_letter` method, so users can specify postage when sending
14
+ a precompiled letter via API.
15
+ * Added postage to `Notification` class on the client.
16
+
17
+ ## 2.10.0
18
+
19
+ * Added subclasses of the `RequestError` class to handle specific types of errors.
20
+
21
+ ## 2.9.0
22
+
23
+ * Added the `send_precompiled_letter` method which allows the client to send letters as PDF files.
24
+ * This requires two arguments - a reference for the letter and the PDF letter file. The file must conform to the Notify printing template.
25
+ * Added support for document uploads using the `send_email` method.
26
+
27
+ ## 2.8.0
28
+
29
+ * Updated the Template class to have a `name` property, which is the name of the template as set in Notify.
30
+
31
+
32
+ ## 2.7.0
33
+
34
+ * The Notification class has a new `created_by_name` property.
35
+ * If the notification was sent manually this will be the name of the sender. If the notification was sent through the API this will be `nil`.
36
+
37
+ ## 2.6.0
38
+
39
+ ### Changed
40
+ * The client now validates that UUIDs derived from the API key are valid and raises a helpful error message if they are not.
41
+
42
+ ## 2.5.0
43
+
44
+ ### Changed
45
+ * Added a new `get_received_texts` method.
46
+ * an optional `older_than` argument can be specified to retrieve the next 250 received text messages older than the given received text id. If omitted 250 of the most recent received text messages are returned.
47
+
48
+
49
+ ## 2.4.0
50
+
51
+ ### Changed
52
+ * It is now possible to have multiple SMS senders and to specify which sender an SMS notification should come from. Added the option to specify `sms_sender_id` when using the `send_sms` method. If no `sms_sender_id` is specified, the default sms sender will be used.
53
+ * Replaced `factory_girl` development dependency with `factory_bot`, which is the [new name for Factory girl.](https://robots.thoughtbot.com/factory_bot)
54
+
55
+
56
+ ## 2.3.0
57
+
58
+ ### Changed
59
+ * It is now possible to have multiple email to reply to addresses. Added the option to specify an `email_reply_to_id`
60
+ when using the `send_email` method. If no `email_reply_to_id` is specified, the default email reply to address will be
61
+ used.
62
+ * Upgraded all dependencies
63
+ * Minor code style changes and fixes for the tests
64
+
65
+ ## 2.2.0
66
+
67
+ ### Changed
68
+ * Added a new `send_letter` method
69
+ * Removed 'govuk-lint' gem as a development dependency
70
+
71
+
72
+ ## 2.1.0
73
+
74
+ ### Changed
75
+ * Added methods to get templates and generate a preview of a template.
76
+ * `get_template_by_id` - get the latest version of a template by id.
77
+ * `get_template_version` - get the template by id and version.
78
+ * `get_all_templates` - get all templates, can be filtered by template type.
79
+ * `generate_template_preview` - get the contents of a template with the placeholders replaced with the given personalisation.
80
+ * See the README for more information about the new template methods.
81
+
82
+
83
+ ## 2.0.0
84
+
85
+ ### Changed
86
+ * Using version 2 of the notification-api.
87
+ * A new `Notifications::Client` no longer requires the `service_id`, only the `api_key` is required.
88
+ * `Notifications::Client.send_sms()` input parameters and the response object has changed, see the README for more information.
89
+ ```ruby
90
+ client.sendSms(phone_number, template_id, personalisation, reference)
91
+ ```
92
+ * `Notifications::Client.send_email()` input parameters has changed and the response object, see the README for more information.
93
+ ```ruby
94
+ client.sendSms(phone_number, template_id, personalisation, reference)
95
+ ```
96
+ * `reference` is a new optional argument of the send methods. The `reference` can be used as a unique reference for the notification. Because Notify does not require this reference to be unique you could also use this reference to identify a batch or group of notifications.
97
+ * `Notifications::Client.get_all_notifications()` => the response object has changed.
98
+ * You can also filter the collection of `Notifications` by `reference`. See the README for more information.
99
+ * `Notifications::Client.get_notification(id)` => the response object has changed. See the README for more information.
100
+ * Initializing a client only requires the api key.
@@ -0,0 +1,39 @@
1
+ # Contributing
2
+
3
+ Pull requests are welcome.
4
+
5
+ ## Tests
6
+
7
+ There are unit and integration tests that can be run to test functionality of the client.
8
+
9
+ ## Unit Tests
10
+
11
+ To run the unit tests:
12
+
13
+ ```
14
+ make test
15
+ ```
16
+
17
+ ## Integration Tests
18
+
19
+ Before running the integration tests, please ensure that the environment variables are set up.
20
+
21
+ ```sh
22
+ export NOTIFY_API_URL="https://example.notify-api.url"
23
+ export API_KEY="example_API_test_key"
24
+ export FUNCTIONAL_TEST_NUMBER="valid mobile number"
25
+ export FUNCTIONAL_TEST_EMAIL="valid email address"
26
+ export EMAIL_TEMPLATE_ID="valid email_template_id"
27
+ export SMS_TEMPLATE_ID="valid sms_template_id"
28
+ export LETTER_TEMPLATE_ID="valid letter_template_id"
29
+ export EMAIL_REPLY_TO_ID="valid email reply to id"
30
+ export SMS_SENDER_ID="valid sms_sender_id - to test sending to a receiving number, so needs to be a valid number"
31
+ export API_SENDING_KEY="API_whitelist_key for sending a SMS to a receiving number"
32
+ export INBOUND_SMS_QUERY_KEY="API_test_key to get received text messages"
33
+ ```
34
+
35
+ To run the integration tests:
36
+
37
+ ```
38
+ make integration-test
39
+ ```
@@ -0,0 +1,949 @@
1
+ # Ruby client documentation
2
+
3
+ This documentation is for developers interested in using the GOV.UK Notify Ruby client to send emails, text messages or letters.
4
+
5
+ We recommend that you use this client library rather than use the [GOV.UK Notify API](https://github.com/alphagov/notifications-api) directly, as there is no documentation for using the API in this way.
6
+
7
+ # Set up the client
8
+
9
+ ## Install the client
10
+
11
+ Run the following in the command line:
12
+
13
+ ```
14
+ gem install 'notifications-ruby-client'
15
+ ```
16
+
17
+ Refer to the [client changelog](https://github.com/alphagov/notifications-ruby-client/blob/master/CHANGELOG.md) for the version number and the latest updates.
18
+
19
+ ## Create a new instance of the client
20
+
21
+ Add this code to your application:
22
+
23
+ ```ruby
24
+ require 'notifications/client'
25
+ client = Notifications::Client.new(api_key)
26
+ ```
27
+
28
+ To get an API key, [sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/) and go to the __API integration__ page. You can find more information in the [API keys](/ruby.html#api-keys) section of this documentation.
29
+
30
+ # Send a message
31
+
32
+ You can use GOV.UK Notify to send text messages, emails or letters.
33
+
34
+ ## Send a text message
35
+
36
+ ### Method
37
+
38
+ ```ruby
39
+ smsresponse = client.send_sms(
40
+ phone_number: "+447900900123",
41
+ template_id: "f33517ff-2a88-4f6e-b855-c550268ce08a",
42
+ )
43
+ ```
44
+
45
+ ### Arguments
46
+
47
+ #### phone_number (required)
48
+
49
+ The phone number of the text message recipient. This can be a UK or international number. For example:
50
+
51
+ ```ruby
52
+ phone_number:"+447900900123"
53
+ ```
54
+
55
+ #### template_id (required)
56
+
57
+ Sign in to [GOV.UK Notify](https://www.notifications.service.gov.uk/) and go to the __Templates__ page to find the template ID. For example:
58
+
59
+ ```ruby
60
+ template_id:"f33517ff-2a88-4f6e-b855-c550268ce08a"
61
+ ```
62
+
63
+ #### personalisation (optional)
64
+
65
+ If a template has placeholder fields for personalised information such as name or reference number, you must provide their values in a hash. For example:
66
+
67
+ ```ruby
68
+ personalisation: {
69
+ name: "John Smith",
70
+ ID: "300241",
71
+ }
72
+ ```
73
+
74
+ You can leave out this argument if a template does not have any placeholder fields for personalised information.
75
+
76
+ #### reference (optional)
77
+
78
+ A unique identifier you can create if necessary. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. For example:
79
+
80
+ ```ruby
81
+ reference: "your_reference_string"
82
+ ```
83
+
84
+ You can leave out this argument if you do not have a reference.
85
+
86
+ #### sms_sender_id (optional)
87
+
88
+ A unique identifier of the sender of the text message notification. You can find this information on the __Text Message sender__ settings screen.
89
+
90
+ 1. Sign in to your GOV.UK Notify account.
91
+ 1. Go to __Settings__.
92
+ 1. If you need to change to another service, select __Switch service__ in the top right corner of the screen and select the correct one.
93
+ 1. Go to the __Text Messages__ section and select __Manage__ on the __Text Message sender__ row.
94
+
95
+ You can then either:
96
+
97
+ - copy the sender ID that you want to use and paste it into the method
98
+ - select __Change__ to change the default sender that the service uses, and select __Save__
99
+
100
+
101
+ For example:
102
+
103
+ ```ruby
104
+ sms_sender_id: "8e222534-7f05-4972-86e3-17c5d9f894e2"
105
+ ```
106
+
107
+ You can leave out this argument if your service only has one text message sender, or if you want to use the default sender.
108
+
109
+ ### Response
110
+
111
+ If the request to the client is successful, the client returns a `Notifications::Client:ResponseNotification` object. In the example shown in the [Method section](/ruby.html#method), the object is named `smsresponse`.
112
+
113
+ You can then call different methods on this object:
114
+
115
+ |Method|Information|Type|
116
+ |:---|:---|:---|
117
+ |`smsresponse.id`|Notification UUID|String|
118
+ |`smsresponse.reference`|`reference` argument|String|
119
+ |`smsresponse.content`|- `body`: Message body sent to the recipient<br>- `from_number`: SMS sender number of your service|Hash|
120
+ |`smsresponse.template`|Contains the `id`, `version` and `uri` of the template|Hash|
121
+ |`smsresponse.uri`|Notification URL|String|
122
+
123
+ If you are using the [test API key](/ruby.html#test), all your messages come back with a `delivered` status.
124
+
125
+ All messages sent using the [team and whitelist](#team-and-whitelist) or [live](#live) keys appear on your GOV.UK Notify dashboard.
126
+
127
+ ### Error codes
128
+
129
+ If the request is not successful, the client returns a `Notifications::Client::RequestError` and an error code.
130
+
131
+ |error.code|error.message|class|How to fix|
132
+ |:---|:---|:---|:---|
133
+ |`400`|`BadRequestError: Can't send to this recipient using a team-only API key`|`BadRequestError`|Use the correct type of [API key](/ruby.html#api-keys)|
134
+ |`400`|`BadRequestError: Can't send to this recipient when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode`|`BadRequestError`|Your service cannot send this notification in [trial mode](https://www.notifications.service.gov.uk/features/using-notify#trial-mode)|
135
+ |`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
136
+ |`403`|`AuthError: Invalid token: signature, api token not found`|`AuthError`|Use the correct API key. Refer to [API keys](/ruby.html#api-keys) for more information|
137
+ |`429`|`RateLimitError: Exceeded rate limit for key type TEAM/TEST/LIVE of 3000 requests per 60 seconds`|`RateLimitError`|Refer to [API rate limits](/ruby.html#api-rate-limits) for more information|
138
+ |`429`|`TooManyRequestsError: Exceeded send limits (LIMIT NUMBER) for today`|`ClientError`|Refer to [service limits](/ruby.html#service-limits) for the limit number|
139
+ |`500`|`Exception: Internal server error`|`ServerError`|Notify was unable to process the request, resend your notification|
140
+
141
+ ## Send an email
142
+
143
+ ### Method
144
+
145
+ ```ruby
146
+ emailresponse = client.send_email(
147
+ email_address: "sender@something.com",
148
+ template_id: "f33517ff-2a88-4f6e-b855-c550268ce08a",
149
+ )
150
+ ```
151
+
152
+ ### Arguments
153
+
154
+ #### email_address (required)
155
+
156
+ The email address of the recipient. For example:
157
+
158
+ ```ruby
159
+ email_address: "sender@something.com"
160
+ ```
161
+
162
+ #### template_id (required)
163
+
164
+ Sign in to [GOV.UK Notify](https://www.notifications.service.gov.uk/) and go to the __Templates__ page to find the template ID. For example:
165
+
166
+ ```ruby
167
+ template_id: "f33517ff-2a88-4f6e-b855-c550268ce08a"
168
+ ```
169
+
170
+ #### personalisation (optional)
171
+
172
+ If a template has placeholder fields for personalised information such as name or reference number, you must provide their values in a hash. For example:
173
+
174
+ ```ruby
175
+ personalisation: {
176
+ name: "John Smith",
177
+ year: "2016"
178
+ }
179
+ ```
180
+
181
+ You can leave out this argument if a template does not have any placeholder fields for personalised information.
182
+
183
+ #### reference (optional)
184
+
185
+ A unique identifier you can create if necessary. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. For example:
186
+
187
+ ```ruby
188
+ reference: "your_reference_string"
189
+ ```
190
+
191
+ You can leave out this argument if you do not have a reference.
192
+
193
+ #### email_reply_to_id (optional)
194
+
195
+ This is an email reply-to address specified by you to receive replies from your users. Your service cannot go live until you set up at least one of these email addresses.
196
+
197
+ 1. Sign into your GOV.UK Notify account.
198
+ 1. Go to __Settings__.
199
+ 1. If you need to change to another service, select __Switch service__ in the top right corner of the screen and select the correct one.
200
+ 1. Go to the __Email__ section and select __Manage__ on the __Email reply-to addresses__ row.
201
+ 1. Select __Change__ to specify the email address to receive replies, and select __Save__.
202
+
203
+
204
+ For example:
205
+
206
+ ```ruby
207
+ email_reply_to_id: '8e222534-7f05-4972-86e3-17c5d9f894e2'
208
+ ```
209
+
210
+ You can leave out this argument if your service only has one email reply-to address, or you want to use the default email address.
211
+
212
+ ## Send a document by email
213
+
214
+ Send files without the need for email attachments.
215
+
216
+ This is an invitation-only feature. [Contact the GOV.UK Notify team](https://www.notifications.service.gov.uk/support) to enable this function for your service.
217
+
218
+ To send a document by email, add a placeholder field to the template then upload a file. The placeholder field will contain a secure link to download the document.
219
+
220
+ ### Add a placeholder field to the template
221
+
222
+ 1. Sign in to [GOV.UK Notify](https://www.notifications.service.gov.uk/).
223
+ 1. Go to the __Templates__ page and select the relevant email template.
224
+ 1. Add a placeholder field to the email template using double brackets. For example:
225
+
226
+ "Download your document at: ((link_to_document))"
227
+
228
+ ### Upload your document
229
+
230
+ The document you upload must be a PDF file smaller than 2MB.
231
+
232
+ 1. Pass the file object as an argument to the `Notifications.prepare_upload` helper method.
233
+ 1. Pass the result into the personalisation argument.
234
+
235
+ For example:
236
+
237
+ ```ruby
238
+ File.open("file.pdf", "rb") do |f|
239
+ ...
240
+ personalisation: {
241
+ first_name: "Amala",
242
+ application_date: "2018-01-01",
243
+ link_to_document: Notifications.prepare_upload(f),
244
+ }
245
+ end
246
+ ```
247
+
248
+ ### Response
249
+
250
+ If the request to the client is successful, the client returns a `Notifications::Client:ResponseNotification` object. In the example shown in the [Method section](/ruby.html#send-an-email-method), the object is named `emailresponse`.
251
+
252
+ You can then call different methods on this object to return the requested information.
253
+
254
+ |Method|Information|Type|
255
+ |:---|:---|:---|
256
+ |`emailresponse.id`|Notification UUID|String|
257
+ |`emailresponse.reference`|`reference` argument|String|
258
+ |`emailresponse.content`|- `body`: Message body<br>- `subject`: Message subject<br>- `from_email`: From email address of your service found on the **Settings** page|Hash|
259
+ |`emailresponse.template`|Contains the `id`, `version` and `uri` of the template|Hash|
260
+ |`emailresponse.uri`|Notification URL|String|
261
+
262
+ ### Error codes
263
+
264
+ If the request is not successful, the client returns a `Notifications::Client::RequestError` and an error code.
265
+
266
+ |error.code|error.message|class|How to fix|
267
+ |:--- |:---|:---|:---|
268
+ |`400`|`BadRequestError: Can't send to this recipient using a team-only API key`|`BadRequestError`|Use the correct type of [API key](/ruby.html#api-keys)|
269
+ |`400`|`BadRequestError: Can't send to this recipient when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode`|`BadRequestError`|Your service cannot send this notification in [trial mode](https://www.notifications.service.gov.uk/features/using-notify#trial-mode)|
270
+ |`400`|`BadRequestError: Unsupported document type '{}'. Supported types are: {}`|`BadRequestError`|The document you upload must be a PDF file|
271
+ |`400`|`BadRequestError: Document didn't pass the virus scan`|`BadRequestError`|The document you upload must be virus free|
272
+ |`400`|`BadRequestError: Service is not allowed to send documents`|`BadRequestError`|Contact the GOV.UK Notify team|
273
+ |`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
274
+ |`403`|`AuthError: Invalid token: signature, api token not found`|`AuthError`|Use the correct API key. Refer to [API keys](/ruby.html#api-keys) for more information|
275
+ |`429`|`RateLimitError: Exceeded rate limit for key type TEAM/TEST/LIVE of 3000 requests per 60 seconds`|`RateLimitError`|Refer to [API rate limits](/ruby.html#api-rate-limits) for more information|
276
+ |`429`|`TooManyRequestsError: Exceeded send limits (LIMIT NUMBER) for today`|`RateLimitError`|Refer to [service limits](/ruby.html#service-limits) for the limit number|
277
+ |`500`|`Exception: Internal server error`|`ServerError`|Notify was unable to process the request, resend your notification|
278
+ |-|`ArgumentError: Document is larger than 2MB")`|-|Document size was too large, upload a smaller document|
279
+
280
+ ## Send a letter
281
+
282
+ When your service first signs up to GOV.UK Notify, you’ll start in trial mode. You can only send letters in live mode. You must ask GOV.UK Notify to make your service live.
283
+
284
+ 1. Sign in to [GOV.UK Notify](https://www.notifications.service.gov.uk/).
285
+ 1. Select __Using Notify__.
286
+ 1. Select __requesting to go live__.
287
+
288
+ ### Method
289
+
290
+ ```ruby
291
+ letterresponse = client.send_letter(
292
+ template_id: "f33517ff-2a88-4f6e-b855-c550268ce08a",
293
+ personalisation: {
294
+ address_line_1: 'The Occupier',
295
+ address_line_2: '123 High Street',
296
+ postcode: 'SW14 6BH',
297
+ },
298
+ )
299
+ ```
300
+
301
+ ### Arguments
302
+
303
+ #### template_id (required)
304
+
305
+ Sign in to GOV.UK Notify and go to the __Templates__ page to find the template ID. For example:
306
+
307
+ ```ruby
308
+ template_id: "f33517ff-2a88-4f6e-b855-c550268ce08a"
309
+ ```
310
+
311
+ #### personalisation (required)
312
+
313
+ The personalisation argument always contains the following parameters for the letter recipient's address:
314
+
315
+ - `address_line_1`
316
+ - `address_line_2`
317
+ - `postcode`
318
+
319
+ Any other placeholder fields included in the letter template also count as required parameters. You must provide their values in a hash. For example:
320
+
321
+
322
+ ```ruby
323
+ personalisation: {
324
+ address_line_1: 'The Occupier', # mandatory address field
325
+ address_line_2: '123 High Street', # mandatory address field
326
+ postcode: 'SW14 6BH', # mandatory address field
327
+ name: 'John Smith', # field from template
328
+ application_date: '2018-01-01' # field from template
329
+ },
330
+ ```
331
+
332
+ #### personalisation (optional)
333
+
334
+ The following parameters in the letter recipient's address are optional:
335
+
336
+ ```ruby
337
+ personalisation: {
338
+ address_line_3: 'Richmond', # optional address field
339
+ address_line_4: 'London', # optional address field
340
+ address_line_5: 'Middlesex', # optional address field
341
+ address_line_6: 'UK', # optional address field
342
+ },
343
+ ```
344
+
345
+ #### reference (optional)
346
+
347
+ A unique identifier you can create if necessary. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. For example:
348
+
349
+ ```ruby
350
+ reference: 'your_reference_string'
351
+ ```
352
+
353
+ ### Response
354
+
355
+ If the request to the client is successful, the client returns a `Notifications::Client:ResponseNotification` object. In the example shown in the [Method section](/ruby.html#send-a-letter-method), the object is named `letterresponse`.
356
+
357
+ You can then call different methods on this object to return the requested information.
358
+
359
+ |Method|Information|Type|
360
+ |:---|:---|:---|
361
+ |`letterresponse.id`|Notification UUID|String|
362
+ |`letterresponse.reference`|`reference` argument|String|
363
+ |`letterresponse.content`|- `body`: Letter body<br>- `subject`: Letter subject or main heading|Hash|
364
+ |`letterresponse.template`|Contains the `id`, `version` and `uri` of the template|Hash|
365
+ |`letterresponse.uri`|Notification URL|String|
366
+
367
+
368
+ ### Error codes
369
+
370
+ If the request is not successful, the client returns a `Notifications::Client::RequestError` and an error code.
371
+
372
+ |error.code|error.message|class|How to fix|
373
+ |:--- |:---|:---|:---|
374
+ |`400`|`BadRequestError: Cannot send letters with a team api key`|`BadRequestError`|Use the correct type of [API key](/ruby.html#api-keys)|
375
+ |`400`|`BadRequestError: Cannot send letters when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode`|`BadRequestError`|Your service cannot send this notification in [trial mode](https://www.notifications.service.gov.uk/features/using-notify#trial-mode)|
376
+ |`400`|`ValidationError: personalisation address_line_1 is a required property`|`BadRequestError`|Ensure that your template has a field for the first line of the address, refer to [personalisation](/ruby.html#personalisation-required) for more information|
377
+ |`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
378
+ |`403`|`AuthError: Invalid token: signature, api token not found`|`AuthError`|Use the correct API key. Refer to [API keys](/ruby.html#api-keys) for more information|
379
+ |`429`|`RateLimitError: Exceeded rate limit for key type TEAM/TEST/LIVE of 3000 requests per 60 seconds`|`RateLimitError`|Refer to [API rate limits](/ruby.html#api-rate-limits) for more information|
380
+ |`429`|`TooManyRequestsError: Exceeded send limits (LIMIT NUMBER) for today`|`RateLimitError`|Refer to [service limits](/ruby.html#service-limits) for the limit number|
381
+ |`500`|`Exception: Internal server error`|`ServerError`|Notify was unable to process the request, resend your notification|
382
+
383
+ ## Send a precompiled letter
384
+
385
+ ### Method
386
+ ```ruby
387
+ precompiled_letter = client.send_precompiled_letter(reference, pdf_file)
388
+ ```
389
+
390
+ ### Arguments
391
+
392
+ #### reference (required)
393
+ A unique identifier you create. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address.
394
+
395
+ #### pdf_file (required)
396
+
397
+ The precompiled letter must be a PDF file which meets [the GOV.UK Notify PDF letter specification](https://docs.notifications.service.gov.uk/documentation/images/notify-pdf-letter-spec-v2.3.pdf).
398
+
399
+ ```ruby
400
+ File.open("path/to/pdf_file", "rb") do |pdf_file|
401
+ client.send_precompiled_letter("your reference", pdf_file)
402
+ end
403
+ ```
404
+
405
+ #### postage (optional)
406
+
407
+ You can choose first or second class postage for your precompiled letter. Set the value to `first` for first class, or `second` for second class. If you do not pass in this argument, the postage will default to second class.
408
+
409
+
410
+ ### Response
411
+
412
+ If the request to the client is successful, the client returns a `Notifications::Client:ResponsePrecompiledLetter` object. In the example shown in the [Method section](/ruby.html#send-a-pre-compiled-letter-method), the object is named `precompiled_letter`.
413
+
414
+ You can then call different methods on this object to return the requested information.
415
+
416
+ |Method|Information|Type|
417
+ |:---|:---|:---|
418
+ |`precompiled_letter.id`|Notification UUID|String|
419
+ |`precompiled_letter.reference`|`reference` argument|String|
420
+ |`precompiled_letter.postage`|`postage` argument|String|
421
+
422
+
423
+ ### Error codes
424
+
425
+ If the request is not successful, the client returns a `Notifications::Client::RequestError` and an error code.
426
+
427
+ |error.status_code|error.message|class|How to fix|
428
+ |:---|:---|:---|:---|
429
+ |`400`|`BadRequestError: Cannot send letters with a team api key`|`BadRequestError`|Use the correct type of [API key](#api-keys)|
430
+ |`400`|`BadRequestError: Letter content is not a valid PDF`|`BadRequestError`|PDF file format is required|
431
+ |`400`|`BadRequestError: Cannot send letters when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode`|`BadRequestError`|Your service cannot send this notification in [trial mode](https://www.notifications.service.gov.uk/features/using-notify#trial-mode)|
432
+ |`400`|`ValidationError: reference is a required property`|`BadRequestError`|Add a `reference` argument to the method call|
433
+ |`400`|`ValidationError: postage invalid. It must be either first or second.`|`BadRequestError`|Change the value of `postage` argument in the method call to either 'first' or 'second'|
434
+ |`429`|`RateLimitError: Exceeded rate limit for key type live of 10 requests per 20 seconds`|`RateLimitError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
435
+ |`429`|`TooManyRequestsError: Exceeded send limits (50) for today`|`RateLimitError`|Refer to [service limits](#service-limits) for the limit number|
436
+
437
+ # Get message status
438
+
439
+ Message status depends on the type of message you have sent.
440
+
441
+ You can only get the status of messages that are 7 days old or newer.
442
+
443
+ ## Status - text and email
444
+
445
+ |Status|Information|
446
+ |:---|:---|
447
+ |Created|GOV.UK Notify has placed the message in a queue, ready to be sent to the provider. It should only remain in this state for a few seconds.|
448
+ |Sending|GOV.UK Notify has sent the message to the provider. The provider will try to deliver the message to the recipient. GOV.UK Notify is waiting for delivery information.|
449
+ |Delivered|The message was successfully delivered.|
450
+ |Failed|This covers all failure statuses:<br>- `permanent-failure` - "The provider could not deliver the message because the email address or phone number was wrong. You should remove these email addresses or phone numbers from your database. You’ll still be charged for text messages to numbers that do not exist."<br>- `temporary-failure` - "The provider could not deliver the message after trying for 72 hours. This can happen when the recipient's inbox is full or their phone is off. You can try to send the message again. You’ll still be charged for text messages to phones that are not accepting messages."<br>- `technical-failure` - "Your message was not sent because there was a problem between Notify and the provider.<br>You’ll have to try sending your messages again. You will not be charged for text messages that are affected by a technical failure."|
451
+
452
+ ## Status - text only
453
+
454
+ |Status|Information|
455
+ |:---|:---|
456
+ |Pending|GOV.UK Notify is waiting for more delivery information.<br>GOV.UK Notify received a callback from the provider but the recipient's device has not yet responded. Another callback from the provider determines the final status of the notification.|
457
+ |Sent / Sent internationally|The message was sent to an international number. The mobile networks in some countries do not provide any more delivery information. The GOV.UK Notify client API returns this status as `sent`. The GOV.UK Notify client app returns this status as `Sent internationally`.|
458
+
459
+ ## Status - letter
460
+
461
+ |Status|information|
462
+ |:---|:---|
463
+ |Failed|The only failure status that applies to letters is `technical-failure`. GOV.UK Notify had an unexpected error while sending to our printing provider.|
464
+ |Accepted|GOV.UK Notify has sent the letter to the provider to be printed.|
465
+ |Received|The provider has printed and dispatched the letter.|
466
+
467
+ ## Status - precompiled letter
468
+
469
+ |Status|information|
470
+ |:---|:---|
471
+ |Pending virus check|GOV.UK Notify has not completed a virus scan of the precompiled letter file.|
472
+ |Virus scan failed|GOV.UK Notify found a potential virus in the precompiled letter file.|
473
+ |Validation failed|Content in the precompiled letter file is outside the printable area. See the [GOV.UK Notify PDF letter specification](https://docs.notifications.service.gov.uk/documentation/images/notify-pdf-letter-spec-v2.3.pdf) for more information.|
474
+
475
+ ## Get the status of one message
476
+
477
+ You can only get the status of messages that are 7 days old or newer.
478
+
479
+ ### Method
480
+
481
+ ```ruby
482
+ response = client.get_notification(id)
483
+ ```
484
+
485
+ ### Arguments
486
+
487
+ #### id (required)
488
+
489
+ The ID of the notification. You can find the notification ID in the response to the [original notification method call](/ruby.html#response).
490
+
491
+ You can also find it in your [GOV.UK Notify Dashboard](https://www.notifications.service.gov.uk).
492
+
493
+ 1. Sign into GOV.UK Notify and select __Dashboard__.
494
+ 1. Select either __emails sent__, __text messages sent__, or __letters sent__.
495
+ 1. Select the relevant notification.
496
+ 1. Copy the notification ID from the end of the page URL, for example `https://www.notifications.service.gov.uk/services/af90d4cb-ae88-4a7c-a197-5c30c7db423b/notification/ID`.
497
+
498
+ ### Response
499
+
500
+ If the request to the client is successful, the client returns a `Notifications::Client::Notification` object. In the example shown in the [Method section](/ruby.html#get-the-status-of-one-message-method), the object is named `response`.
501
+
502
+ You can then call different methods on this object to return the requested information.
503
+
504
+ |Method|Information|Type|
505
+ |:---|:---|:---|
506
+ |`response.id`|Notification UUID|String|
507
+ |`response.reference`| String supplied in `reference` argument|String|
508
+ |`response.email_address`|Recipient email address (email only)|String|
509
+ |`response.phone_number`|Recipient phone number (SMS only)|String|
510
+ |`response.line_1`|Recipient address line 1 of the address (letter only)|String|
511
+ |`response.line_2`|Recipient address line 2 of the address (letter only)|String|
512
+ |`response.line_3`|Recipient address line 3 of the address (letter only)|String|
513
+ |`response.line_4`|Recipient address line 4 of the address (letter only)|String|
514
+ |`response.line_5`|Recipient address line 5 of the address (letter only)|String|
515
+ |`response.line_6`|Recipient address line 6 of the address (letter only)|String|
516
+ |`response.postcode`|Recipient postcode (letter only)|String|
517
+ |`response.postage`|Postage class of the notification sent (letter only)|String|
518
+ |`response.type`|Type of notification sent (sms, email or letter)|String|
519
+ |`response.status`|Notification status (sending / delivered / permanent-failure / temporary-failure / technical-failure)|String|
520
+ |`response.template`|Template UUID|String|
521
+ |`response.body`|Notification body|String|
522
+ |`response.subject`|Notification subject (email and letter)|String|
523
+ |`response.sent_at`|Date and time notification sent to provider|String|
524
+ |`response.created_at`|Date and time notification created|String|
525
+ |`response.completed_at`|Date and time notification delivered or failed|String|
526
+ |`response.created_by_name`|Name of sender if notification sent manually|String|
527
+
528
+ ### Error codes
529
+
530
+ If the request is not successful, the client returns a `Notification::Client::RequestError` and an error code:
531
+
532
+ |error.code|error.message|class|How to fix|
533
+ |:---|:---|:---|:---|
534
+ |`400`|`ValidationError: id is not a valid UUID`|`BadRequestError`|Check the notification ID|
535
+ |`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
536
+ |`403`|`AuthError: Invalid token: signature, api token not found`|`AuthError`|Use the correct API key. Refer to [API keys](/ruby.html#api-keys) for more information|
537
+ |`404`|`NoResultFound: No result found`|`NotFoundError`|Check the notification ID. This error occurs if the notification is more than 7 days old.|
538
+
539
+ ## Get the status of multiple messages
540
+
541
+ This API call returns one page of up to 250 messages and statuses. You can get either the most recent messages, or get older messages by specifying a particular notification ID in the `older_than` argument.
542
+
543
+ You can only get messages that are 7 days old or newer.
544
+
545
+ ### Method
546
+
547
+ ```ruby
548
+ args = {
549
+ template_type: 'sms',
550
+ status: 'failed',
551
+ reference: 'your_reference_string'
552
+ older_than: 'e194efd1-c34d-49c9-9915-e4267e01e92e'
553
+ }
554
+ response = client.get_notifications(args)
555
+ ```
556
+
557
+ You can leave out the `older_than` argument to get the 250 most recent messages.
558
+
559
+ To get older messages, pass the ID of an older notification into the `older_than` argument. This returns the next 250 oldest messages from the specified notification ID.
560
+
561
+ ### Arguments
562
+
563
+ You can leave out these arguments to ignore these filters.
564
+
565
+ #### status (optional)
566
+
567
+ | status | description | text | email | letter |Precompiled letter|
568
+ |:--- |:--- |:--- |:--- |:--- |:--- |
569
+ |created|GOV.UK Notify has placed the message in a queue, ready to be sent to the provider. It should only remain in this state for a few seconds.|Yes|Yes|||
570
+ |sending|GOV.UK Notify has sent the message to the provider. The provider will try to deliver the message to the recipient. GOV.UK Notify is waiting for delivery information.|Yes|Yes|||
571
+ |delivered|The message was successfully delivered|Yes|Yes|||
572
+ |sent / sent internationally|The message was sent to an international number. The mobile networks in some countries do not provide any more delivery information.|Yes||||
573
+ |pending|GOV.UK Notify is waiting for more delivery information.<br>GOV.UK Notify received a callback from the provider but the recipient's device has not yet responded. Another callback from the provider determines the final status of the notification.|Yes||||
574
+ |failed|This returns all failure statuses:<br>- permanent-failure<br>- temporary-failure<br>- technical-failure|Yes|Yes|||
575
+ |permanent-failure|The provider could not deliver the message because the email address or phone number was wrong. You should remove these email addresses or phone numbers from your database. You’ll still be charged for text messages to numbers that do not exist.|Yes|Yes|||
576
+ |temporary-failure|The provider could not deliver the message after trying for 72 hours. This can happen when the recipient's inbox is full or their phone is off. You can try to send the message again. You’ll still be charged for text messages to phones that are not accepting messages.|Yes|Yes|||
577
+ |technical-failure|Email / Text: Your message was not sent because there was a problem between Notify and the provider.<br>You’ll have to try sending your messages again. You will not be charged for text messages that are affected by a technical failure. <br><br>Letter: Notify had an unexpected error while sending to our printing provider. <br><br>You can leave out this argument to ignore this filter.|Yes|Yes|||
578
+ |accepted|GOV.UK Notify has sent the letter to the provider to be printed.|||Yes||
579
+ |received|The provider has printed and dispatched the letter.|||Yes||
580
+ |pending-virus-check|GOV.UK Notify is scanning the precompiled letter file for viruses.||||Yes|
581
+ |virus-scan-failed|GOV.UK Notify found a potential virus in the precompiled letter file.||||Yes|
582
+ |validation-failed|Content in the precompiled letter file is outside the printable area.||||Yes|
583
+
584
+ #### templateType (optional)
585
+
586
+ You can filter by:
587
+
588
+ * `email`
589
+ * `sms`
590
+ * `letter`
591
+
592
+ #### reference (optional)
593
+
594
+ A unique identifier you can create if necessary. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. For example:
595
+
596
+ ```ruby
597
+ reference: 'your_reference_string'
598
+ ```
599
+
600
+ #### older_than (optional)
601
+
602
+ Input the ID of a notification into this argument. If you use this argument, the client returns the next 250 received notifications older than the given ID. For example:
603
+
604
+ ```ruby
605
+ older_than: 'e194efd1-c34d-49c9-9915-e4267e01e92e'
606
+ ```
607
+
608
+ If you leave out this argument, the client returns the most recent 250 notifications.
609
+
610
+ The client only returns notifications that are 7 days old or newer. If the notification specified in this argument is older than 7 days, the client returns an empty response.
611
+
612
+ ### Response
613
+
614
+ If the request to the client is successful, the client returns a `Notifications::Client::NotificationsCollection` object. In the example shown in the [Method section](/ruby.html#get-the-status-of-multiple-messages-method), the object is named `response`.
615
+
616
+ You must then call either the `.links` method or the `.collection` method on this object.
617
+
618
+ |Method|Information|
619
+ |:---|:---|
620
+ |`response.links`|Returns a hash linking to the requested notifications (limited to 250)|
621
+ |`response.collection`|Returns an array of the required notifications|
622
+
623
+ If you call the `collection` method on this object to return a notification array, you must then call the following methods on the notifications in this array to return information on those notifications:
624
+
625
+ |Method|Information|Type|
626
+ |:---|:---|:---|
627
+ |`response.id`|Notification UUID|String|
628
+ |`response.reference`| String supplied in `reference` argument|String|
629
+ |`response.email_address`|Recipient email address (email only)|String|
630
+ |`response.phone_number`|Recipient phone number (SMS only)|String|
631
+ |`response.line_1`|Recipient address line 1 of the address (letter only)|String|
632
+ |`response.line_2`|Recipient address line 2 of the address (letter only)|String|
633
+ |`response.line_3`|Recipient address line 3 of the address (letter only)|String|
634
+ |`response.line_4`|Recipient address line 4 of the address (letter only)|String|
635
+ |`response.line_5`|Recipient address line 5 of the address (letter only)|String|
636
+ |`response.line_6`|Recipient address line 6 of the address (letter only)|String|
637
+ |`response.postcode`|Recipient postcode (letter only)|String|
638
+ |`response.type`|Type of notification sent (sms, email or letter)|String|
639
+ |`response.status`|Notification status (sending / delivered / permanent-failure / temporary-failure / technical-failure)|String|
640
+ |`response.template`|Template UUID|String|
641
+ |`response.body`|Notification body|String|
642
+ |`response.subject`|Notification subject (email and letter)|String|
643
+ |`response.sent_at`|Date and time notification sent to provider|String|
644
+ |`response.created_at`|Date and time notification created|String|
645
+ |`response.completed_at`|Date and time notification delivered or failed|String|
646
+ |`response.created_by_name`|Name of sender if notification sent manually|String|
647
+
648
+ If the notification specified in the `older_than` argument is older than 7 days, the client returns an empty `collection` response.
649
+
650
+ ### Error codes
651
+
652
+ If the request is not successful, the client returns a `Notifications::Client::RequestError` and an error code.
653
+
654
+ |error.code|error.message|class|How to fix|
655
+ |:---|:---|:---|:---|
656
+ |`400`|`ValidationError: bad status is not one of [created, sending, sent, delivered, pending, failed, technical-failure, temporary-failure, permanent-failure, accepted, received]`|`BadRequestError`|Contact the GOV.UK Notify team|
657
+ |`400`|`ValidationError: Template type is not one of [sms, email, letter]`|`BadRequestError`|Contact the GOV.UK Notify team|
658
+ |`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
659
+ |`403`|`AuthError: Invalid token: signature, api token not found`|`AuthError`|Use the correct API key. Refer to [API keys](/ruby.html#api-keys) for more information|
660
+
661
+ # Get a template
662
+
663
+ ## Get a template by ID
664
+
665
+ ### Method
666
+
667
+ This returns the latest version of the template.
668
+
669
+ ```ruby
670
+ response = client.get_template_by_id(id)
671
+ ```
672
+
673
+ ### Arguments
674
+
675
+ #### id (required)
676
+
677
+ The ID of the template. Sign into GOV.UK Notify and go to the __Templates__ page to find this. For example:
678
+
679
+ ```
680
+ 'f33517ff-2a88-4f6e-b855-c550268ce08a'
681
+ ```
682
+
683
+ ### Response
684
+
685
+ If the request to the client is successful, the client returns a `Notifications::Client::Template` object. In the example shown in the [Method section](/ruby.html#get-a-template-by-id-method), the object is named `response`.
686
+
687
+ You can then call different methods on this object to return the requested information.
688
+
689
+ |Method|Information|Type|
690
+ |:---|:---|:---|
691
+ |`response.id`|Template UUID|String|
692
+ |`response.name`|Template name|String|
693
+ |`response.type`|Template type (email/sms/letter)|String|
694
+ |`response.created_at`|Date and time template created|String|
695
+ |`response.updated_at`|Date and time template last updated (may be nil if version 1)|String|
696
+ |`response.created_by`|Email address of person that created the template|String|
697
+ |`response.version`|Template version|String|
698
+ |`response.body`|Template content|String|
699
+ |`response.subject`|Template subject (email and letter)|String|
700
+
701
+ ### Error codes
702
+
703
+ If the request is not successful, the client returns a `Notifications::Client::RequestError` and an error code:
704
+
705
+ |error.code|error.message|class|How to fix|
706
+ |:---|:---|:---|:---|
707
+ |`400`|`ValidationError: id is not a valid UUID`|`BadRequestError`|Check the notification ID|
708
+ |`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
709
+ |`403`|`AuthError: Invalid token: signature, api token not found`|`AuthError`|Use the correct API key. Refer to [API keys](/ruby.html#api-keys) for more information|
710
+ |`404`|`NoResultFound: No Result Found`|`NotFoundError`|Check your [template ID](/ruby.html#get-a-template-by-id-arguments-id-required)|
711
+
712
+ ## Get a template by ID and version
713
+
714
+ ### Method
715
+
716
+ ```ruby
717
+ response = client.get_template_version(id, version)
718
+ ```
719
+
720
+ ### Arguments
721
+
722
+ #### id (required)
723
+
724
+ The ID of the template. Sign in to GOV.UK Notify and go to the __Templates__ page to find this. For example:
725
+
726
+ ```ruby
727
+ 'f33517ff-2a88-4f6e-b855-c550268ce08a'
728
+ ```
729
+
730
+ #### version (required)
731
+
732
+ The version number of the template.
733
+
734
+ ### Response
735
+
736
+ If the request to the client is successful, the client returns a `Notifications::Client::Template` object. In the example shown in the [Method section](/ruby.html#get-a-template-by-id-and-version-method), the object is named `response`.
737
+
738
+ You can then call different methods on this object to return the requested information.
739
+
740
+ |Method|Information|Type|
741
+ |:---|:---|:---|
742
+ |`response.id`|Template UUID|String|
743
+ |`response.name`|Template name|String|
744
+ |`response.type`|Template type (email/sms/letter)|String|
745
+ |`response.created_at`|Date and time template created|String|
746
+ |`response.updated_at`|Date and time template last updated (may be nil if it is the first version)|String|
747
+ |`response.created_by`|Email address of person that created the template|String|
748
+ |`response.version`|Template version|String|
749
+ |`response.body`|Template content|String|
750
+ |`response.subject`|Template subject (email and letter)|String|
751
+
752
+ ### Error codes
753
+
754
+ If the request is not successful, the client returns a `Notifications::Client::RequestError` and an error code:
755
+
756
+ |error.code|error.message|class|How to fix|
757
+ |:---|:---|:---|:---|
758
+ |`400`|`ValidationError: id is not a valid UUID`|`BadRequestError`|Check the notification ID|
759
+ |`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
760
+ |`403`|`AuthError: Invalid token: signature, api token not found`|`AuthError`|Use the correct API key. Refer to [API keys](/ruby.html#api-keys) for more information|
761
+ |`404`|`NoResultFound: No Result Found`|`NotFoundError`|Check your [template ID](/ruby.html#get-a-template-by-id-and-version-arguments-id-required) and [version](/ruby.html#version-required)|
762
+
763
+ ## Get all templates
764
+
765
+ ### Method
766
+
767
+ This returns the latest version of all templates inside a collection object.
768
+
769
+ ```ruby
770
+ args = {
771
+ type: 'sms'
772
+ }
773
+ response = client.get_all_templates(args)
774
+ ```
775
+
776
+ ### Arguments
777
+
778
+ #### type (optional)
779
+
780
+ If you do not use `type`, the client returns all templates. Otherwise you can filter by:
781
+
782
+ - `email`
783
+ - `sms`
784
+ - `letter`
785
+
786
+ ### Response
787
+
788
+ If the request to the client is successful, the client returns a `Notifications::Client::TemplateCollection` object. In the example shown in the [Method section](/ruby.html#get-all-templates-method), the object is named `response`.
789
+
790
+ You must then call the `.collection` method on this object to return an array of the required templates.
791
+
792
+ Once the client has returned a template array, you must then call the following methods on the templates in this array to return information on those templates.
793
+
794
+ |Method|Information|Type|
795
+ |:---|:---|:---|
796
+ |`response.id`|Template UUID|String|
797
+ |`response.name`|Template name|String|
798
+ |`response.type`|Template type (email/sms/letter)|String|
799
+ |`response.created_at`|Date and time template created|String|
800
+ |`response.updated_at`|Date and time template last updated (may be nil if it is the first version)|String|
801
+ |`response.created_by`|Email address of person that created the template|String|
802
+ |`response.version`|Template version|String|
803
+ |`response.body`|Template content|String|
804
+ |`response.subject`|Template subject (email and letter)|String|
805
+
806
+ If no templates exist for a template type or there no templates for a service, the templates array will be empty.
807
+
808
+ ### Error codes
809
+
810
+ If the request is not successful, the client returns a `Notifications::Client::RequestError` and an error code:
811
+
812
+ |error.code|error.message|class|How to fix|
813
+ |:---|:---|:---|:---|
814
+ |`400`|`ValidationError: Template type is not one of [sms, email, letter]`|`BadRequestError`|Contact the Notify team|
815
+
816
+ ## Generate a preview template
817
+
818
+ ### Method
819
+
820
+ This generates a preview version of a template.
821
+
822
+ ```ruby
823
+ response = client.generate_template_preview(id)
824
+ ```
825
+
826
+ The parameters in the personalisation argument must match the placeholder fields in the actual template. The API notification client ignores any extra fields in the method.
827
+
828
+ ### Arguments
829
+
830
+ #### id (required)
831
+
832
+ The ID of the template. Sign into GOV.UK Notify and go to the __Templates__ page. For example:
833
+
834
+ ```ruby
835
+ 'f33517ff-2a88-4f6e-b855-c550268ce08a'
836
+ ```
837
+
838
+ #### personalisation (optional)
839
+
840
+ If a template has placeholder fields for personalised information such as name or application date, you must provide their values in a hash. For example:
841
+
842
+ ```ruby
843
+ personalisation: {
844
+ name: "John Smith",
845
+ ID: "300241",
846
+ }
847
+ ```
848
+
849
+ You can leave out this argument if a template does not have any placeholder fields for personalised information.
850
+
851
+ ### Response
852
+
853
+ If the request to the client is successful, the client returns a `Notifications::Client::TemplatePreview` object. In the example shown in the [Method section](/ruby.html#generate-a-preview-template-method), the object is named `response`.
854
+
855
+ You can then call different methods on this object to return the requested information.
856
+
857
+ |Method|Information|Type|
858
+ |:---|:---|:---|
859
+ |`response.id`|Template UUID|String|
860
+ |`response.version`|Template version|String|
861
+ |`response.body`|Template content|String|
862
+ |`response.subject`|Template subject (email and letter)|String|
863
+ |`response.type`|Template type (sms/email/letter)|String|
864
+ |`response.html`|Body as rendered HTML (email only)|String|
865
+
866
+ ### Error codes
867
+
868
+ If the request is not successful, the client returns a `Notifications::Client::RequestError` and an error code:
869
+
870
+ |error.code|error.message|class|How to fix|
871
+ |:---|:---|:---|:---|
872
+ |`400`|`BadRequestError: Missing personalisation: [PERSONALISATION FIELD]`|`BadRequestError`|Check that the personalisation arguments in the method match the placeholder fields in the template|
873
+ |`400`|`NoResultFound: No result found`|`BadRequestError`|Check the [template ID](/ruby.html#generate-a-preview-template-arguments-id-required)|
874
+ |`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
875
+ |`403`|`AuthError: Invalid token: signature, api token not found`|`AuthError`|Use the correct API key. Refer to [API keys](/ruby.html#api-keys) for more information|
876
+
877
+ # Get received text messages
878
+
879
+ This API call returns one page of up to 250 received text messages. You can get either the most recent messages, or get older messages by specifying a particular notification ID in the `older_than` argument.
880
+
881
+ You can only get the status of messages that are 7 days old or newer.
882
+
883
+ You can also set up [callbacks](/ruby.html#callbacks) for received text messages.
884
+
885
+ ## Enable received text messages
886
+
887
+ Contact the GOV.UK Notify team on the [support page](https://www.notifications.service.gov.uk/support) or through the [Slack channel](https://ukgovernmentdigital.slack.com/messages/govuk-notify) to enable receiving text messages for your service.
888
+
889
+ ## Get a page of received text messages
890
+
891
+ ### Method
892
+
893
+ ```ruby
894
+ args = {
895
+ older_than: 'e194efd1-c34d-49c9-9915-e4267e01e92e'
896
+ }
897
+ response = client.get_received_texts(args)
898
+ ```
899
+
900
+ To get older messages, pass the ID of an older notification into the `older_than` argument. This returns the next oldest messages from the specified notification ID.
901
+
902
+ If you leave out the `older_than` argument, the client returns the most recent 250 notifications.
903
+
904
+ ### Arguments
905
+
906
+ #### older_than (optional)
907
+
908
+ Input the ID of a received text message into this argument. If you use this argument, the client returns the next 250 received text messages older than the given ID. For example:
909
+
910
+ ```ruby
911
+ older_than: '8e222534-7f05-4972-86e3-17c5d9f894e2'
912
+ ```
913
+
914
+ If you leave out the `older_than` argument, the client returns the most recent 250 notifications.
915
+
916
+ The client only returns notifications that are 7 days old or newer. If the notification specified in this argument is older than 7 days, the client returns an empty `collection` response.
917
+
918
+ ### Response
919
+
920
+ If the request to the client is successful, the client returns a `Notifications::Client::ReceivedTextCollection` object. In the example shown in the [Method section](/ruby.html#get-received-text-messages-method), the object is named `response`.
921
+
922
+ You must then call either the `.links` method or the `.collection` method on this object.
923
+
924
+ |Method|Information|
925
+ |:---|:---|
926
+ |`response.links`|Returns a hash linking to the requested texts (limited to 250)|
927
+ |`response.collection`|Returns an array of the required texts|
928
+
929
+ If you call the `collection` method on this object to return an array, you must then call the following methods on the received texts in this array to return information on those texts:
930
+
931
+ |Method|Information|Type|
932
+ |:---|:---|:---|
933
+ |`response.id`|Received text UUID|String|
934
+ |`response.created_at`|Date and time of received text|String|
935
+ |`response.content`|Received text content|String|
936
+ |`response.notify_number`|Number that received text was sent to|String|
937
+ |`response.service_id`|Received text service ID|String|
938
+ |`response.user_number`|Number that received text was sent from|String|
939
+
940
+ If the notification specified in the `older_than` argument is older than 7 days, the client returns an empty `collection` response.
941
+
942
+ ### Error codes
943
+
944
+ If the request is not successful, the client returns a `Notifications::Client::RequestError` and an error code.
945
+
946
+ |error.code|error.message|class|How to fix|
947
+ |:---|:---|:---|:---|
948
+ |`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
949
+ |`403`|`AuthError: Invalid token: signature, api token not found`|`AuthError`|Use the correct API key. Refer to [API keys](/ruby.html#api-keys) for more information|