diff --git a/packages/sms/CHANGELOG.md b/packages/sms/CHANGELOG.md index 64912161..2ee38a3b 100644 --- a/packages/sms/CHANGELOG.md +++ b/packages/sms/CHANGELOG.md @@ -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`: + +| Deprecated | New | +|--------------------------|-----------------| +| ParameterObj | ParameterGroup | +| ParameterObjParameterKey | ParameterValues | + - [E2E] Add Cucumber steps implementation. ## Version 1.1.0 diff --git a/packages/sms/src/models/v1/api-update-mms-mt-message/api-update-mms-mt-message.ts b/packages/sms/src/models/v1/api-update-mms-mt-message/api-update-mms-mt-message.ts index 9057b61a..79574eeb 100644 --- a/packages/sms/src/models/v1/api-update-mms-mt-message/api-update-mms-mt-message.ts +++ b/packages/sms/src/models/v1/api-update-mms-mt-message/api-update-mms-mt-message.ts @@ -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 { @@ -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; } diff --git a/packages/sms/src/models/v1/api-update-text-mt-message/api-update-text-mt-message.ts b/packages/sms/src/models/v1/api-update-text-mt-message/api-update-text-mt-message.ts index 64ae8181..1f52fee8 100644 --- a/packages/sms/src/models/v1/api-update-text-mt-message/api-update-text-mt-message.ts +++ b/packages/sms/src/models/v1/api-update-text-mt-message/api-update-text-mt-message.ts @@ -1,4 +1,4 @@ -import { ParameterObj } from '../parameter-obj'; +import { ParameterGroup } from '../parameter-group'; import { DeliveryReportEnum } from '../enums'; export interface ApiUpdateTextMtMessage { @@ -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; } diff --git a/packages/sms/src/models/v1/index.ts b/packages/sms/src/models/v1/index.ts index a7cd9de0..810d1a46 100644 --- a/packages/sms/src/models/v1/index.ts +++ b/packages/sms/src/models/v1/index.ts @@ -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'; diff --git a/packages/sms/src/models/v1/media-request/media-request.ts b/packages/sms/src/models/v1/media-request/media-request.ts index 2c39855e..0226502a 100644 --- a/packages/sms/src/models/v1/media-request/media-request.ts +++ b/packages/sms/src/models/v1/media-request/media-request.ts @@ -1,5 +1,5 @@ import { MediaBody } from '../media-body'; -import { ParameterObj } from '../parameter-obj'; +import { ParameterGroup } from '../parameter-group'; import { DeliveryReportEnum } from '../enums'; /** @@ -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. */ diff --git a/packages/sms/src/models/v1/media-response/media-response.ts b/packages/sms/src/models/v1/media-response/media-response.ts index d355c255..964cddfa 100644 --- a/packages/sms/src/models/v1/media-response/media-response.ts +++ b/packages/sms/src/models/v1/media-response/media-response.ts @@ -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 { @@ -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 */ diff --git a/packages/sms/src/models/v1/parameter-group/index.ts b/packages/sms/src/models/v1/parameter-group/index.ts new file mode 100644 index 00000000..39b8f6c3 --- /dev/null +++ b/packages/sms/src/models/v1/parameter-group/index.ts @@ -0,0 +1 @@ +export type { ParameterObj, ParameterGroup } from './parameter-group'; diff --git a/packages/sms/src/models/v1/parameter-obj/parameter-obj.ts b/packages/sms/src/models/v1/parameter-group/parameter-group.ts similarity index 63% rename from packages/sms/src/models/v1/parameter-obj/parameter-obj.ts rename to packages/sms/src/models/v1/parameter-group/parameter-group.ts index 15beaa86..55c2564d 100644 --- a/packages/sms/src/models/v1/parameter-obj/parameter-obj.ts +++ b/packages/sms/src/models/v1/parameter-group/parameter-group.ts @@ -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 { /** @see ParameterObjParameterKey */ '{parameter_key}'?: ParameterObjParameterKey; } - - diff --git a/packages/sms/src/models/v1/parameter-obj-parameter-key/index.ts b/packages/sms/src/models/v1/parameter-obj-parameter-key/index.ts deleted file mode 100644 index 2b230f38..00000000 --- a/packages/sms/src/models/v1/parameter-obj-parameter-key/index.ts +++ /dev/null @@ -1 +0,0 @@ -export type { ParameterObjParameterKey } from './parameter-obj-parameter-key'; diff --git a/packages/sms/src/models/v1/parameter-obj/index.ts b/packages/sms/src/models/v1/parameter-obj/index.ts deleted file mode 100644 index 39022580..00000000 --- a/packages/sms/src/models/v1/parameter-obj/index.ts +++ /dev/null @@ -1 +0,0 @@ -export type { ParameterObj } from './parameter-obj'; diff --git a/packages/sms/src/models/v1/parameter-values/index.ts b/packages/sms/src/models/v1/parameter-values/index.ts new file mode 100644 index 00000000..c4d2048b --- /dev/null +++ b/packages/sms/src/models/v1/parameter-values/index.ts @@ -0,0 +1 @@ +export type { ParameterObjParameterKey, ParameterValues } from './parameter-values'; diff --git a/packages/sms/src/models/v1/parameter-obj-parameter-key/parameter-obj-parameter-key.ts b/packages/sms/src/models/v1/parameter-values/parameter-values.ts similarity index 54% rename from packages/sms/src/models/v1/parameter-obj-parameter-key/parameter-obj-parameter-key.ts rename to packages/sms/src/models/v1/parameter-values/parameter-values.ts index 2e33d1d2..e8938bea 100644 --- a/packages/sms/src/models/v1/parameter-obj-parameter-key/parameter-obj-parameter-key.ts +++ b/packages/sms/src/models/v1/parameter-values/parameter-values.ts @@ -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 MSISDNs. */ + default?: string; +} + +/** @deprecated Use ParameterValues instead */ export interface ParameterObjParameterKey { /** The key is the recipient that should have the `parameter_key` replaced with the value */ diff --git a/packages/sms/src/models/v1/text-request/text-request.ts b/packages/sms/src/models/v1/text-request/text-request.ts index 6bd814ec..8fdb6fa3 100644 --- a/packages/sms/src/models/v1/text-request/text-request.ts +++ b/packages/sms/src/models/v1/text-request/text-request.ts @@ -1,4 +1,4 @@ -import { ParameterObj } from '../parameter-obj'; +import { ParameterGroup } from '../parameter-group'; import { DeliveryReportEnum } from '../enums'; export interface TextRequest { @@ -6,8 +6,8 @@ export interface TextRequest { 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 */ diff --git a/packages/sms/src/models/v1/text-response/text-response.ts b/packages/sms/src/models/v1/text-response/text-response.ts index 292c90f6..fc27053a 100644 --- a/packages/sms/src/models/v1/text-response/text-response.ts +++ b/packages/sms/src/models/v1/text-response/text-response.ts @@ -1,4 +1,4 @@ -import { ParameterObj } from '../parameter-obj'; +import { ParameterGroup } from '../parameter-group'; import { DeliveryReportEnum } from '../enums'; export interface TextResponse { @@ -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 */ diff --git a/packages/sms/tests/rest/v1/batches/batches.steps.ts b/packages/sms/tests/rest/v1/batches/batches.steps.ts index 88ec91a8..be06582d 100644 --- a/packages/sms/tests/rest/v1/batches/batches.steps.ts +++ b/packages/sms/tests/rest/v1/batches/batches.steps.ts @@ -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; @@ -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: { @@ -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 () => {