diff --git a/packages/messages/README.md b/packages/messages/README.md index 114a9a0a..ec58ccd7 100644 --- a/packages/messages/README.md +++ b/packages/messages/README.md @@ -13,6 +13,7 @@ If you are updating from V2 to V3, please check the migration guide found [here] * [Installation](#installation) * [Usage](#usage) * [Promises](#promises) +* [Channels](#channels) ## Installation @@ -109,6 +110,25 @@ Run: npm run test ``` +## Channels + +The Vonage Messages API supports several different communication channels, and +from time to time will add new channels. Each channel follows our normal product +development cycle and therefore different channels within the overall API may +have different release statuses at a certain point in time. Channels available +for general use will be listed as having 'General Availability'. Channels which +are currently part of a Beta program will be listed as 'Beta'. This table +details the current release status of each channel implemented in this SDK: + +| Channel | API Release Status | +|--------------------|:--------------------:| +| SMS | General Availability | +| MMS | General Availability | +| RCS | Beta | +| Facebook Messenger | General Availability | +| WhatsApp | General Availability | +| Viber | General Availability | + [signup]: https://dashboard.nexmo.com/sign-up?utm_source=DEV_REL&utm_medium=github&utm_campaign=node-server-sdk [license]: ../../LICENSE.txt diff --git a/packages/messages/__tests__/__dataSets__/index.ts b/packages/messages/__tests__/__dataSets__/index.ts index 3ff90be5..f41a12b9 100644 --- a/packages/messages/__tests__/__dataSets__/index.ts +++ b/packages/messages/__tests__/__dataSets__/index.ts @@ -3,26 +3,31 @@ import mmsTests from './mms'; import messengerTests from './messenger'; import viberTests from './viber'; import whatsAppTests from './whatsApp'; +import RCSTests from './rcs'; export default [ { - label: 'SMS Messages', + label: 'SMS', tests: smsTests, }, { - label: 'MMS Messages', + label: 'MMS', tests: mmsTests, }, { - label: 'Messenger Messages', + label: 'Messenger', tests: messengerTests, }, { - label: 'Viber Messages', + label: 'Viber', tests: viberTests, }, { - label: 'WhatsApp Messages', + label: 'WhatsApp', tests: whatsAppTests, }, + { + label: 'RCS', + tests: RCSTests, + }, ]; diff --git a/packages/messages/__tests__/__dataSets__/messenger.ts b/packages/messages/__tests__/__dataSets__/messenger.ts index 4f6bcad2..ddbc8064 100644 --- a/packages/messages/__tests__/__dataSets__/messenger.ts +++ b/packages/messages/__tests__/__dataSets__/messenger.ts @@ -29,7 +29,7 @@ import { MessageCategory } from '../../lib/enums/Messenger/MessageCategory'; export default [ { - label: 'send Messenger text', + label: 'send text', request: [ '/v1/messages', 'POST', @@ -61,7 +61,7 @@ export default [ } as MessageSuccess, }, { - label: 'send Messenger text with ref and messenger properties', + label: 'send text with ref and messenger properties', request: [ '/v1/messages', 'POST', @@ -107,7 +107,7 @@ export default [ } as MessageSuccess, }, { - label: 'send Messenger text with old class', + label: 'send text with old class', request: [ '/v1/messages', 'POST', @@ -149,7 +149,7 @@ export default [ } as MessageSuccess, }, { - label: 'send Messenger image', + label: 'send image', request: [ '/v1/messages', 'POST', @@ -185,7 +185,7 @@ export default [ } as MessageSuccess, }, { - label: 'send Messenger image with messenger properties and ref', + label: 'send image with messenger properties and ref', request: [ '/v1/messages', 'POST', @@ -231,7 +231,7 @@ export default [ } as MessageSuccess, }, { - label: 'send Messenger image with old class', + label: 'send image with old class', request: [ '/v1/messages', 'POST', @@ -277,7 +277,7 @@ export default [ } as MessageSuccess, }, { - label: 'send Messenger audio', + label: 'send audio', request: [ '/v1/messages', 'POST', @@ -313,7 +313,7 @@ export default [ } as MessageSuccess, }, { - label: 'send Messenger audio with caption and ref', + label: 'send audio with caption and ref', request: [ '/v1/messages', 'POST', @@ -359,7 +359,7 @@ export default [ } as MessageSuccess, }, { - label: 'send Messenger audio with old class', + label: 'send audio with old class', request: [ '/v1/messages', 'POST', @@ -405,7 +405,7 @@ export default [ } as MessageSuccess, }, { - label: 'send Messenger video', + label: 'send video', request: [ '/v1/messages', 'POST', @@ -441,7 +441,7 @@ export default [ } as MessageSuccess, }, { - label: 'send Messenger video with messenger and ref', + label: 'send video with messenger and ref', request: [ '/v1/messages', 'POST', @@ -487,7 +487,7 @@ export default [ } as MessageSuccess, }, { - label: 'send Messenger video with old class', + label: 'send video with old class', request: [ '/v1/messages', 'POST', @@ -533,7 +533,7 @@ export default [ } as MessageSuccess, }, { - label: 'send Messenger file', + label: 'send file', request: [ '/v1/messages', 'POST', @@ -569,7 +569,7 @@ export default [ } as MessageSuccess, }, { - label: 'send Messenger file with messenger and ref', + label: 'send file with messenger and ref', request: [ '/v1/messages', 'POST', @@ -615,7 +615,7 @@ export default [ } as MessageSuccess, }, { - label: 'send Messenger file with old class', + label: 'send file with old class', request: [ '/v1/messages', 'POST', diff --git a/packages/messages/__tests__/__dataSets__/mms.ts b/packages/messages/__tests__/__dataSets__/mms.ts index 4ab5bbc0..646f4dce 100644 --- a/packages/messages/__tests__/__dataSets__/mms.ts +++ b/packages/messages/__tests__/__dataSets__/mms.ts @@ -22,7 +22,7 @@ import { Vcard } from '../../lib/classes/MMS/Vcard'; export default [ { - label: 'send MMS image', + label: 'send image', request: [ '/v1/messages', 'POST', @@ -58,7 +58,7 @@ export default [ } as MessageSuccess, }, { - label: 'send MMS image with caption and ref', + label: 'send image with caption and ref', request: [ '/v1/messages', 'POST', @@ -102,7 +102,7 @@ export default [ } as MessageSuccess, }, { - label: 'send MMS image with old class ', + label: 'send image with old class ', request: [ '/v1/messages', 'POST', @@ -142,7 +142,7 @@ export default [ } as MessageSuccess, }, { - label: 'send MMS audio', + label: 'send audio', request: [ '/v1/messages', 'POST', @@ -178,7 +178,7 @@ export default [ } as MessageSuccess, }, { - label: 'send MMS audio with caption and ref', + label: 'send audio with caption and ref', request: [ '/v1/messages', 'POST', @@ -218,7 +218,7 @@ export default [ } as MessageSuccess, }, { - label: 'send MMS audio using old class ', + label: 'send audio using old class ', request: [ '/v1/messages', 'POST', @@ -258,7 +258,7 @@ export default [ } as MessageSuccess, }, { - label: 'send MMS video', + label: 'send video', request: [ '/v1/messages', 'POST', @@ -294,7 +294,7 @@ export default [ } as MessageSuccess, }, { - label: 'send MMS video with caption and ref', + label: 'send video with caption and ref', request: [ '/v1/messages', 'POST', @@ -334,7 +334,7 @@ export default [ } as MessageSuccess, }, { - label: 'send MMS video with old class ', + label: 'send video with old class ', request: [ '/v1/messages', 'POST', @@ -374,7 +374,7 @@ export default [ } as MessageSuccess, }, { - label: 'send MMS vcard', + label: 'send vcard', request: [ '/v1/messages', 'POST', @@ -410,7 +410,7 @@ export default [ } as MessageSuccess, }, { - label: 'send MMS vcard with client ref', + label: 'send vcard with client ref', request: [ '/v1/messages', 'POST', @@ -450,7 +450,7 @@ export default [ } as MessageSuccess, }, { - label: 'send MMS vcard with old class', + label: 'send vcard with old class', request: [ '/v1/messages', 'POST', diff --git a/packages/messages/__tests__/__dataSets__/rcs.ts b/packages/messages/__tests__/__dataSets__/rcs.ts new file mode 100644 index 00000000..0d12f23b --- /dev/null +++ b/packages/messages/__tests__/__dataSets__/rcs.ts @@ -0,0 +1,437 @@ +import { + MessageSuccess, + RCSText, + RCSImage, + RCSVideo, + RCSFile, + RCSCustom, +} from '../../lib'; + +export default [ + { + label: 'send text', + request: [ + '/v1/messages', + 'POST', + { + from: 'Vonage', + to: '14152739164', + text: 'too many secrets', + channel: 'rcs', + message_type: 'text', + }, + ], + response: [ + 202, + { + message_uuid: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a', + }, + ], + method: 'POST', + clientMethod: 'send', + parameters: [ + new RCSText({ + from: 'Vonage', + to: '14152739164', + text: 'too many secrets', + }), + ], + expected: { + messageUUID: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a', + } as MessageSuccess, + }, + { + label: 'send text with all parameters', + request: [ + '/v1/messages', + 'POST', + { + from: 'Vonage', + to: '14152739164', + text: 'too many secrets', + channel: 'rcs', + message_type: 'text', + client_ref: 'nsa-1', + ttl: 42, + }, + ], + response: [ + 202, + { + message_uuid: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a', + }, + ], + method: 'POST', + clientMethod: 'send', + parameters: [ + new RCSText({ + from: 'Vonage', + to: '14152739164', + text: 'too many secrets', + ttl: 42, + clientRef: 'nsa-1', + }), + ], + expected: { + messageUUID: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a', + } as MessageSuccess, + }, + { + label: 'send image', + request: [ + '/v1/messages', + 'POST', + { + from: 'Vonage', + to: '14152739164', + channel: 'rcs', + message_type: 'image', + image: { + url: 'https://example.com', + }, + }, + ], + response: [ + 200, + { + message_uuid: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a', + }, + ], + method: 'POST', + clientMethod: 'send', + parameters: [ + new RCSImage({ + from: 'Vonage', + to: '14152739164', + image: { + url: 'https://example.com', + }, + }), + ], + expected: { + messageUUID: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a', + } as MessageSuccess, + }, + { + label: 'send image with all parameters', + request: [ + '/v1/messages', + 'POST', + { + from: 'Vonage', + to: '14152739164', + channel: 'rcs', + client_ref: 'my-ref', + message_type: 'image', + image: { + url: 'https://example.com', + }, + webhook_url: 'https://example.com', + ttl: 42, + }, + ], + response: [ + 202, + { + message_uuid: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a', + }, + ], + method: 'POST', + clientMethod: 'send', + parameters: [ + new RCSImage({ + from: 'Vonage', + to: '14152739164', + clientRef: 'my-ref', + image: { + url: 'https://example.com', + }, + webhookUrl: 'https://example.com', + ttl: 42, + }), + ], + expected: { + messageUUID: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a', + } as MessageSuccess, + }, + { + label: 'send video', + request: [ + '/v1/messages', + 'POST', + { + from: 'Vonage', + to: '14152739164', + channel: 'rcs', + message_type: 'video', + video: { + url: 'https://example.com', + }, + }, + ], + response: [ + 202, + { + message_uuid: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a', + }, + ], + method: 'POST', + clientMethod: 'send', + parameters: [ + new RCSVideo({ + from: 'Vonage', + to: '14152739164', + video: { + url: 'https://example.com', + }, + }), + ], + expected: { + messageUUID: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a', + } as MessageSuccess, + }, + { + label: 'send video with all parameters', + request: [ + '/v1/messages', + 'POST', + { + from: 'Vonage', + to: '14152739164', + channel: 'rcs', + message_type: 'video', + client_ref: 'my-ref', + ttl: 42, + video: { + url: 'http://example.com/video.mp4', + }, + }, + ], + response: [ + 202, + { + message_uuid: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a', + }, + ], + method: 'POST', + clientMethod: 'send', + parameters: [ + new RCSVideo({ + from: 'Vonage', + to: '14152739164', + clientRef: 'my-ref', + ttl: 42, + video: { + url: 'http://example.com/video.mp4', + }, + }), + ], + expected: { + messageUUID: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a', + } as MessageSuccess, + }, + { + label: 'send custom', + request: [ + '/v1/messages', + 'POST', + { + from: 'Vonage', + to: '14152739164', + channel: 'rcs', + message_type: 'custom', + custom: { + contentMessage: { + text: 'Check out our latest offers!', + suggestions: [ + { + action: { + text: 'Open product page', + postbackData: 'postback_data_1234', + openUrlAction: { + url: 'http://example.com/', + }, + }, + }, + ], + }, + } as Record, + }, + ], + response: [ + 202, + { + message_uuid: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a', + }, + ], + method: 'POST', + clientMethod: 'send', + parameters: [ + new RCSCustom({ + from: 'Vonage', + to: '14152739164', + custom: { + contentMessage: { + text: 'Check out our latest offers!', + suggestions: [ + { + action: { + text: 'Open product page', + postbackData: 'postback_data_1234', + openUrlAction: { + url: 'http://example.com/', + }, + }, + }, + ], + }, + }, + }), + ], + expected: { + messageUUID: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a', + } as MessageSuccess, + }, + { + label: 'send custom with all parameters', + request: [ + '/v1/messages', + 'POST', + { + from: 'Vonage', + to: '14152739164', + channel: 'rcs', + message_type: 'custom', + client_ref: 'my-ref', + ttl: 42, + custom: { + contentMessage: { + text: 'Check out our latest offers!', + suggestions: [ + { + action: { + text: 'Open product page', + postbackData: 'postback_data_1234', + openUrlAction: { + url: 'http://example.com/', + }, + }, + }, + ], + }, + } as Record, + }, + ], + response: [ + 202, + { + message_uuid: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a', + }, + ], + method: 'POST', + clientMethod: 'send', + parameters: [ + new RCSCustom({ + from: 'Vonage', + to: '14152739164', + clientRef: 'my-ref', + ttl: 42, + custom: { + contentMessage: { + text: 'Check out our latest offers!', + suggestions: [ + { + action: { + text: 'Open product page', + postbackData: 'postback_data_1234', + openUrlAction: { + url: 'http://example.com/', + }, + }, + }, + ], + }, + }, + }), + ], + expected: { + messageUUID: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a', + } as MessageSuccess, + }, + { + label: 'send file', + request: [ + '/v1/messages', + 'POST', + { + from: 'Vonage', + to: '14152739164', + channel: 'rcs', + message_type: 'file', + file: { + url: 'https://example.com/my-file.png', + }, + }, + ], + response: [ + 202, + { + message_uuid: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a', + }, + ], + method: 'POST', + clientMethod: 'send', + parameters: [ + new RCSFile({ + from: 'Vonage', + to: '14152739164', + file: { + url: 'https://example.com/my-file.png', + }, + }), + ], + expected: { + messageUUID: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a', + } as MessageSuccess, + }, + { + label: 'send file with all parameters', + request: [ + '/v1/messages', + 'POST', + { + from: 'Vonage', + to: '14152739164', + channel: 'rcs', + message_type: 'file', + client_ref: 'my-ref', + ttl: 42, + file: { + url: 'https://example.com/my-file.png', + }, + }, + ], + response: [ + 202, + { + message_uuid: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a', + }, + ], + method: 'POST', + clientMethod: 'send', + parameters: [ + new RCSFile({ + from: 'Vonage', + to: '14152739164', + clientRef: 'my-ref', + ttl: 42, + file: { + url: 'https://example.com/my-file.png', + }, + }), + ], + expected: { + messageUUID: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a', + } as MessageSuccess, + }, +]; diff --git a/packages/messages/__tests__/__dataSets__/sms.ts b/packages/messages/__tests__/__dataSets__/sms.ts index d675f0ef..56b73153 100644 --- a/packages/messages/__tests__/__dataSets__/sms.ts +++ b/packages/messages/__tests__/__dataSets__/sms.ts @@ -1,11 +1,10 @@ import { SMS } from '../../lib'; import { MessageSuccess } from '../../lib'; import { MessageParamsText, SMSMessageRequest } from '../../lib'; -import { AuthType } from '../common'; export default [ { - label: 'send SMS message', + label: 'send message', request: [ '/v1/messages', 'POST', @@ -15,7 +14,7 @@ export default [ text: 'too many secrets', channel: 'sms', message_type: 'text', - } as SMSMessageRequest, + }, ], response: [ 200, @@ -37,7 +36,7 @@ export default [ } as MessageSuccess, }, { - label: 'send SMS message with SMS extra params', + label: 'send message with extra params', request: [ '/v1/messages', 'POST', @@ -79,7 +78,7 @@ export default [ } as MessageSuccess, }, { - label: 'send SMS message with client ref', + label: 'send message with client ref', request: [ '/v1/messages', 'POST', @@ -117,7 +116,7 @@ export default [ } as MessageSuccess, }, { - label: 'send SMS message with client ref', + label: 'send message with client ref', request: [ '/v1/messages', 'POST', @@ -151,7 +150,7 @@ export default [ } as MessageSuccess, }, { - label: 'send SMS message with old params', + label: 'send message with old params', request: [ '/v1/messages', 'POST', @@ -180,7 +179,7 @@ export default [ } as MessageSuccess, }, { - label: 'send SMS message with error response', + label: 'send message with error response', request: [ '/v1/messages', 'POST', @@ -214,6 +213,5 @@ export default [ messageUUID: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a', } as MessageSuccess, error: 'Request failed with status code 401', - authType: AuthType.JWT, }, ]; diff --git a/packages/messages/__tests__/__dataSets__/viber.ts b/packages/messages/__tests__/__dataSets__/viber.ts index 2d6e15ac..7f3a89dd 100644 --- a/packages/messages/__tests__/__dataSets__/viber.ts +++ b/packages/messages/__tests__/__dataSets__/viber.ts @@ -23,7 +23,7 @@ import { MessageCategory } from '../../lib/enums/Viber/MessageCategory'; export default [ { - label: 'send Viber text', + label: 'send text', request: [ '/v1/messages', 'POST', @@ -55,7 +55,7 @@ export default [ } as MessageSuccess, }, { - label: 'send Viber text with viber service', + label: 'send text with viber service', request: [ '/v1/messages', 'POST', @@ -111,7 +111,7 @@ export default [ } as MessageSuccess, }, { - label: 'send Viber text with old class', + label: 'send text with old class', request: [ '/v1/messages', 'POST', @@ -155,7 +155,7 @@ export default [ } as MessageSuccess, }, { - label: 'send Viber image', + label: 'send image', request: [ '/v1/messages', 'POST', @@ -191,7 +191,7 @@ export default [ } as MessageSuccess, }, { - label: 'send Viber image with viber service', + label: 'send image with viber service', request: [ '/v1/messages', 'POST', @@ -247,7 +247,7 @@ export default [ } as MessageSuccess, }, { - label: 'send Viber image with old class', + label: 'send image with old class', request: [ '/v1/messages', 'POST', @@ -303,7 +303,7 @@ export default [ } as MessageSuccess, }, { - label: 'send Viber video', + label: 'send video', request: [ '/v1/messages', 'POST', @@ -343,7 +343,7 @@ export default [ } as MessageSuccess, }, { - label: 'send Viber video with viber service', + label: 'send video with viber service', request: [ '/v1/messages', 'POST', @@ -381,7 +381,7 @@ export default [ } as MessageSuccess, }, { - label: 'send Viber file', + label: 'send file', request: [ '/v1/messages', 'POST', @@ -417,7 +417,7 @@ export default [ } as MessageSuccess, }, { - label: 'send Viber file with viber service', + label: 'send file with viber service', request: [ '/v1/messages', 'POST', diff --git a/packages/messages/__tests__/__dataSets__/whatsApp.ts b/packages/messages/__tests__/__dataSets__/whatsApp.ts index df6a9dad..90354bdd 100644 --- a/packages/messages/__tests__/__dataSets__/whatsApp.ts +++ b/packages/messages/__tests__/__dataSets__/whatsApp.ts @@ -39,7 +39,7 @@ import { Video } from '../../lib/classes/WhatsApp/Video'; export default [ { - label: 'send WhatsApp text', + label: 'send text', request: [ '/v1/messages', 'POST', @@ -71,7 +71,7 @@ export default [ } as MessageSuccess, }, { - label: 'send WhatsApp text with client ref and context', + label: 'send text with client ref and context', request: [ '/v1/messages', 'POST', @@ -115,7 +115,7 @@ export default [ } as MessageSuccess, }, { - label: 'send WhatsApp text with old class', + label: 'send text with old class', request: [ '/v1/messages', 'POST', @@ -149,7 +149,7 @@ export default [ } as MessageSuccess, }, { - label: 'send WhatsApp template', + label: 'send template', request: [ '/v1/messages', 'POST', @@ -195,7 +195,7 @@ export default [ } as MessageSuccess, }, { - label: 'send WhatsApp template with client ref', + label: 'send template with client ref', request: [ '/v1/messages', 'POST', @@ -243,7 +243,7 @@ export default [ } as MessageSuccess, }, { - label: 'send WhatsApp template with old class', + label: 'send template with old class', request: [ '/v1/messages', 'POST', @@ -288,7 +288,7 @@ export default [ } as MessageSuccess, }, { - label: 'send WhatsApp url sticker', + label: 'send url sticker', request: [ '/v1/messages', 'POST', @@ -324,7 +324,7 @@ export default [ } as MessageSuccess, }, { - label: 'send WhatsApp url sticker with clientRef', + label: 'send url sticker with clientRef', request: [ '/v1/messages', 'POST', @@ -362,7 +362,7 @@ export default [ } as MessageSuccess, }, { - label: 'send WhatsApp id sticker', + label: 'send id sticker', request: [ '/v1/messages', 'POST', @@ -398,7 +398,7 @@ export default [ } as MessageSuccess, }, { - label: 'send WhatsApp id sticker with client ref', + label: 'send id sticker with client ref', request: [ '/v1/messages', 'POST', @@ -436,7 +436,7 @@ export default [ } as MessageSuccess, }, { - label: 'send WhatsApp file', + label: 'send file', request: [ '/v1/messages', 'POST', @@ -472,7 +472,7 @@ export default [ } as MessageSuccess, }, { - label: 'send WhatsApp file with caption and ref', + label: 'send file with caption and ref', request: [ '/v1/messages', 'POST', @@ -514,7 +514,7 @@ export default [ } as MessageSuccess, }, { - label: 'send WhatsApp file with old class', + label: 'send file with old class', request: [ '/v1/messages', 'POST', @@ -554,7 +554,7 @@ export default [ } as MessageSuccess, }, { - label: 'send WhatsApp custom', + label: 'send custom', request: [ '/v1/messages', 'POST', @@ -590,7 +590,7 @@ export default [ } as MessageSuccess, }, { - label: 'send WhatsApp custom with client ref', + label: 'send custom with client ref', request: [ '/v1/messages', 'POST', @@ -628,7 +628,7 @@ export default [ } as MessageSuccess, }, { - label: 'send WhatsApp custom with old class', + label: 'send custom with old class', request: [ '/v1/messages', 'POST', @@ -666,7 +666,7 @@ export default [ } as MessageSuccess, }, { - label: 'send WhatsApp image', + label: 'send image', request: [ '/v1/messages', 'POST', @@ -702,7 +702,7 @@ export default [ } as MessageSuccess, }, { - label: 'send WhatsApp image with caption and ref', + label: 'send image with caption and ref', request: [ '/v1/messages', 'POST', @@ -742,7 +742,7 @@ export default [ } as MessageSuccess, }, { - label: 'send WhatsApp image with old class', + label: 'send image with old class', request: [ '/v1/messages', 'POST', @@ -782,7 +782,7 @@ export default [ } as MessageSuccess, }, { - label: 'send WhatsApp audio', + label: 'send audio', request: [ '/v1/messages', 'POST', @@ -818,7 +818,7 @@ export default [ } as MessageSuccess, }, { - label: 'send WhatsApp audio with caption and ref', + label: 'send audio with caption and ref', request: [ '/v1/messages', 'POST', @@ -858,7 +858,7 @@ export default [ } as MessageSuccess, }, { - label: 'send WhatsApp audio with old class', + label: 'send audio with old class', request: [ '/v1/messages', 'POST', @@ -898,7 +898,7 @@ export default [ } as MessageSuccess, }, { - label: 'send WhatsApp video', + label: 'send video', request: [ '/v1/messages', 'POST', @@ -934,7 +934,7 @@ export default [ } as MessageSuccess, }, { - label: 'send WhatsApp video with caption and ref', + label: 'send video with caption and ref', request: [ '/v1/messages', 'POST', @@ -974,7 +974,7 @@ export default [ } as MessageSuccess, }, { - label: 'send WhatsApp video with old class', + label: 'send video with old class', request: [ '/v1/messages', 'POST', diff --git a/packages/messages/__tests__/common.ts b/packages/messages/__tests__/common.ts deleted file mode 100644 index a83830a9..00000000 --- a/packages/messages/__tests__/common.ts +++ /dev/null @@ -1,51 +0,0 @@ -import nock from 'nock'; -import { Auth, AlgorithmTypes } from '@vonage/auth'; -import { Messages } from '../lib/index'; -import { readFileSync } from 'fs'; - -export enum AuthType { - JWT = 'jwt', - SIG = 'sig', - QUERY = 'query', -} - -export const BASE_URL = 'https://api.nexmo.com'; - -const checkJWTAuth = (value) => value.startsWith('Bearer '); - -const testKey = readFileSync(`${__dirname}/private.test.key`).toString(); - -const scopes = { - [AuthType.JWT]: nock(BASE_URL, { - reqheaders: { - Authorization: checkJWTAuth, - }, - }).persist(), - [AuthType.SIG]: nock(BASE_URL).persist(), - [AuthType.QUERY]: nock(BASE_URL).persist(), -}; - -const auths = { - [AuthType.JWT]: new Auth({ - applicationId: 'abcd-1234', - privateKey: testKey, - }), - [AuthType.SIG]: new Auth({ - apiKey: '12345', - signature: { - secret: 'ABCDE', - algorithm: AlgorithmTypes.md5hash, - }, - }), - [AuthType.QUERY]: new Auth({ - apiKey: '12345', - apiSecret: 'ABCDE', - }), -}; - -export const getAuth = (authType: AuthType): Auth => auths[authType]; - -export const getClient = (authType: AuthType): Messages => - new Messages(getAuth(authType)); - -export const getScope = (authType: AuthType): nock => scopes[authType]; diff --git a/packages/messages/__tests__/messages.test.ts b/packages/messages/__tests__/messages.test.ts index 0e150932..bbc7f30b 100644 --- a/packages/messages/__tests__/messages.test.ts +++ b/packages/messages/__tests__/messages.test.ts @@ -1,80 +1,73 @@ -import nock from 'nock'; -import { getScope, getClient, AuthType } from './common'; -import testDataSets from './__dataSets__/index'; +import testDataSets from './__dataSets__/'; +import { Messages } from '../lib'; +import { + VonageTest, + SDKTestCase, + TestResponse, + TestRequest, + testPrivateKey, + TestTuple, +} from '../../../testHelpers'; -describe.each(testDataSets)('$label', ({ tests }) => { - afterEach(function () { - nock.cleanAll(); - }); +// Convert the test data sets into SDK test cases +const messageTests = testDataSets.map((dataSet): TestTuple => { + const { label, tests } = dataSet; - const successTests = tests - .filter(({ error }) => !error) - .map((test) => [ - { - ...test, - authType: AuthType.QUERY, - request: [ - test.request[0], - test.request[1], - { - ...(test.request[2] as object), - api_key: '12345', - api_secret: 'ABCDE', - }, - ], - }, - { - ...test, - authType: AuthType.JWT, - }, - ]) - .flat(); - - const failureTests = tests.filter(({ error }) => !!error); - - test.each(successTests)( - 'Can $label using method: [$clientMethod] with auth: [$authType]', - async ({ - request, - response, - clientMethod, - parameters, - expected, - authType, - }) => { - const scope = getScope(authType); - const client = getClient(authType); - scope.intercept(...request).reply(...response); + const newTests = tests + .map((test): SDKTestCase[] => { + const JWTTest: SDKTestCase = { + label: `${test.label} [JWT]`, + baseUrl: 'https://api.nexmo.com', + reqHeaders: { + authorization: (value: string) => value.startsWith('Bearer '), + }, + responses: [test.response as TestResponse], + requests: [test.request as TestRequest], + client: new Messages({ + applicationId: 'abcd-1234', + privateKey: testPrivateKey, + }), + clientMethod: 'send', + parameters: test.parameters, + generator: false, + error: test.error || false, + expected: test.expected, + }; - const results = await client[clientMethod](...parameters); - expect(results).toEqual(expected); - expect(nock.isDone()).toBeTruthy(); - }, - ); - - if (failureTests.length < 1) { - return; - } + const QueryTest: SDKTestCase = { + label: `${test.label} [API Key and Secret]`, + baseUrl: 'https://api.nexmo.com', + responses: [test.response as TestResponse], + requests: [ + [ + test.request[0], + test.request[1], + { + ...test.request[2], + api_key: '12345', + api_secret: 'ABCDE', + }, + ] as TestRequest, + ], + client: new Messages({ + apiKey: '12345', + apiSecret: 'ABCDE', + }), + clientMethod: 'send', + parameters: test.parameters, + generator: false, + error: test.error || false, + expected: test.expected, + }; - test.each(failureTests)( - 'Will throw $label for method: $clientMethod', - async ({ - request, - response, - clientMethod, - parameters, - error, - authType, - }) => { - const scope = getScope(authType); - const client = getClient(authType); - request[2] = await request[2]?.sig; - scope.intercept(...request).reply(...response); + return [QueryTest, JWTTest]; + }) + .flat(); - await expect(() => - client[clientMethod](...parameters), - ).rejects.toThrow(error); - expect(nock.isDone()).toBeTruthy(); - }, - ); + return { + name: label, + tests: newTests, + }; }); + +VonageTest(messageTests); diff --git a/packages/messages/lib/classes/RCS/RCSCustom.ts b/packages/messages/lib/classes/RCS/RCSCustom.ts new file mode 100644 index 00000000..d48e462a --- /dev/null +++ b/packages/messages/lib/classes/RCS/RCSCustom.ts @@ -0,0 +1,59 @@ +import { AbstractMessage } from '../AbstractMessage'; +import { RCSCustomParams } from '../../types'; +import { Channels } from '../../enums'; + +/** + * Represents a custom message for RCS. + * + * @group RCS + */ +export class RCSCustom extends AbstractMessage implements RCSCustomParams { + /** + * The channel through which the message will be sent. Always `rcs` + */ + public channel: Channels.RCS = Channels.RCS; + + /** + * The type of message. For a custom message, this will always be `custom`. + */ + public messageType = 'custom'; + + /** + * A custom payload. The schema of a custom object can vary widely. + */ + public custom: Record; + + /** + * The duration in seconds the delivery of a message will be attempted. By + * default Vonage attempts delivery for 72 hours, however the maximum effective + * value depends on the operator and is typically 24 - 48 hours. We recommend + * this value should be kept at its default or at least 30 minutes. + */ + public ttl?: number; + + /** + * Sends a custom message through RCS + * + * @param {RCSCustomParams} params - The parameters for creating a RCS custom message. + * @example + * ```ts + * import { RCSCustom } from '@vonage/messages'; + * + * const { messageUUID } = await messagesClient.send(new RCSCustom({ + * to: TO_NUMBER, + * from: FROM_NUMBER, + * custom: { + * foo: 'bar', + * } + * clientRef: 'my-personal-reference', + * })); + * + * console.log(`Message sent successfully with UUID ${messageUUID}`); + * ``` + */ + public constructor(params: RCSCustomParams) { + super(params); + this.custom = params.custom; + this.ttl = params.ttl; + } +} diff --git a/packages/messages/lib/classes/RCS/RCSFile.ts b/packages/messages/lib/classes/RCS/RCSFile.ts new file mode 100644 index 00000000..b0480c5c --- /dev/null +++ b/packages/messages/lib/classes/RCS/RCSFile.ts @@ -0,0 +1,52 @@ +import { AbstractFileMessage } from '../AbstractFileMessage'; +import { MessageParams, RCSFileParams } from '../../types'; +import { Channels } from '../../enums'; + +/** + * Represents a file message for the RCS channel. + * + * @group RCS + */ +export class RCSFile + extends AbstractFileMessage + implements RCSFileParams, MessageParams +{ + /** + * The channel for this message (always 'rcs'). + */ + public channel: Channels.RCS = Channels.RCS; + + /** + * The duration in seconds the delivery of a message will be attempted. By + * default Vonage attempts delivery for 72 hours, however the maximum effective + * value depends on the operator and is typically 24 - 48 hours. We recommend + * this value should be kept at its default or at least 30 minutes. + */ + public ttl?: number; + + /** + * Sends a file message to the RCS channel. + * + * @param {RCSFileParams} params - The parameters for creating a RCS file message. + * + * @example + * ```ts + * import { RCSFile } from '@vonage/messages'; + * + * const { messageUUID } = await messagesClient.send(new RCSFile({ + * to: TO_NUMBER, + * from: FROM_NUMBER, + * file: { + * url: 'https://example.com/image.pdf', + * }, + * clientRef: 'my-personal-reference', + * })); + * + * console.log(`Message sent successfully with UUID ${messageUUID}`); + * ``` + */ + public constructor(params: MessageParams & RCSFileParams) { + super(params); + this.ttl = params.ttl; + } +} diff --git a/packages/messages/lib/classes/RCS/RCSImage.ts b/packages/messages/lib/classes/RCS/RCSImage.ts new file mode 100644 index 00000000..6c2d2de2 --- /dev/null +++ b/packages/messages/lib/classes/RCS/RCSImage.ts @@ -0,0 +1,48 @@ +import { AbstractImageMessage } from '../AbstractImageMessage'; +import { RCSImageParams } from '../../types'; +import { Channels } from '../../enums'; + +/** + * Represents an image message for the RCS channel. + * + * @group RCS + */ +export class RCSImage extends AbstractImageMessage implements RCSImageParams { + /** + * The channel through which the message will be sent. Always `rcs` + */ + public channel: Channels.RCS = Channels.RCS; + + /** + * The duration in seconds the delivery of a message will be attempted. By + * default Vonage attempts delivery for 72 hours, however the maximum effective + * value depends on the operator and is typically 24 - 48 hours. We recommend + * this value should be kept at its default or at least 30 minutes. + */ + public ttl?: number; + + /** + * Send an RCS image message. + * + * @param {RCSImageParams} params - The parameters for creating the image message. + * @example + * ```ts + * import { RCSImage } from '@vonage/messages'; + * + * const { messageUUID } = await messagesClient.send(new RCSImage({ + * to: TO_NUMBER, + * from: FROM_NUMBER, + * image: { + * url: 'https://example.com/image.jpg', + * }, + * clientRef: 'my-personal-reference', + * })); + * + * console.log(`Message sent successfully with UUID ${messageUUID}`); + * ``` + */ + constructor(params: RCSImageParams) { + super(params); + this.ttl = params.ttl; + } +} diff --git a/packages/messages/lib/classes/RCS/RCSText.ts b/packages/messages/lib/classes/RCS/RCSText.ts new file mode 100644 index 00000000..e56405a3 --- /dev/null +++ b/packages/messages/lib/classes/RCS/RCSText.ts @@ -0,0 +1,47 @@ +import { AbstractTextMessage } from '../AbstractTextMessage'; +import { RCSTextParams } from '../../types'; +import { Channels } from '../../enums'; + +/** + * Represents a text message for the RCS channel. + * + * @group RCS + */ +export class RCSText extends AbstractTextMessage implements RCSTextParams { + /** + * The channel for this message (always 'rcs'). + */ + public channel: Channels.RCS = Channels.RCS; + + /** + * The duration in seconds the delivery of a message will be attempted. By + * default Vonage attempts delivery for 72 hours, however the maximum effective + * value depends on the operator and is typically 24 - 48 hours. We recommend + * this value should be kept at its default or at least 30 minutes. + */ + public ttl?: number; + + /** + * Sends a text message through the RCS channel. + * + * @param {RCSTextParams} params - The parameters for creating a RCS text message. + * + * @example + * ```ts + * import { RCSText } from '@vonage/messages'; + * + * const { messageUUID } = await messagesClient.send(new RCSText({ + * to: TO_NUMBER, + * from: FROM_NUMBER, + * text: 'Hello world', + * clientRef: 'my-personal-reference', + * })); + * + * console.log(`Message sent successfully with UUID ${messageUUID}`); + * ``` + */ + public constructor(params: RCSTextParams) { + super(params); + this.ttl = params.ttl; + } +} diff --git a/packages/messages/lib/classes/RCS/RCSVideo.ts b/packages/messages/lib/classes/RCS/RCSVideo.ts new file mode 100644 index 00000000..fdfbbd54 --- /dev/null +++ b/packages/messages/lib/classes/RCS/RCSVideo.ts @@ -0,0 +1,50 @@ +import { AbstractVideoMessage } from '../'; +import { RCSVideoParams } from '../../types'; +import { Channels } from '../../enums'; + +/** + * Represents an video message for the RCS channel. + * + * @group RCS + */ +export class RCSVideo extends AbstractVideoMessage implements RCSVideoParams { + /** + * The channel through which the message will be sent. Always `rcs` + */ + public channel: Channels.RCS; + + /** + * The duration in seconds the delivery of a message will be attempted. By + * default Vonage attempts delivery for 72 hours, however the maximum effective + * value depends on the operator and is typically 24 - 48 hours. We recommend + * this value should be kept at its default or at least 30 minutes. + */ + public ttl?: number; + + /** + * Send an RCS video message. + * + * @param {RCSVideoParams} params - The parameters for creating the video message. + * + * @example + * ```ts + * import { RCSVideo } from '@vonage/messages'; + * + * const { messageUUID } = await messagesClient.send(new RCSVideo({ + * to: TO_NUMBER, + * from: FROM_NUMBER, + * audio: { + * url: 'https://example.com/video.mp4', + * }, + * clientRef: 'my-personal-reference', + * })); + * + * console.log(`Message sent successfully with UUID ${messageUUID}`); + * ``` + */ + public constructor(params: RCSVideoParams) { + super(params); + this.channel = Channels.RCS; + this.ttl = params?.ttl; + } +} diff --git a/packages/messages/lib/classes/RCS/index.ts b/packages/messages/lib/classes/RCS/index.ts new file mode 100644 index 00000000..be7fa436 --- /dev/null +++ b/packages/messages/lib/classes/RCS/index.ts @@ -0,0 +1,5 @@ +export * from './RCSCustom'; +export * from './RCSFile'; +export * from './RCSImage'; +export * from './RCSText'; +export * from './RCSVideo'; diff --git a/packages/messages/lib/classes/index.ts b/packages/messages/lib/classes/index.ts index 8471013b..b2d91889 100644 --- a/packages/messages/lib/classes/index.ts +++ b/packages/messages/lib/classes/index.ts @@ -5,8 +5,9 @@ export * from './AbstractImageMessage'; export * from './AbstractTextMessage'; export * from './AbstractVcardMessage'; export * from './AbstractVideoMessage'; -export * from './MMS/index'; -export * from './Messenger/index'; -export * from './SMS/index'; -export * from './Viber/index'; -export * from './WhatsApp/index'; +export * from './MMS'; +export * from './Messenger'; +export * from './SMS'; +export * from './Viber'; +export * from './WhatsApp'; +export * from './RCS'; diff --git a/packages/messages/lib/enums/Channels.ts b/packages/messages/lib/enums/Channels.ts index b661182f..e01ccbaf 100644 --- a/packages/messages/lib/enums/Channels.ts +++ b/packages/messages/lib/enums/Channels.ts @@ -4,4 +4,5 @@ export enum Channels { SMS = 'sms', WHATSAPP = 'whatsapp', VIBER = 'viber_service', + RCS = 'rcs', } diff --git a/packages/messages/lib/messages.ts b/packages/messages/lib/messages.ts index 06b9c0e4..b5f1e4d1 100644 --- a/packages/messages/lib/messages.ts +++ b/packages/messages/lib/messages.ts @@ -3,7 +3,8 @@ import { VetchOptions } from '@vonage/vetch'; import { MessageSuccess, SendMessageParams, - MessageSuccessResponse, AnyChannel, + MessageSuccessResponse, + AnyChannel, } from './types'; import debug from 'debug'; @@ -11,9 +12,9 @@ const log = debug('vonage:messages'); /** * Client class to interact with the Messages API which enables users to manage - * send messages through various channels programmatically. + * send messages through various channels programmatically. * @see {@link https://developer.nexmo.com/en/messages/overview} - + * @group Client * * @example @@ -80,13 +81,15 @@ export class Messages extends Client { public async send( message: SendMessageParams | AnyChannel, ): Promise { + const data = Client.transformers.snakeCaseObjectKeys(message, true); + + if ('custom' in message) { + data.custom = message.custom; + } + const resp = await this.sendPostRequest( `${this.config.apiHost}/v1/messages`, - JSON.parse( - JSON.stringify( - Client.transformers.snakeCaseObjectKeys(message, true), - ), - ), + data, ); return { diff --git a/packages/messages/lib/types/Channels/MMS/MMSVcardParams.ts b/packages/messages/lib/types/Channels/MMS/MMSVcardParams.ts index d6f12315..bb539496 100644 --- a/packages/messages/lib/types/Channels/MMS/MMSVcardParams.ts +++ b/packages/messages/lib/types/Channels/MMS/MMSVcardParams.ts @@ -1,5 +1,5 @@ -import { MessageParams } from "../../MessageParams"; -import { MessageVcardType } from "../../MessageVcardType"; +import { MessageParams } from '../../MessageParams'; +import { MessageVcardType } from '../../MessageVcardType'; /** * Represents the parameters for sending a vCard message on the MMS channel. @@ -10,4 +10,10 @@ import { MessageVcardType } from "../../MessageVcardType"; * @group MMS * @category Parameters */ -export type MMSVcardParams = MessageParams & MessageVcardType; +export type MMSVcardParams = { + /** + * The amount of time in seconds the message will live for + */ + ttl?: number; +} & MessageParams & + MessageVcardType; diff --git a/packages/messages/lib/types/Channels/RCS/RCSCustomParams.ts b/packages/messages/lib/types/Channels/RCS/RCSCustomParams.ts new file mode 100644 index 00000000..05b9f749 --- /dev/null +++ b/packages/messages/lib/types/Channels/RCS/RCSCustomParams.ts @@ -0,0 +1,25 @@ +import { MessageParams } from '../../MessageParams'; +import { Channels } from '../../../enums'; + +/** + * Represents the parameters for sending a custom message using RCS. + */ +export type RCSCustomParams = MessageParams & { + /** + * The channel to send to. You must provide `rcs` in this field. + */ + channel?: Channels.RCS; + + /** + * A custom payload. The schema of a custom object can vary widely. + */ + custom: Record; + + /** + * The duration in seconds the delivery of a message will be attempted. By + * default Vonage attempts delivery for 72 hours, however the maximum + * effective value depends on the operator and is typically 24 - 48 hours. + * We recommend this value should be kept at its default or at least 30 minutes. + */ + ttl?: number; +}; diff --git a/packages/messages/lib/types/Channels/RCS/RCSFileParams.ts b/packages/messages/lib/types/Channels/RCS/RCSFileParams.ts new file mode 100644 index 00000000..32b26bac --- /dev/null +++ b/packages/messages/lib/types/Channels/RCS/RCSFileParams.ts @@ -0,0 +1,20 @@ +import { MessageParamsFile } from '../../MessageParamsFile'; +import { Channels } from '../../../enums'; + +/** + * Represents the parameters for sending a file message using RCS. + */ +export type RCSFileParams = MessageParamsFile & { + /** + * The channel to send to. You must provide `rcs` in this field. + */ + channel?: Channels.RCS; + + /** + * The duration in seconds the delivery of a message will be attempted. By + * default Vonage attempts delivery for 72 hours, however the maximum + * effective value depends on the operator and is typically 24 - 48 hours. + * We recommend this value should be kept at its default or at least 30 minutes. + */ + ttl?: number; +}; diff --git a/packages/messages/lib/types/Channels/RCS/RCSImageParams.ts b/packages/messages/lib/types/Channels/RCS/RCSImageParams.ts new file mode 100644 index 00000000..634aa044 --- /dev/null +++ b/packages/messages/lib/types/Channels/RCS/RCSImageParams.ts @@ -0,0 +1,12 @@ +import { MessageParamsImage } from '../../MessageParamsImage'; +import { Channels } from '../../../enums'; + +/** + * Represents the parameters for sending an image message using RCS. + */ +export type RCSImageParams = MessageParamsImage & { + /** + * The channel to send to. You must provide `rcs` in this field. + */ + channel?: Channels.RCS; +}; diff --git a/packages/messages/lib/types/Channels/RCS/RCSTextParams.ts b/packages/messages/lib/types/Channels/RCS/RCSTextParams.ts new file mode 100644 index 00000000..405dc9be --- /dev/null +++ b/packages/messages/lib/types/Channels/RCS/RCSTextParams.ts @@ -0,0 +1,25 @@ +import { MessageParams } from '../../MessageParams'; +import { Channels } from '../../../enums'; + +/** + * Represents the parameters for sending a text message using RCS. + */ +export type RCSTextParams = MessageParams & { + /** + * The channel to send to. You must provide `rcs` in this field. + */ + channel?: Channels.RCS; + + /** + * The text of the message to send. Limited to 3072 characters, including unicode. + */ + text: string; + + /** + * The duration in seconds the delivery of a message will be attempted. By + * default Vonage attempts delivery for 72 hours, however the maximum + * effective value depends on the operator and is typically 24 - 48 hours. + * We recommend this value should be kept at its default or at least 30 minutes. + */ + ttl?: number; +}; diff --git a/packages/messages/lib/types/Channels/RCS/RCSVideoParams.ts b/packages/messages/lib/types/Channels/RCS/RCSVideoParams.ts new file mode 100644 index 00000000..2716029d --- /dev/null +++ b/packages/messages/lib/types/Channels/RCS/RCSVideoParams.ts @@ -0,0 +1,23 @@ +import { Channels } from '../../../enums'; +import { MessageParams } from '../../MessageParams'; +import { MessageVideoType } from '../../MessageVideoType'; + +/** + * Represents the parameters for sending a video message using RCS. + */ +export type RCSVideoParams = MessageParams & { + video: MessageVideoType; + + /** + * The channel to send to. You must provide `rcs` in this field. + */ + channel?: Channels.RCS; + + /** + * The duration in seconds the delivery of a message will be attempted. By + * default Vonage attempts delivery for 72 hours, however the maximum + * effective value depends on the operator and is typically 24 - 48 hours. + * We recommend this value should be kept at its default or at least 30 minutes. + */ + ttl?: number; +}; diff --git a/packages/messages/lib/types/Channels/RCS/index.ts b/packages/messages/lib/types/Channels/RCS/index.ts new file mode 100644 index 00000000..d8df3e63 --- /dev/null +++ b/packages/messages/lib/types/Channels/RCS/index.ts @@ -0,0 +1,18 @@ +import { RCSCustomParams } from './RCSCustomParams'; +import { RCSFileParams } from './RCSFileParams'; +import { RCSImageParams } from './RCSImageParams'; +import { RCSTextParams } from './RCSTextParams'; +import { RCSVideoParams } from './RCSVideoParams'; + +export * from './RCSCustomParams'; +export * from './RCSFileParams'; +export * from './RCSImageParams'; +export * from './RCSTextParams'; +export * from './RCSVideoParams'; + +export type AnyRCSChannel = + | RCSCustomParams + | RCSFileParams + | RCSImageParams + | RCSTextParams + | RCSVideoParams; diff --git a/packages/messages/lib/types/Channels/WhatsApp/WhatsAppAudioParams.ts b/packages/messages/lib/types/Channels/WhatsApp/WhatsAppAudioParams.ts index 8c31b616..a0f94927 100644 --- a/packages/messages/lib/types/Channels/WhatsApp/WhatsAppAudioParams.ts +++ b/packages/messages/lib/types/Channels/WhatsApp/WhatsAppAudioParams.ts @@ -7,4 +7,10 @@ import { WhatsAppParams } from './WhatsAppParams'; * @group WhatsApp * @category Parameters */ -export type WhatsAppAudioParams = WhatsAppParams & MessageParamsAudio; +export type WhatsAppAudioParams = { + /** + * The amount of time in seconds the message will live for + */ + ttl?: number; +} & WhatsAppParams & + MessageParamsAudio; diff --git a/packages/messages/lib/types/Channels/WhatsApp/WhatsAppVideoParams.ts b/packages/messages/lib/types/Channels/WhatsApp/WhatsAppVideoParams.ts index d5bf0bcf..2af0a648 100644 --- a/packages/messages/lib/types/Channels/WhatsApp/WhatsAppVideoParams.ts +++ b/packages/messages/lib/types/Channels/WhatsApp/WhatsAppVideoParams.ts @@ -7,4 +7,10 @@ import { WhatsAppParams } from './WhatsAppParams'; * @group WhatsApp * @category Parameters */ -export type WhatsAppVideoParams = WhatsAppParams & MessageParamsVideo; +export type WhatsAppVideoParams = { + /** + * The amount of time in seconds the message will live for + */ + ttl?: number; +} & WhatsAppParams & + MessageParamsVideo; diff --git a/packages/messages/lib/types/Channels/index.ts b/packages/messages/lib/types/Channels/index.ts index c7b82636..f42e9b97 100644 --- a/packages/messages/lib/types/Channels/index.ts +++ b/packages/messages/lib/types/Channels/index.ts @@ -1,21 +1,25 @@ -import { AnyMessengerChannel } from "./Messenger"; -import { AnyMMSChannel } from "./MMS"; -import { AnyViberChannel } from "./Viber"; -import { AnyWhatsAppChannel } from "./WhatsApp"; -import { SMSChannel } from "./SMSParams"; +import { AnyMessengerChannel } from './Messenger'; +import { AnyMMSChannel } from './MMS'; +import { AnyViberChannel } from './Viber'; +import { AnyWhatsAppChannel } from './WhatsApp'; +import { SMSChannel } from './SMSParams'; +import { AnyRCSChannel } from './RCS'; export * from './Messenger'; export * from './MMS'; export * from './Viber'; export * from './WhatsApp'; export * from './SMSParams'; +export * from './RCS'; /** * Represents a union type that can be any of the specific channel message * parameters or configurations, including Messenger, MMS, Viber, WhatsApp, or SMS. */ -export type AnyChannel = AnyMessengerChannel -| AnyMMSChannel -| AnyViberChannel -| AnyWhatsAppChannel -| SMSChannel +export type AnyChannel = + | AnyMessengerChannel + | AnyMMSChannel + | AnyViberChannel + | AnyWhatsAppChannel + | SMSChannel + | AnyRCSChannel; diff --git a/packages/messages/lib/types/MessageParamsImage.ts b/packages/messages/lib/types/MessageParamsImage.ts index abe502ff..a37f09b6 100644 --- a/packages/messages/lib/types/MessageParamsImage.ts +++ b/packages/messages/lib/types/MessageParamsImage.ts @@ -9,4 +9,9 @@ export type MessageParamsImage = { * The image attachment content. */ image: MessageImageType; + + /** + * The amount of time in seconds the message will live for + */ + ttl?: number; } & MessageParams; diff --git a/packages/messages/lib/types/Requests/MMSImageRequest.ts b/packages/messages/lib/types/Requests/MMSImageRequest.ts index fb52ab8f..4b1a3b6f 100644 --- a/packages/messages/lib/types/Requests/MMSImageRequest.ts +++ b/packages/messages/lib/types/Requests/MMSImageRequest.ts @@ -48,4 +48,9 @@ export type MMSImageRequest = { * The channel through which the message will be sent, which is 'mms' for MMS. */ channel: 'mms'; + + /** + * The amount of time in seconds the message will live for + */ + ttl?: number; } diff --git a/packages/messages/lib/types/Requests/WhatsAppImageRequest.ts b/packages/messages/lib/types/Requests/WhatsAppImageRequest.ts index 499a6e1b..f8d25061 100644 --- a/packages/messages/lib/types/Requests/WhatsAppImageRequest.ts +++ b/packages/messages/lib/types/Requests/WhatsAppImageRequest.ts @@ -48,4 +48,9 @@ export type WhatsAppImageRequest = { * The channel through which the message will be sent, which is 'whatsapp' for WhatsApp. */ channel: 'whatsapp'; -} + + /** + * The amount of time in seconds the message will live for + */ + ttl?: number; +}; diff --git a/packages/messages/package.json b/packages/messages/package.json index 47c4962b..5513938d 100644 --- a/packages/messages/package.json +++ b/packages/messages/package.json @@ -47,14 +47,10 @@ "prepublishOnly": "npm run build" }, "dependencies": { - "@vonage/auth": "^1.10.0", "@vonage/server-client": "^1.12.0", "@vonage/vetch": "^1.7.1", "debug": "^4.3.4" }, - "devDependencies": { - "nock": "^13.3.4" - }, "publishConfig": { "directory": "dist" }