-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SE-53] Add conditional-recording feature (#644)
- Loading branch information
Showing
9 changed files
with
146 additions
and
5 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,31 @@ | ||
--- | ||
sidebar_label: conditional-recording | ||
title: conditional-recording | ||
--- | ||
|
||
Flex includes a built-in call recording feature which can be enabled via the Twilio Console > Flex > Manage > Voice. This records the conference for every call handled within Flex, in either single- or dual-channel. | ||
|
||
However, for regulatory compliance purposes, some implementations may need to prevent recording certain calls. This feature adds that capability to the built-in call recording feature, by preventing recording based on task queue or based on the presence of certain task attributes. The task attributes and/or task queues that should be excluded from recording are configurable. | ||
|
||
:::info dual-channel-recording feature | ||
The `conditional-recording` feature works with the native call recording functionality. It is not applicable in conjunction with [the template's `dual-channel-recording` feature](/feature-library/dual-channel-recording), which has its own conditional recording functionality. | ||
::: | ||
|
||
## setup and dependencies | ||
|
||
If you are enabling the conditional recording feature, you must also **enable** the call recording flag within Twilio Console > Flex > Manage > Voice, otherwise recordings will not be accessible via Flex Insights. | ||
|
||
The `conditional-recording` feature has the following settings: | ||
- `enabled` - Set to `true` to enable the feature | ||
- `exclude_attributes` - To exclude recording tasks based on the task attributes present, set this to an array of key/value pair objects. For example, to prevent recording outbound calls: | ||
``` | ||
"exclude_attributes": [{ "key":"direction", "value":"outbound" }] | ||
``` | ||
- `exclude_queues` - To exclude recording tasks based on queue name or queue SID, set this to an array of queue names or SIDs. For example: | ||
``` | ||
"exclude_queues": ["Queue Name 1", "Queue Name 2"] // or ["WQxxx", "WQxxx2"] | ||
``` | ||
|
||
## how it works | ||
|
||
Before an inbound or outbound call task is accepted, the task is evaluated based on the defined attributes and/or queues to exclude from recording. The `payload.conferenceOptions.conferenceRecord` flag is set to `true` or `false` depending on the outcome of this evaluation. If this flag is set to `true`, then TaskRouter will initiate the conference recording immediately upon conference start. |
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
24 changes: 24 additions & 0 deletions
24
plugin-flex-ts-template-v2/src/feature-library/conditional-recording/config.ts
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,24 @@ | ||
import { getFeatureFlags, getLoadedFeatures } from '../../utils/configuration'; | ||
import ConditionalRecordingConfig from './types/ServiceConfiguration'; | ||
|
||
const { | ||
enabled = false, | ||
exclude_attributes = [], | ||
exclude_queues = [], | ||
} = (getFeatureFlags()?.features?.conditional_recording as ConditionalRecordingConfig) || {}; | ||
|
||
export const isFeatureEnabled = () => { | ||
return enabled; | ||
}; | ||
|
||
export const getExcludedAttributes = () => { | ||
return exclude_attributes; | ||
}; | ||
|
||
export const getExcludedQueues = () => { | ||
return exclude_queues; | ||
}; | ||
|
||
export const isDualChannelEnabled = () => { | ||
return getLoadedFeatures().includes('dual-channel-recording'); | ||
}; |
33 changes: 33 additions & 0 deletions
33
...ts-template-v2/src/feature-library/conditional-recording/flex-hooks/actions/AcceptTask.ts
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,33 @@ | ||
import * as Flex from '@twilio/flex-ui'; | ||
|
||
import { FlexActionEvent, FlexAction } from '../../../../types/feature-loader'; | ||
import logger from '../../../../utils/logger'; | ||
import { canRecordTask } from '../../helpers/conditionalRecordingHelper'; | ||
import { isDualChannelEnabled } from '../../config'; | ||
|
||
export const actionEvent = FlexActionEvent.before; | ||
export const actionName = FlexAction.AcceptTask; | ||
export const actionHook = function setRecordingFlag(flex: typeof Flex) { | ||
flex.Actions.addListener(`${actionEvent}${actionName}`, async (payload) => { | ||
if (!payload.task && !payload.sid) return; | ||
|
||
// If the dual-channel-recording feature is enabled, it will perform the recording instead | ||
if (isDualChannelEnabled()) { | ||
logger.warn( | ||
'[conditional-recording] Because the dual-channel-recording feature is enabled, the conditional-recording configuration will be ignored.', | ||
); | ||
return; | ||
} | ||
|
||
let task = payload.task; | ||
|
||
if (!task) { | ||
task = Flex.TaskHelper.getTaskByTaskSid(payload.sid); | ||
} | ||
|
||
payload.conferenceOptions.conferenceRecord = canRecordTask(task); | ||
logger.debug( | ||
`[conditional-recording] Recording flag for ${task.sid}: ${payload.conferenceOptions.conferenceRecord}`, | ||
); | ||
}); | ||
}; |
17 changes: 17 additions & 0 deletions
17
...mplate-v2/src/feature-library/conditional-recording/helpers/conditionalRecordingHelper.ts
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,17 @@ | ||
import { ITask } from '@twilio/flex-ui'; | ||
|
||
import { getExcludedAttributes, getExcludedQueues } from '../config'; | ||
|
||
export const canRecordTask = (task: ITask): boolean => { | ||
if (getExcludedQueues().findIndex((queue) => queue === task.queueName || queue === task.queueSid) >= 0) { | ||
return false; | ||
} | ||
|
||
for (const attribute of getExcludedAttributes()) { | ||
if (task.attributes[attribute.key] === attribute.value) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
}; |
9 changes: 9 additions & 0 deletions
9
plugin-flex-ts-template-v2/src/feature-library/conditional-recording/index.ts
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,9 @@ | ||
import { FeatureDefinition } from '../../types/feature-loader'; | ||
import { isFeatureEnabled } from './config'; | ||
// @ts-ignore | ||
import hooks from './flex-hooks/**/*.*'; | ||
|
||
export const register = (): FeatureDefinition => { | ||
if (!isFeatureEnabled()) return {}; | ||
return { name: 'conditional-recording', hooks: typeof hooks === 'undefined' ? [] : hooks }; | ||
}; |
10 changes: 10 additions & 0 deletions
10
...ex-ts-template-v2/src/feature-library/conditional-recording/types/ServiceConfiguration.ts
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,10 @@ | ||
interface AttributesQualificationConfig { | ||
key: string; | ||
value: string; | ||
} | ||
|
||
export default interface ConditionalRecordingConfig { | ||
enabled: boolean; | ||
exclude_attributes: Array<AttributesQualificationConfig>; | ||
exclude_queues: Array<string>; | ||
} |