Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEVEXP-248: Voice API - Generate models #3

Merged
merged 5 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/verification/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const credentials: SinchClientParameters = {
const sinch = new SinchClient(credentials);

const requestData: StartVerificationRequestData = {
InitiateVerificationResource: {
initiateVerificationRequestBody: {
identity: {
type: 'number',
endpoint: '+17813334444',
Expand All @@ -67,7 +67,7 @@ const verificationInitResponse: InitiateVerificationResponse

### Standalone

The SDK can be used standalone if you need to use only the Verification APIs. You will need to import the `XTimestampRequest` and `SigningRequest` plugins from the `@sinch/sdk-client` package to manage the authentication.
The SDK can be used standalone if you need to use only the Verification APIs.

```typescript
import {
Expand All @@ -88,7 +88,7 @@ const credentials: SinchClientParameters = {
const verification = new Verification(credentials);

const requestData: StartVerificationRequestData = {
InitiateVerificationResource: {
initiateVerificationRequestBody: {
identity: {
type: 'number',
endpoint: '+17813334444',
Expand Down
1 change: 0 additions & 1 deletion packages/verification/src/models/v1/error/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/verification/src/models/v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export * from './callout-verification-report-request-callout';
export * from './callout-verification-report-response';
export * from './data-initiate-verification-response';
export * from './data-initiate-verification-response-seamless';
export * from './error';
export * from './verification-error';
export * from './flash-call-initiate-verification-response';
export * from './flash-call-initiate-verification-response-flash-call';
export * from './flash-call-request-event-response';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { VerificationError } from './verification-error';
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Model: VerificationError
*
* THIS FILE HAS BEEN AUTOMATICALLY GENERATED. DO NOT EDIT.
*
*/


export interface VerificationError {

/** A summary of the HTTP error code and error type. */
status?: string;
/** The HTTP error code. */
errorCode?: string;
/** A simple description of the cause of the error. */
message?: string;
/** If applicable, a reference ID for support to use with diagnosing the error. */
reference?: string;
}


Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { VerificationsApi, ReportVerificationByIdRequestData, ReportVerificationByIdentityRequestData, StartVerificationRequestData } from './verifications-api';
import { InitiateVerificationResponse, VerificationResponse } from '../../../models';
import { VerificationsApi, ReportVerificationByIdRequestData, ReportVerificationByIdentityRequestData, StartVerificationRequestData } from './verifications-api';

export class VerificationsApiFixture implements Partial<Readonly<VerificationsApi>> {

/**
* Fixture associated to function reportVerificationById
*/
public reportById: jest.Mock<Promise<VerificationResponse>, [ReportVerificationByIdRequestData]>
= jest.fn();
public reportById: jest.Mock<Promise<VerificationResponse>, [ReportVerificationByIdRequestData]> = jest.fn();
/**
* Fixture associated to function reportVerificationByIdentity
*/
Expand All @@ -16,6 +15,5 @@ export class VerificationsApiFixture implements Partial<Readonly<VerificationsAp
/**
* Fixture associated to function startVerification
*/
public start: jest.Mock<Promise<InitiateVerificationResponse>, [StartVerificationRequestData]>
= jest.fn();
public start: jest.Mock<Promise<InitiateVerificationResponse>, [StartVerificationRequestData]> = jest.fn();
}
136 changes: 136 additions & 0 deletions packages/voice/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# Sinch Voice SDK for Node.js

This package contains the Sinch Voice SDK for Node.js for use with [Sinch APIs](https://developers.sinch.com/). To use it, you will need a Sinch account. Please [sign up](https://dashboard.sinch.com/signup) or [log in](https://dashboard.sinch.com/login) if you already have one.

<span style="color:red; font-weight:bold">Warning:</span>
**This SDK is currently available for preview purposes only. It should not be used in production environments.**


## Installation

We recommend to use this SDK as part of the `@sinch/sdk-core` package as it will take care about the authentication plugins to use.

However, it's still possible to use this SDK standalone is you need to access the Verification API only.

### With NPM

```bash
npm install @sinch/voice
```

### With Yarn

```bash
yarn add @sinch/voice
```

## Usage

### Credentials

The `Voice` API uses the Application Signed Request to authenticate against the server. You will need to provide the following credentials:
- applicationKey: one of the application keys that can be found in [Apps section](https://dashboard.sinch.com/voice/apps) of the Voice dashboard
- applicationSecret: the corresponding secret that can be found at the same place

### As part of the Sinch SDK

If you are using this SDK as part of the Sinch SDK (`@sinch/sdk-core`) you can access it as the `voice` property of the client that you would have instantiated.

```typescript
import {
CalloutsRequestData,
GetCalloutResponseObj,
SinchClient,
SinchClientParameters,
} from '@sinch/sdk-core';

const credentials: SinchClientParameters = {
applicationKey: 'APPLICATION_ID',
applicationSecret: 'APPLICATION_SECRET',
};
const sinch = new SinchClient(credentials);

const requestData: CalloutsRequestData = {
calloutRequestBody: {
method: 'ttsCallout',
ttsCallout: {
destination: {
type: 'number',
endpoint: '+14045005000',
},
cli: '+14045001000',
locale: 'en-US',
text: 'Hello, this is a call from Sinch.',
},
},
};

// Access the 'voice' domain registered on the Sinch Client
const calloutResponse: GetCalloutResponseObj
= await sinch.voice.callouts.callouts(requestData);
```

### Standalone

The SDK can be used standalone if you need to use only the Voice APIs.

```typescript
import {
SinchClientParameters
} from '@sinch/sdk-client';
import {
CalloutsRequestData,
GetCalloutResponseObj,
Voice,
} from '@sinch/voice';

const credentials: SinchClientParameters = {
applicationKey: 'APPLICATION_ID',
applicationSecret: 'APPLICATION_SECRET',
};

// Declare the 'verification' in a standalone way
const voice = new Voice(credentials);

const requestData: CalloutsRequestData = {
calloutRequestBody: {
method: 'ttsCallout',
ttsCallout: {
destination: {
type: 'number',
endpoint: '+14045005000',
},
cli: '+14045001000',
locale: 'en-US',
text: 'Hello, this is a call from Sinch.',
},
},
};

// Use the standalone declaration of the 'verification' domain
const calloutResponse: GetCalloutResponseObj
= await voice.callouts.callouts(requestData);
```

## Promises

All the methods that interact with the Sinch APIs use Promises. You can use `await` in an `async` method to wait for the response or you can resolve them yourself with `then()` / `catch()`.

```typescript
// Method 1: Wait for the Promise to complete
let calloutResponse: GetCalloutResponseObj;
try {
calloutResponse = await sinch.voice.callouts.callouts(requestData);
console.log(`callId = ${response.callId}`);
} catch (error: any) {
console.error(`ERROR ${error.statusCode}: Impossible to make a call out to the number ${requestData.calloutRequestBody.ttsCallout.destination.endpoint}`);
}

// Method 2: Resolve the promise
sinch.voice.callouts.callouts(requestData)
.then(response => console.log(`callId = ${response.callId}`))
.catch(error => console.error(`ERROR ${error.statusCode}: Impossible to make a call out to the number ${requestData.calloutRequestBody.ttsCallout.destination.endpoint}`));
```

## Contact
Developer Experience team: [[email protected]](mailto:[email protected])
37 changes: 37 additions & 0 deletions packages/voice/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "@sinch/voice",
"version": "0.0.0",
"description": "Sinch Voice API",
"homepage": "",
"repository": {
"type": "git",
"url": ""
},
"license": "Apache-2.0",
"author": "Sinch",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.js"
}
},
"directories": {
"src": "dist",
"test": "tests"
},
"files": ["/dist"],
"scripts": {
"build": "yarn run clean && yarn run compile",
"clean": "rimraf dist tsconfig.tsbuildinfo tsconfig.build.tsbuildinfo",
"compile": "tsc -p tsconfig.build.json && tsc -p tsconfig.tests.json && rimraf dist/tests tsconfig.build.tsbuildinfo"
},
"dependencies": {
"@sinch/sdk-client": "^0.0.0"
},
"devDependencies": {},
"publishConfig": {
"directory": "dist"
}
}
1 change: 1 addition & 0 deletions packages/voice/src/models/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './v1';
22 changes: 22 additions & 0 deletions packages/voice/src/models/v1/ace-request-amd/ace-request-amd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Model: AceRequestAmd
*
* THIS FILE HAS BEEN AUTOMATICALLY GENERATED. DO NOT EDIT.
*
*/


/**
* If [Answering Machine Detection](/docs/voice/api-reference/amd_v2) (AMD) is enabled, this object contains information about whether the call was answered by a machine.
*/
export interface AceRequestAmd {

/** The determination by the system of who answered the call. */
status?: string;
/** The reason that the system used to determine who answered the call. */
reason?: string;
/** The length of the call. */
duration?: number;
}


1 change: 1 addition & 0 deletions packages/voice/src/models/v1/ace-request-amd/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { AceRequestAmd } from './ace-request-amd';
29 changes: 29 additions & 0 deletions packages/voice/src/models/v1/ace-request/ace-request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Model: AceRequest
*
* THIS FILE HAS BEEN AUTOMATICALLY GENERATED. DO NOT EDIT.
*
*/

import { AceRequestAmd } from '../ace-request-amd';

/**
* The request body of an Answered Call Event.
*/
export interface AceRequest {

/** Must have the value `ace`. */
event?: string;
/** The unique ID assigned to this call. */
callId?: string;
/** The timestamp in UTC format. */
timestamp?: Date;
/** The current API version. */
version?: number;
/** A string that can be used to pass custom information related to the call. */
custom?: string;
/** @see AceRequestAmd */
amd?: AceRequestAmd;
}


1 change: 1 addition & 0 deletions packages/voice/src/models/v1/ace-request/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { AceRequest } from './ace-request';
20 changes: 20 additions & 0 deletions packages/voice/src/models/v1/call-header/call-header.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Model: CallHeader
*
* THIS FILE HAS BEEN AUTOMATICALLY GENERATED. DO NOT EDIT.
*
*/


/**
* Call Headers can be used to pass custom data from a Sinch SDK client to another, or specified in an ICE response to be made available to the receiving client. Further, if Call Headers is specified they will be available in ICE and DICE events.
*/
export interface CallHeader {

/** The call header key of the key value pair. */
key?: string;
/** The call header value of the key value pair. */
value?: string;
}


1 change: 1 addition & 0 deletions packages/voice/src/models/v1/call-header/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { CallHeader } from './call-header';
28 changes: 28 additions & 0 deletions packages/voice/src/models/v1/callout-request/callout-request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Model: CalloutRequest
*
* THIS FILE HAS BEEN AUTOMATICALLY GENERATED. DO NOT EDIT.
*
*/

import { ConferenceCalloutRequest } from '../conference-callout-request';
import { CustomCalloutRequest } from '../custom-callout-request';
import { TtsCalloutRequest } from '../tts-callout-request';

/**
* Currently three types of callouts are supported: conference callouts, text-to-speech callouts and custom callouts. The custom callout is the most flexible, but text-to-speech and conference callouts are more convenient.
*/
export interface CalloutRequest {

/** Sets the type of callout. */
method: MethodEnum;
/** @see ConferenceCalloutRequest */
conferenceCallout?: ConferenceCalloutRequest;
/** @see TtsCalloutRequest */
ttsCallout?: TtsCalloutRequest;
/** @see CustomCalloutRequest */
customCallout?: CustomCalloutRequest;
}

export type MethodEnum = 'conferenceCallout' | 'ttsCallout' | 'customCallout';

1 change: 1 addition & 0 deletions packages/voice/src/models/v1/callout-request/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { CalloutRequest } from './callout-request';
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Model: ConferenceCalloutRequestConferenceDtmfOptions
*
* THIS FILE HAS BEEN AUTOMATICALLY GENERATED. DO NOT EDIT.
*
*/


/**
* Options to control how DTMF signals are used by the participant in the conference. For information on how to use this feature, read more [here](../../../conference-dtmf).
*/
export interface ConferenceCalloutRequestConferenceDtmfOptions {

/** Determines what DTMF mode the participant will use in the call. */
mode?: string;
/** The maximum number of accepted digits before sending the collected input via a PIE callback. The default value is `1`. If the value is greater than `1`, the PIE callback is triggered by one of the three following events: - No additional digit is entered before the `timeoutMills` timeout period has elapsed. - The `#` character is entered. - The maximum number of digits has been entered. */
maxDigits?: number;
/** The number of milliseconds that the system will wait between entered digits before triggering the PIE callback. The default value is `3000`. */
timeoutMills?: number;
}


Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { ConferenceCalloutRequestConferenceDtmfOptions } from './conference-callout-request-conference-dtmf-options';

Check failure on line 1 in packages/voice/src/models/v1/conference-callout-request-conference-dtmf-options/index.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

This line has a length of 122. Maximum allowed is 120

Check failure on line 1 in packages/voice/src/models/v1/conference-callout-request-conference-dtmf-options/index.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

This line has a length of 122. Maximum allowed is 120

Check failure on line 1 in packages/voice/src/models/v1/conference-callout-request-conference-dtmf-options/index.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

This line has a length of 122. Maximum allowed is 120
Loading
Loading