Skip to content

Commit

Permalink
feat: updating messages to be non breaking (#813)
Browse files Browse the repository at this point in the history
  • Loading branch information
manchuck authored Apr 4, 2023
1 parent f10f9e4 commit 555ea86
Show file tree
Hide file tree
Showing 37 changed files with 1,442 additions and 67 deletions.
63 changes: 10 additions & 53 deletions packages/messages/README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,22 @@
# Vonage Messages SDK for Node.js

![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/vonage/vonage-node-sdk/Vonage/3.x?logo=github&style=flat-square&label=Workflow%20Build) [![Codecov](https://img.shields.io/codecov/c/github/vonage/vonage-node-sdk?label=Codecov&logo=codecov&style=flat-square)](https://codecov.io/gh/Vonage/vonage-server-sdk) ![Latest Release](https://img.shields.io/github/v/release/vonage/vonage-node-sdk?logo=npm&style=flat-square)

[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg?style=flat-square)](../../CODE_OF_CONDUCT.md) [![License](https://img.shields.io/npm/l/@vonage/server-sdk?label=License&style=flat-square)][../../LICENSE.TXT]
![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/Vonage/vonage-node-sdk/ci.yml?branch=3.x) [![Codecov](https://img.shields.io/codecov/c/github/vonage/vonage-node-sdk?label=Codecov&logo=codecov&style=flat-square)](https://codecov.io/gh/Vonage/vonage-server-sdk) ![Latest Release](https://img.shields.io/github/v/release/vonage/vonage-node-sdk?logo=npm&style=flat-square) [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg?style=flat-square)](../../CODE_OF_CONDUCT.md) [![License](https://img.shields.io/npm/l/@vonage/server-sdk?label=License&style=flat-square)](../../LICENSE.TXT)

<img src="https://developer.nexmo.com/images/logos/vbc-logo.svg" height="48px" alt="Vonage" />

This is the Vonage Messages SDK for Node.js for use
with [Vonage APIs](https://www.vonage.com/). To use it you will need a Vonage
account. Sign up [for free at vonage.com][signup].

We recommend using this package as part of the
overall [`@vonage/server-sdk` package](https://github.com/vonage/vonage-node-sdk)
.
This is the Vonage Messages SDK for Node.js for use with [Vonage APIs](https://www.vonage.com/). To use it you will need a Vonage account. Sign up [for free][signup] at vonage.com.

For full API documentation refer
to [developer.nexmo.com](https://developer.nexmo.com/).
For full API documentation refer to [developer.nexmo.com](https://developer.nexmo.com/).

* [Installation](#installation)
* [Constructor](#constructor)
* [Callbacks](#callbacks)
* [Testing](#testing)
* [Examples](#examples)
* [Supported APIs](#supported-apis)
* [Usage](#usage)
* [Promises](#promises)

## Installation

We recommend using this SDK as part of the
overall [`@vonage/server-sdk` package](https://github.com/vonage/vonage-node-sdk)
. Please see the main package for installation.
We recommend using this SDK as part of the overall [`@vonage/server-sdk` package](https://github.com/vonage/vonage-node-sdk). Please see the main package for installation.

You can also use this SDK standalone if you only need access to just the
Messages API.
You can also use this SDK standalone if you only need access to just the Messages API.

### With NPM

Expand All @@ -45,12 +30,11 @@ npm install @vonage/messages
yarn add @vonage/messages
```

## Using the Vonage Messages SDK
## Usage

### As part of the Vonage Server SDK

If you are using this SDK as part of the Vonage Server SDK, you can access it as
the `messages` property off of the client that you instantiate.
If you are using this SDK as part of the Vonage Server SDK, you can access it as the `messages` property off of the client that you instantiate.

```js
const {Vonage} = require('@vonage/server-sdk');
Expand Down Expand Up @@ -94,36 +78,9 @@ const messagesClient = new Messages(new Auth({
}), options);
```

* `apiKey` - API Key from Vonage API. If `applicationId` and `privateKey` are
present, `apiKey` is optional.
* `apiSecret` - API Secret from Vonage API. If `applicationId` and `privateKey`
are present, `apiSecret` is optional.
* `applicationId` - (optional) The Vonage API Application ID to be used when
creating JWTs.
* `signature` - (optional) [deprecated] An object containg the secret and HASH
algroithm to use for signing the request.
* `privateKey` - (optional) The Private Key to be used when creating JWTs. You
can specify the key as any of the following:
* A String containing the path to the key file on disk.
* A String containing the key itself.
* A Buffer containing the file contents.
* `options` is an object that can contain:

```json5
{
// Set a custom timeout for requests to Nexmo in milliseconds. Defaults to the standard for Node http requests, which is 120,000 ms.
timeout: integer,
// Set a custom host for requests instead of api.nexmo.com
apiHost: string,
// Set a custom host for requests instead of rest.nexmo.com
restHost: string
}
```

## Promises

Most methods that interact with the Vonage API uses Promises. You can either
resolve these yourself, or use `await` to
Most methods that interact with the Vonage API uses Promises. You can either resolve these yourself, or use `await` to
wait for a response.

```js
Expand Down
233 changes: 233 additions & 0 deletions packages/messages/__tests__/__dataSets__/messenger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ import {
MessengerFileParams,
} from '../../lib';

import { Audio } from '../../lib/classes/Messenger/Audio';
import { File } from '../../lib/classes/Messenger/File';
import { Image } from '../../lib/classes/Messenger/Image';
import { Text } from '../../lib/classes/Messenger/Text';
import { Video } from '../../lib/classes/Messenger/Video';
import { MessageCategory } from '../../lib/enums/Messenger/MessageCategory';

export default [
{
label: 'send Messenger text',
Expand Down Expand Up @@ -95,6 +102,48 @@ export default [
messageUUID: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a',
} as MessageSuccess,
},
{
label: 'send Messenger text with old class',
request: [
'/v1/messages',
'POST',
{
from: '12126875309',
to: '14152739164',
text: 'too many secrets',
channel: 'messenger',
message_type: 'text',
client_ref: 'my-ref',
messenger: {
category: MessengerCategory.RESPONSE,
tag: MessengerTags.ACCOUNT_UPDATE,
},
} as MessengerTextRequest,
],
response: [
200,
{
message_uuid: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a',
},
],
method: 'POST',
clientMethod: 'send',
parameters: [
new Text(
'too many secrets', // text
'14152739164', // to
'12126875309', // from
{
category: MessageCategory.RESPONSE,
tag: MessengerTags.ACCOUNT_UPDATE,
},
'my-ref', // client ref
),
],
expected: {
messageUUID: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a',
} as MessageSuccess,
},
{
label: 'send Messenger image',
request: [
Expand Down Expand Up @@ -177,6 +226,52 @@ export default [
messageUUID: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a',
} as MessageSuccess,
},
{
label: 'send Messenger image with old class',
request: [
'/v1/messages',
'POST',
{
from: '12126875309',
to: '14152739164',
channel: 'messenger',
client_ref: 'my-ref',
message_type: 'image',
image: {
url: 'https://example.com',
},
messenger: {
category: MessengerCategory.RESPONSE,
tag: MessengerTags.ACCOUNT_UPDATE,
},
} as MessengerImageRequest,
],
response: [
200,
{
message_uuid: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a',
},
],
method: 'POST',
clientMethod: 'send',
parameters: [
new Image(
{
url: 'https://example.com',
},
'14152739164', // to
'12126875309', // from
{
category: MessageCategory.RESPONSE,
tag: MessengerTags.ACCOUNT_UPDATE,
},
'my-ref', // client ref
),
],
expected: {
messageUUID: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a',
} as MessageSuccess,
},
{
label: 'send Messenger audio',
request: [
Expand Down Expand Up @@ -259,6 +354,52 @@ export default [
messageUUID: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a',
} as MessageSuccess,
},
{
label: 'send Messenger audio with old class',
request: [
'/v1/messages',
'POST',
{
from: '12126875309',
to: '14152739164',
channel: 'messenger',
message_type: 'audio',
client_ref: 'my-ref',
audio: {
url: 'https://example.com',
},
messenger: {
category: MessengerCategory.RESPONSE,
tag: MessengerTags.ACCOUNT_UPDATE,
},
} as MessengerAudioRequest,
],
response: [
200,
{
message_uuid: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a',
},
],
method: 'POST',
clientMethod: 'send',
parameters: [
new Audio(
{
url: 'https://example.com',
},
'14152739164', // to
'12126875309', // from
{
category: MessageCategory.RESPONSE,
tag: MessengerTags.ACCOUNT_UPDATE,
},
'my-ref',
),
],
expected: {
messageUUID: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a',
} as MessageSuccess,
},
{
label: 'send Messenger video',
request: [
Expand Down Expand Up @@ -341,6 +482,52 @@ export default [
messageUUID: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a',
} as MessageSuccess,
},
{
label: 'send Messenger video with old class',
request: [
'/v1/messages',
'POST',
{
from: '12126875309',
to: '14152739164',
channel: 'messenger',
message_type: 'video',
client_ref: 'my-ref',
video: {
url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
},
messenger: {
category: MessengerCategory.RESPONSE,
tag: MessengerTags.ACCOUNT_UPDATE,
},
} as MessengerVideoRequest,
],
response: [
200,
{
message_uuid: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a',
},
],
method: 'POST',
clientMethod: 'send',
parameters: [
new Video(
{
url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
},
'14152739164', // to
'12126875309', // from
{
category: MessengerCategory.RESPONSE,
tag: MessengerTags.ACCOUNT_UPDATE,
},
'my-ref', // client ref
),
],
expected: {
messageUUID: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a',
} as MessageSuccess,
},
{
label: 'send Messenger file',
request: [
Expand Down Expand Up @@ -423,4 +610,50 @@ export default [
messageUUID: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a',
} as MessageSuccess,
},
{
label: 'send Messenger file with old class',
request: [
'/v1/messages',
'POST',
{
from: '12126875309',
to: '14152739164',
channel: 'messenger',
message_type: 'file',
client_ref: 'my-ref',
file: {
url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
},
messenger: {
category: MessengerCategory.RESPONSE,
tag: MessengerTags.ACCOUNT_UPDATE,
},
} as MessengerFileRequest,
],
response: [
200,
{
message_uuid: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a',
},
],
method: 'POST',
clientMethod: 'send',
parameters: [
new File(
{
url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
},
'14152739164', // to
'12126875309', // from
{
category: MessengerCategory.RESPONSE,
tag: MessengerTags.ACCOUNT_UPDATE,
},
'my-ref', // client ref
),
],
expected: {
messageUUID: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a',
} as MessageSuccess,
},
];
Loading

0 comments on commit 555ea86

Please sign in to comment.