Skip to content

Commit

Permalink
Add status callback options to send calls
Browse files Browse the repository at this point in the history
  • Loading branch information
acodegirl authored Apr 7, 2020
1 parent f9e286a commit ed8c918
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [5.1.0] - 2020-04-07

### Changed

- Added delivery status callback options to sendEmail and sendSms calls

## [5.0.3] - 2019-12-19

### Changed
Expand Down
1 change: 0 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export API_SENDING_KEY="API_whitelist_key for sending a SMS to a receiving numbe
export INBOUND_SMS_QUERY_KEY="API_test_key to get received text messages - leave blank for local development as cannot test locally"
```


To run the integration tests:

`make integration-test`
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ If you omit this argument your default sms sender will be set for the notificati

Example usage with optional reference -

##### `statusCallbackUrl`

Optional. Specifies the identifier of the HTTPS URL for delivery status updates to be sent to.

##### `statusCallbackBearerToken`

Optional. Specifies the identifier of the Bearer token that will be used for authentication to the delivery status callback URL. This must be provided if the status callback URL is provided.

</details>

### Email
Expand Down Expand Up @@ -257,6 +265,14 @@ personalisation = {
Optional. Specifies the identifier of the email reply-to address to set for the notification. The identifiers are found in your service Settings, when you 'Manage' your 'Email reply to addresses'.
If you omit this argument your default email reply-to address will be set for the notification.

##### `statusCallbackUrl`

Optional. Specifies the identifier of the HTTPS URL for delivery status updates to be sent to.

##### `statusCallbackBearerToken`

Optional. Specifies the identifier of the Bearer token that will be used for authentication to the delivery status callback URL. This must be provided if the status callback URL is provided.

</details>

### Send a document by email
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@govau-platforms/notify-client",
"author": "Digital Transformation Agency",
"version": "5.0.3",
"version": "5.1.0",
"homepage": "https://github.com/govau/notify-client-node",
"description": "Notify.gov.au Node.js client ",
"license": "MIT",
Expand Down
54 changes: 54 additions & 0 deletions spec/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,33 @@ describe("notification api", () => {
});
});

it("should send an email with status callback url and bearer token", () => {
let email = "[email protected]",
templateId = "123",
options = {
personalisation: { foo: "bar" },
statusCallbackUrl: "https://localhost/callback",
statusCallbackBearerToken: "1234567890"
},
data = {
template_id: templateId,
email_address: email,
personalisation: options.personalisation,
status_callback_url: options.statusCallbackUrl,
status_callback_bearer_token: options.statusCallbackBearerToken
};

notifyAuthNock
.post("/v2/notifications/email", data)
.reply(200, { hooray: "bkbbk" });

return notifyClient
.sendEmail(templateId, email, options)
.then(response => {
expect(response.statusCode).to.equal(200);
});
});

it("should reject options dicts with unknown options", () => {
let email = "[email protected]",
templateId = "123",
Expand Down Expand Up @@ -154,6 +181,33 @@ describe("notification api", () => {
});
});

it("should send an sms with status callback url and bearer token", () => {
let phoneNo = "07525755555",
templateId = "123",
options = {
personalisation: { foo: "bar" },
statusCallbackUrl: "https://localhost/callback",
statusCallbackBearerToken: "1234567890"
},
data = {
template_id: templateId,
phone_number: phoneNo,
personalisation: options.personalisation,
status_callback_url: options.statusCallbackUrl,
status_callback_bearer_token: options.statusCallbackBearerToken
};

notifyAuthNock
.post("/v2/notifications/sms", data)
.reply(200, { hooray: "bkbbk" });

return notifyClient
.sendSms(templateId, phoneNo, options)
.then(function(response) {
expect(response.statusCode).to.equal(200);
});
});

it("should reject options dicts with unknown options", () => {
let phoneNumber = "07123456789",
templateId = "123",
Expand Down
51 changes: 50 additions & 1 deletion spec/integration/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ describer("notification api with a live service", function() {
let smsNotificationId;
const personalisation = { name: "Foo" };
const clientRef = "client-ref";
const statusCallbackUrl = "https://localhost/callback";
const statusCallbackBearerToken = "1234567890";
const email = process.env.FUNCTIONAL_TEST_EMAIL;
const phoneNumber = process.env.FUNCTIONAL_TEST_NUMBER;
const smsTemplateId = process.env.SMS_TEMPLATE_ID;
Expand Down Expand Up @@ -98,9 +100,38 @@ describer("notification api with a live service", function() {
});
});

it("send email notification with status callback URL and bearer token", () => {
const postEmailNotificationResponseJson = require("./schemas/v2/POST_notification_email_response.json");
const options = {
personalisation: personalisation,
reference: clientRef,
statusCallbackUrl: statusCallbackUrl,
statusCallbackBearerToken: statusCallbackBearerToken
};

return notifyClient
.sendEmail(emailTemplateId, email, options)
.then(response => {
response.statusCode.should.equal(201);
expect(response.body).to.be.jsonSchema(
postEmailNotificationResponseJson
);
response.body.content.body.should.equal(
"Hello Foo\n\nFunctional test help make our world a better place\n"
);
response.body.content.subject.should.equal("NodeJS integration test");
response.body.reference.should.equal(clientRef);
emailNotificationId = response.body.id;
});
});

it("send sms notification", () => {
var postSmsNotificationResponseJson = require("./schemas/v2/POST_notification_sms_response.json"),
options = { personalisation: personalisation };
options = {
personalisation: personalisation,
statusCallbackUrl: statusCallbackUrl,
statusCallbackBearerToken: statusCallbackBearerToken
};

return notifyClient
.sendSms(smsTemplateId, phoneNumber, options)
Expand Down Expand Up @@ -139,6 +170,24 @@ describer("notification api with a live service", function() {
});
});

it("send sms notification with status callback URL and bearer token", () => {
var postSmsNotificationResponseJson = require("./schemas/v2/POST_notification_sms_response.json"),
options = { personalisation: personalisation };

return notifyClient
.sendSms(smsTemplateId, phoneNumber, options)
.then(response => {
response.statusCode.should.equal(201);
expect(response.body).to.be.jsonSchema(
postSmsNotificationResponseJson
);
response.body.content.body.should.equal(
"Hello Foo\n\nFunctional Tests make our world a better place"
);
smsNotificationId = response.body.id;
});
});

const getNotificationJson = require("./schemas/v2/GET_notification_response.json");
const getNotificationsJson = require("./schemas/v2/GET_notifications_response.json");

Expand Down
45 changes: 40 additions & 5 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,25 @@ export default class Client {
): any {
options = options || {};
const err = checkOptionsKeys(
["personalisation", "reference", "emailReplyToId"],
[
"personalisation",
"reference",
"emailReplyToId",
"statusCallbackUrl",
"statusCallbackBearerToken"
],
options
);
if (err) {
return Promise.reject(err);
}

const personalisation = options.personalisation || undefined;
const reference = options.reference || undefined;
const emailReplyToId = options.emailReplyToId || undefined;
const statusCallbackUrl = options.statusCallbackUrl || undefined;
const statusCallbackBearerToken =
options.statusCallbackBearerToken || undefined;

return this.httpClient.post(
"/v2/notifications/email",
Expand All @@ -33,15 +43,23 @@ export default class Client {
emailAddress,
personalisation,
reference,
emailReplyToId
emailReplyToId,
statusCallbackUrl,
statusCallbackBearerToken
)
);
}

public sendSms(templateId: string, phoneNumber: string, options?: any): any {
options = options || {};
const err = checkOptionsKeys(
["personalisation", "reference", "smsSenderId"],
[
"personalisation",
"reference",
"smsSenderId",
"statusCallbackUrl",
"statusCallbackBearerToken"
],
options
);
if (err) {
Expand All @@ -51,6 +69,9 @@ export default class Client {
const personalisation = options.personalisation || undefined;
const reference = options.reference || undefined;
const smsSenderId = options.smsSenderId || undefined;
const statusCallbackUrl = options.statusCallbackUrl || undefined;
const statusCallbackBearerToken =
options.statusCallbackBearerToken || undefined;

return this.httpClient.post(
"/v2/notifications/sms",
Expand All @@ -60,7 +81,9 @@ export default class Client {
phoneNumber,
personalisation,
reference,
smsSenderId
smsSenderId,
statusCallbackUrl,
statusCallbackBearerToken
)
);
}
Expand Down Expand Up @@ -142,7 +165,9 @@ const createPayload = (
to: string,
personalisation?: object,
reference?: string,
replyToId?: string
replyToId?: string,
statusCallbackUrl?: string,
statusCallbackBearerToken?: string
) => {
const payload: {
template_id: string;
Expand All @@ -152,6 +177,8 @@ const createPayload = (
reference?: string;
email_reply_to_id?: string;
sms_sender_id?: string;
status_callback_url?: string;
status_callback_bearer_token?: string;
} = { template_id: templateId };

if (type == "email") {
Expand All @@ -174,6 +201,14 @@ const createPayload = (
payload.sms_sender_id = replyToId;
}

if (statusCallbackUrl) {
payload.status_callback_url = statusCallbackUrl;
}

if (statusCallbackBearerToken) {
payload.status_callback_bearer_token = statusCallbackBearerToken;
}

return payload;
};

Expand Down

0 comments on commit ed8c918

Please sign in to comment.