Skip to content

Commit

Permalink
DEVEXP-588: Add send batch with multiple parameters (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
asein-sinch authored Oct 1, 2024
1 parent a7367fe commit 412e534
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 37 deletions.
7 changes: 7 additions & 0 deletions packages/sms/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
- [Bugfix] In the interface `UpdateGroupRequest`, the property `name` can also be set to null to remove an existing name set.
- [Deprecation Notice] All variations of a group response (`GroupResponse`, `CreateGroupResponse`, `ReplaceGroupResponse` and `UpdateGroupResponse`) are deprecated and replaced by the unique interface `Group`.
- [Deprecation Notice] In the interface `GetDeliveryReportByPhoneNumberRequestData`, the request parameter `recipient_msisdn` is deprecated and should be replaced by `phone_number`.
- [Deprecation Notice] The "parameters" related interfaces have been updated and the interface `ParameterGroup`uses an index signature to allow for arbitrary keys instead of extending a `Record<string, any>`:

| Deprecated | New |
|--------------------------|-----------------|
| ParameterObj | ParameterGroup |
| ParameterObjParameterKey | ParameterValues |

- [E2E] Add Cucumber steps implementation.

## Version 1.1.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MediaBody } from '../media-body';
import { ParameterObj } from '../parameter-obj';
import { ParameterGroup } from '../parameter-group';
import { DeliveryReportEnum } from '../enums';

export interface ApiUpdateMmsMtMessage {
Expand All @@ -22,8 +22,8 @@ export interface ApiUpdateMmsMtMessage {
callback_url?: string;
/** @see MediaBody */
body?: MediaBody;
/** @see ParameterObj */
parameters?: ParameterObj;
/** @see ParameterGroup */
parameters?: ParameterGroup;
/** Whether or not you want the media included in your message to be checked against [Sinch MMS channel best practices](/docs/mms/bestpractices/). If set to true, your message will be rejected if it doesn\'t conform to the listed recommendations, otherwise no validation will be performed. */
strict_validation?: boolean;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ParameterObj } from '../parameter-obj';
import { ParameterGroup } from '../parameter-group';
import { DeliveryReportEnum } from '../enums';

export interface ApiUpdateTextMtMessage {
Expand All @@ -19,8 +19,8 @@ export interface ApiUpdateTextMtMessage {
expire_at?: Date;
/** Override the default callback URL for this batch. Constraints: Must be valid URL. */
callback_url?: string;
/** @see ParameterObj */
parameters?: ParameterObj;
/** @see ParameterGroup */
parameters?: ParameterGroup;
/** The message content */
body?: string;
}
4 changes: 2 additions & 2 deletions packages/sms/src/models/v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export * from './media-body';
export * from './media-request';
export * from './media-response';
export * from './message-delivery-status';
export * from './parameter-obj';
export * from './parameter-obj-parameter-key';
export * from './parameter-group';
export * from './parameter-values';
export * from './recipient-delivery-report';
export * from './replace-group-request';
export * from './send-sms-response';
Expand Down
6 changes: 3 additions & 3 deletions packages/sms/src/models/v1/media-request/media-request.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MediaBody } from '../media-body';
import { ParameterObj } from '../parameter-obj';
import { ParameterGroup } from '../parameter-group';
import { DeliveryReportEnum } from '../enums';

/**
Expand All @@ -12,8 +12,8 @@ export interface MediaRequest {
from?: string;
/** @see MediaBody */
body: MediaBody;
/** @see ParameterObj */
parameters?: ParameterObj;
/** @see ParameterGroup */
parameters?: ParameterGroup;
/** MMS */
type?: 'mt_media';
/** Request delivery report callback. Note that delivery reports can be fetched from the API regardless of this setting. */
Expand Down
6 changes: 3 additions & 3 deletions packages/sms/src/models/v1/media-response/media-response.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MediaBody } from '../media-body';
import { ParameterObj } from '../parameter-obj';
import { ParameterGroup } from '../parameter-group';
import { DeliveryReportEnum } from '../enums';

export interface MediaResponse {
Expand All @@ -13,8 +13,8 @@ export interface MediaResponse {
canceled?: boolean;
/** @see MediaBody */
body?: MediaBody;
/** @see ParameterObj */
parameters?: ParameterObj;
/** @see ParameterGroup */
parameters?: ParameterGroup;
/** Media message */
type?: 'mt_media';
/** Timestamp for when batch was created. YYYY-MM-DDThh:mm:ss.SSSZ format */
Expand Down
1 change: 1 addition & 0 deletions packages/sms/src/models/v1/parameter-group/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { ParameterObj, ParameterGroup } from './parameter-group';
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { ParameterObjParameterKey } from '../parameter-obj-parameter-key';
import { ParameterObjParameterKey, ParameterValues } from '../parameter-values';

/**
* Contains the parameters that will be used for customizing the message for each recipient. [Click here to learn more about parameterization](/docs/sms/resources/message-info/message-parameterization).
*/
export interface ParameterGroup {
[parameterKey: string]: ParameterValues;
}

/** @deprecated Use ParameterGroup instead */
export interface ParameterObj extends Record<string, any> {

/** @see ParameterObjParameterKey */
'{parameter_key}'?: ParameterObjParameterKey;
}


This file was deleted.

1 change: 0 additions & 1 deletion packages/sms/src/models/v1/parameter-obj/index.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/sms/src/models/v1/parameter-values/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { ParameterObjParameterKey, ParameterValues } from './parameter-values';
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
/**
* The name of the parameter that will be replaced in the message body. Letters A-Z and a-z, digits 0-9 and .-_ allowed.
*/
export interface ParameterValues {
/** The key is the recipient that should have the `parameter_key` replaced with the value */
[msisdn: string]: string | undefined;
/** The fall-back value for omitted recipient phone numbers <a href=\"https://community.sinch.com/t5/Glossary/MSISDN/ta-p/7628\" target=\"_blank\">MSISDNs</a>. */
default?: string;
}

/** @deprecated Use ParameterValues instead */
export interface ParameterObjParameterKey {

/** The key is the recipient that should have the `parameter_key` replaced with the value */
Expand Down
6 changes: 3 additions & 3 deletions packages/sms/src/models/v1/text-request/text-request.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ParameterObj } from '../parameter-obj';
import { ParameterGroup } from '../parameter-group';
import { DeliveryReportEnum } from '../enums';

export interface TextRequest {
/** List of Phone numbers and group IDs that will receive the batch. <a href=\"https://community.sinch.com/t5/Glossary/MSISDN/ta-p/7628\" target=\"_blank\">More info</a> */
to: string[];
/** Sender number. Must be valid phone number, short code or alphanumeric. Required if Automatic Default Originator not configured. */
from?: string;
/** @see ParameterObj */
parameters?: ParameterObj;
/** @see ParameterGroup */
parameters?: ParameterGroup;
/** The message content */
body: string;
/** Regular SMS */
Expand Down
6 changes: 3 additions & 3 deletions packages/sms/src/models/v1/text-response/text-response.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ParameterObj } from '../parameter-obj';
import { ParameterGroup } from '../parameter-group';
import { DeliveryReportEnum } from '../enums';

export interface TextResponse {
Expand All @@ -10,8 +10,8 @@ export interface TextResponse {
from?: string;
/** Indicates if the batch has been canceled or not. */
canceled?: boolean;
/** @see ParameterObj */
parameters?: ParameterObj;
/** @see ParameterGroup */
parameters?: ParameterGroup;
/** The message content */
body?: string;
/** Regular SMS */
Expand Down
73 changes: 61 additions & 12 deletions packages/sms/tests/rest/v1/batches/batches.steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BatchesApi, SmsService, Sms } from '../../../../src';
import { Given, When, Then } from '@cucumber/cucumber';
import * as assert from 'assert';
import { PageResult } from '@sinch/sdk-client';
import { ParameterGroup } from '../../../../src/models';

let batchesApi: BatchesApi;
let sendSmsResponse: Sms.TextResponse;
Expand Down Expand Up @@ -54,6 +55,54 @@ Then('the response contains the text SMS details', () => {
assert.equal(sendSmsResponse.flash_message, false);
});

When('I send a request to send a text message with multiple parameters', async () => {
const sendSmsRequest: Sms.SendTextSMSRequestData = {
sendSMSRequestBody: {
body: 'Hello ${name}! Get 20% off with this discount code ${code}',
to: ['+12017777777', '+12018888888'],
from: '+12015555555',
parameters: {
name: {
'+12017777777': 'John',
'+12018888888': 'Paul',
default: 'there',
},
code: {
'+12017777777': 'HALLOWEEN20 🎃',
},
},
delivery_report: 'full',
},
};
sendSmsResponse = await batchesApi.sendTextMessage(sendSmsRequest);
});

Then('the response contains the text SMS details with multiple parameters', () => {
assert.equal(sendSmsResponse.id, '01W4FFL35P4NC4K35SMSBATCH2');
assert.deepEqual(sendSmsResponse.to, ['12017777777', '12018888888']);
assert.equal(sendSmsResponse.from, '12015555555');
assert.equal(sendSmsResponse.canceled, false);
const parameters: ParameterGroup = {
name: {
default: 'there',
'+12017777777': 'John',
'+12018888888': 'Paul',
},
code: {
'+12017777777': 'HALLOWEEN20 🎃',
},
};
assert.deepEqual(sendSmsResponse.parameters, parameters);
assert.equal(sendSmsResponse.body, 'Hello ${name}! Get 20% off with this discount code ${code}');
assert.equal(sendSmsResponse.type, 'mt_text');
assert.deepEqual(sendSmsResponse.created_at, new Date('2024-06-06T09:22:14.304Z'));
assert.deepEqual(sendSmsResponse.modified_at, new Date('2024-06-06T09:22:14.304Z'));
const fullDeliveryReport: Sms.DeliveryReportEnum = 'full';
assert.equal(sendSmsResponse.delivery_report, fullDeliveryReport);
assert.deepEqual(sendSmsResponse.expire_at, new Date('2024-06-06T09:22:14.304Z'));
assert.equal(sendSmsResponse.flash_message, false);
});

When('I send a request to perform a dry run of a batch', async () => {
const sendSmsRequest: Sms.DryRunRequestData = {
dryRunRequestBody: {
Expand Down Expand Up @@ -154,19 +203,19 @@ When('I send a request to retrieve an SMS batch', async () => {

Then('the response contains the SMS batch details', () => {
assert.equal(batch.id, '01W4FFL35P4NC4K35SMSBATCH1');
assert.deepEqual(sendSmsResponse.to, ['12017777777']);
assert.equal(sendSmsResponse.from, '12015555555');
assert.equal(sendSmsResponse.canceled, false);
assert.equal(sendSmsResponse.body, 'SMS body message');
assert.equal(sendSmsResponse.type, 'mt_text');
assert.deepEqual(sendSmsResponse.created_at, new Date('2024-06-06T09:22:14.304Z'));
assert.deepEqual(sendSmsResponse.modified_at, new Date('2024-06-06T09:22:14.304Z'));
assert.deepEqual(batch.to, ['12017777777']);
assert.equal(batch.from, '12015555555');
assert.equal(batch.canceled, false);
assert.equal(batch.body, 'SMS body message');
assert.equal(batch.type, 'mt_text');
assert.deepEqual(batch.created_at, new Date('2024-06-06T09:22:14.304Z'));
assert.deepEqual(batch.modified_at, new Date('2024-06-06T09:22:14.304Z'));
const fullDeliveryReport: Sms.DeliveryReportEnum = 'full';
assert.equal(sendSmsResponse.delivery_report, fullDeliveryReport);
assert.deepEqual(sendSmsResponse.send_at, new Date('2024-06-06T09:25:00Z'));
assert.deepEqual(sendSmsResponse.expire_at, new Date('2024-06-09T09:25:00Z'));
assert.equal(sendSmsResponse.feedback_enabled, true);
assert.equal(sendSmsResponse.flash_message, false);
assert.equal(batch.delivery_report, fullDeliveryReport);
assert.deepEqual(batch.send_at, new Date('2024-06-06T09:25:00Z'));
assert.deepEqual(batch.expire_at, new Date('2024-06-09T09:25:00Z'));
assert.equal(batch.feedback_enabled, true);
assert.equal((batch as Sms.TextResponse).flash_message, false);
});

When('I send a request to update an SMS batch', async () => {
Expand Down

0 comments on commit 412e534

Please sign in to comment.