Skip to content

Commit

Permalink
add bridge api (#43)
Browse files Browse the repository at this point in the history
* add bridge api

* add bridge api

* add test bridge api

Co-authored-by: una.feng <[email protected]>
  • Loading branch information
Una1219 and una.feng authored Apr 18, 2022
1 parent 495edfa commit c6d7142
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 13 deletions.
15 changes: 15 additions & 0 deletions src/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ export interface AnswerParams {
deviceId: string;
}

export interface BridgeParams {
telephonySessionId: string;
partyId: string;
}

export interface IgnoreParams {
deviceId: string;
}
Expand Down Expand Up @@ -454,6 +459,16 @@ export class Session extends EventEmitter {
return response.json();
}

async bridge(params: BridgeParams) {
const response = await this._sdk.platform().post(
`/restapi/v1.0/account/~/telephony/sessions/${this._data.id}/parties/${this.party.id}/bridge`,
params,
undefined,
this.requestOptions,
);
return response.json();
}

async park() {
const response = await this._sdk.platform().post(
`/restapi/v1.0/account/~/telephony/sessions/${this._data.id}/parties/${this.party.id}/park`,
Expand Down
35 changes: 35 additions & 0 deletions test/mock/data/telephonySessionBridge.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"accountId" : "153906004",
"attributes" : {},
"brandId" : "1210",
"direction" : "Outbound",
"extensionId" : "153906004",
"from" : {
"deviceId" : "30091004",
"extensionId" : "153906004",
"name" : "Klay test1",
"phoneNumber" : "+18445585565"
},
"id" : "p-a4a0d82257c9fz1803a3e5601z9856ea0000-1",
"muted" : false,
"owner" : {
"accountId" : "153906004",
"brandId" : "1210",
"extensionId" : "153906004"
},
"standAlone" : false,
"status" : {
"code" : "Gone",
"peerId" : {
"partyId" : "p-a4a0d812557c5z1803a3eee14z97f6290000-1",
"sessionId" : "s-a4a0d812557c5z1803a3eee14z97f6290000"
},
"reason" : "AttendedTransfer"
},
"to" : {
"extensionId" : "248452004",
"name" : "Something1 New1",
"phoneNumber" : "+18443223062"
}
}

36 changes: 27 additions & 9 deletions test/mock/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import * as fetchMock from 'fetch-mock';

import { SDK } from '@ringcentral/sdk';

import * as extensionBody from './data/extensionInfo.json';
import * as accountPresenceBody from './data/accountPresence.json';
import * as deviceBody from './data/device.json';
import * as extensionBody from './data/extensionInfo.json';
import * as presenceBody from './data/presence.json';
import * as accountPresenceBody from './data/accountPresence.json';
import * as telephonySessionBody from './data/telephonySessionOutbound.json';
import * as telephonySessionCallOutBody from './data/telephonySessionCallOut.json';
import * as telephonyConferenceBody from './data/telephonyConference.json';
import * as telephonySessionPartyBody from './data/telephonySessionOutboundParty.json';
import * as telephonySessionPartyForwardBody from './data/telephonySessionInboundPartyForward.json';
import * as telephonySessionPartyTransferBody from './data/telephonySessionOutboundPartyTransfer.json';
import * as telephonyConferenceBringInBody from './data/telephonyConferenceBringIn.json'
import * as telephonySessionInboundPartyBody from './data/telephonySessionInboundParty.json';
import * as telephonyConferenceBringInBody
from './data/telephonyConferenceBringIn.json';
import * as telephonySessionBridge from './data/telephonySessionBridge.json';
import * as telephonySessionCallOutBody
from './data/telephonySessionCallOut.json';
import * as telephonySessionInboundPartyBody
from './data/telephonySessionInboundParty.json';
import * as telephonySessionPartyForwardBody
from './data/telephonySessionInboundPartyForward.json';
import * as telephonySessionBody from './data/telephonySessionOutbound.json';
import * as telephonySessionPartyBody
from './data/telephonySessionOutboundParty.json';
import * as telephonySessionPartyTransferBody
from './data/telephonySessionOutboundPartyTransfer.json';

export const mockServer = 'http://whatever';
export function createSDK(options = {}) {
Expand Down Expand Up @@ -337,6 +345,16 @@ export function mockTelephoneSessionTransferParty(mockResponse = {}) {
});
}

export function mockTelephoneSessionBridgeParty(mockResponse = {}) {
mockApi({
url: 'express:/restapi/v1.0/account/~/telephony/sessions/:sessionId/parties/:partyId/bridge',
method: 'POST',
body: {
...telephonySessionBridge
},
isOnce: true,
});
}

export function mockTelephoneSessionRemoveParty(mockResponse = {}) {
mockApi({
Expand Down
16 changes: 12 additions & 4 deletions test/session.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { formatParty } from '../src/formatParty';
import { Session } from '../src/Session';
import { USER_AGENT } from '../src/userAgent';
import { formatParty } from '../src/formatParty';
import * as extensionInfo from './mock/data/extensionInfo.json';
import * as telephonySessionOutboundData from './mock/data/telephonySessionOutbound.json';
import * as telephonySessionInboundData from './mock/data/telephonySessionInbound.json';
import * as telephonyConferenceData from './mock/data/telephonyConference.json';

import * as telephonySessionInboundData
from './mock/data/telephonySessionInbound.json';
import * as telephonySessionOutboundData
from './mock/data/telephonySessionOutbound.json';
import * as mock from './mock/sdk';

let sdk;
Expand Down Expand Up @@ -141,6 +142,13 @@ describe('RingCentral Call Control :: Session', () => {
});
})

it('should bridge successfully', async () => {
mock.mockTelephoneSessionBridgeParty();
const party = await session.bridge({ telephonySessionId: 's-a4a0d812557c5z1803a3eee14z97f6290000', partyId: 's-a4a0d812557c5z1803a3eee14z97f6290000-1'});
expect(party.status.reason).toEqual('AttendedTransfer');
});
})

describe('Inbound', () => {
beforeEach(() => {
const data = {
Expand Down

0 comments on commit c6d7142

Please sign in to comment.