-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add ringout inbound leg * fix failed test * new implement * review feedback * Update index.ts fix wrong type * review feedback Co-authored-by: jackson lin <[email protected]>
- Loading branch information
1 parent
d299f02
commit 4408a54
Showing
4 changed files
with
68 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
import { Session, SessionData, Direction as callDirections } from './Session'; | ||
|
||
function ringOutInboundLegCheck(newData: SessionData, allSessions: Session[]) { | ||
const { parties = [], origin = { type: 'Call' } } = newData || {}; | ||
const party = parties[0]; | ||
const checkResult = { | ||
isRingOutInboundLeg: false, | ||
legSessionId: null, | ||
}; | ||
if (!party || origin.type === 'Call' && party.direction === callDirections.outbound) { | ||
return checkResult; | ||
} | ||
if (allSessions.length) { | ||
for (const session of allSessions) { | ||
const sessionIdGap = parseInt(newData.sessionId, 10) - parseInt(session.sessionId, 10); | ||
const { party: existedSessionParty } = session; | ||
switch (sessionIdGap) { | ||
case 1000: | ||
case 2000: | ||
case 3000: | ||
case 4000: { | ||
if (party.direction === callDirections.inbound && party.from && party.to && | ||
existedSessionParty.from && existedSessionParty.to && (party.from.phoneNumber === existedSessionParty.to.phoneNumber) && | ||
(party.to.phoneNumber === existedSessionParty.from.phoneNumber)) { | ||
checkResult.isRingOutInboundLeg = true; | ||
} | ||
break; | ||
} | ||
case -1000: | ||
case -2000: | ||
case -3000: | ||
case -4000: { | ||
if (party.direction === callDirections.outbound && party.from && party.to && | ||
existedSessionParty.from && existedSessionParty.to && (party.from.phoneNumber === existedSessionParty.to.phoneNumber) && | ||
(party.to.phoneNumber === existedSessionParty.from.phoneNumber)) { | ||
checkResult.isRingOutInboundLeg = false; | ||
checkResult.legSessionId = session.id; | ||
} | ||
break; | ||
} | ||
default: | ||
break; | ||
} | ||
} | ||
} | ||
return checkResult; | ||
} | ||
|
||
export { ringOutInboundLegCheck }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters