From c6d71424fcde527f77c0798c2d54e27b58e9fbb0 Mon Sep 17 00:00:00 2001 From: Una1219 <102606119+Una1219@users.noreply.github.com> Date: Mon, 18 Apr 2022 10:53:50 +0800 Subject: [PATCH] add bridge api (#43) * add bridge api * add bridge api * add test bridge api Co-authored-by: una.feng --- src/Session.ts | 15 +++++++++ test/mock/data/telephonySessionBridge.json | 35 +++++++++++++++++++++ test/mock/sdk.ts | 36 ++++++++++++++++------ test/session.test.ts | 16 +++++++--- 4 files changed, 89 insertions(+), 13 deletions(-) create mode 100644 test/mock/data/telephonySessionBridge.json diff --git a/src/Session.ts b/src/Session.ts index 648e67e..ad6e805 100644 --- a/src/Session.ts +++ b/src/Session.ts @@ -111,6 +111,11 @@ export interface AnswerParams { deviceId: string; } +export interface BridgeParams { + telephonySessionId: string; + partyId: string; +} + export interface IgnoreParams { deviceId: string; } @@ -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`, diff --git a/test/mock/data/telephonySessionBridge.json b/test/mock/data/telephonySessionBridge.json new file mode 100644 index 0000000..24d9ac2 --- /dev/null +++ b/test/mock/data/telephonySessionBridge.json @@ -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" + } + } + \ No newline at end of file diff --git a/test/mock/sdk.ts b/test/mock/sdk.ts index 0af03e8..cb819a7 100644 --- a/test/mock/sdk.ts +++ b/test/mock/sdk.ts @@ -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 = {}) { @@ -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({ diff --git a/test/session.test.ts b/test/session.test.ts index 528184c..67542bc 100644 --- a/test/session.test.ts +++ b/test/session.test.ts @@ -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; @@ -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 = {