GOV.UK Notify Node.js client
Use this client to send emails, text messages and letters using the GOV.UK Notify API.
Useful links:
GOV.UK Notify Node.js client
Use this client to send emails, text messages and letters using the GOV.UK Notify API.
Useful links:
setClient
.sendEmail
function can now be passed oneClickUnsubscribeURL
as an optional argument.is_csv
boolean parameter from prepareUpload
. This method now accepts a file and an options map with the following options. For more specific information please read the documentation.filename
(string) - specify the document's filename upon downloadconfirm_email_before_download
(boolean) - require the user to enter their email address before the file can be downloaded.retention_period
(string) - how long Notify should make the file available to the user for.protocol
property when constructing your proxyConfig
object, if using a proxy.confirmEmailBeforeDownload
, which coalesced false to null.prepareUpload
. fs.readFile
can return strings if an encoding is provided, and the client didn't handle these correctly.Add support for new security features when sending a file by email:
confirmEmailBeforeDownload
can be set to true
to require the user to enter their email address before accessing the file.retentionPeriod
can be set to <1-78> weeks
to set how long the file should be made available.The isCsv
parameter to prepareUpload
has now been replaced by an options
parameter. The implementation has been done in a backwards-compatible way, so if you are just sending true/false
values as the seecond parameter, that will continue to work. Though we still recommend updating to use the new options format.
Remove underscore.js dependencyr new send a file features)
Upgrade axios version from ^0.21.1 to ^0.25.0
Correct incorrect description of parameter to be used by NotifyClient.setProxy
Remove unintentional global nature of variable version
We have replaced the use of the npm request-promise package with axios as the npm request package has been deprecated. This makes the following breaking changes:
The response
object
returned by a successful API call is now in the form of an axios response. This has a different interface to a request response. For example:
response.body
becomes response.data
response.statusCode
becomes response.status
The err
object
returned by an unsuccessful API call has a different interface. For example, err.error
becomes err.response.data
. See the axios documentation for further details on error handling.
To configure the use of a proxy you should pass the proxy configuration as an object
rather than a URL. For details, see the axios client.
We now return native promises rather than bluebird promises. You will not need to make any changes unless you are using some of the additional methods found on bluebird promises that do not exist on native promises.
letter_contact_block
to the responses for getTemplateById
, getTemplateByIdAndVersion
and getAllTemplates
.isCsv
parameter in the prepareUpload
function. This fixes a bug when sending a CSV file by email. This ensures that the file is downloaded as a CSV rather than a TXT file.__dirname
global call from api clientnotifyClient.getPdfForLetterNotification(notificationId)
sendPrecompiledLetter
prepareUpload
as a part of this development. This function encodes the document that is to be uploaded with base64 and returns a dictionary with prepared document as a value (the way our API is prepared to receive it). It also checks if the provided file is not larger than 2MB. The function throws an error if the file is too big.name
to the response for getTemplateById()
and getTemplateByIdAndVersion()
created_by_name
to the response for .getNotificationById()
and .getNotifications()
:null
.getReceivedTexts
- get one page of text messages (250) per callsendSms
, sendEmail
and sendLetter
to take an options
object as a parameter.personalisation
, reference
, smsSenderId
and emailReplyToId
now need to be passed to these functions inside options
.Crypto
dependencysendSms
method with optional argument:smsSenderId
- specify the identifier of the sms sender (optional)sendLetter
- send a lettersendEmail
method with optional argument:emailReplyToId
- specify the identifier of the email reply-to address (optional)setProxy(proxyUrl)
- specify the URL of a proxy for the client to use (optional)Added new methods for managing templates:
getTemplateById
- retrieve a single templategetTemplateByIdAndVersion
- retrieve a specific version for a desired templategetAllTemplates
- retrieve all templates (can filter by type)previewTemplateById
- preview a template with personalisation appliedUpdate README to describe how to catch errors
Using v2 of the notification-api.
Update to notifyClient.sendSms()
:
reference
: an optional identifier you generate if you don’t want to use Notify’s id
. It can be used to identify a single notification or a batch of notifications.notifyClient.sendSms(templateId, phoneNumber, personalisation, reference);
personalisation
and reference
can be undefined
.Update to notifyClient.sendEmail()
:
reference
: an optional identifier you generate if you don’t want to use Notify’s id
. It can be used to identify a single notification or a batch of notifications.notifyClient.sendEmail(templateId, emailAddress, personalisation, reference);
personalisation
and reference
can be undefined
.NotificationClient.getAllNotifications()
reference
and olderThanId
, see the README for details.notifyClient.getNotifications(templateType, status, reference, olderThanId);
undefined
Changelog not recorded - please see pull requests on github.