Skip to content

Commit

Permalink
introduce userToUserInformation support
Browse files Browse the repository at this point in the history
also prepare it for refer, even though the backend doesn't support it yet
  • Loading branch information
pschichtel committed Aug 21, 2023
1 parent e7d9c6e commit 4d8abaa
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 10 deletions.
2 changes: 1 addition & 1 deletion extensions/vier-cognitive-voice-gateway/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vier-voice",
"description": "Enable phone bots with VIER Cognitive Voice Gateway",
"version": "4.5.0",
"version": "4.6.0",
"main": "build/module.js",
"author": "VIER GmbH",
"license": "MIT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
"inputCallerIdDescription": "The phone number displayed to the callee. (This is a best-effort option, correct display can not be guaranteed)",
"inputCustomSipHeadersLabel": "Custom SIP Headers",
"inputCustomSipHeadersDescription": "An object where each property is the name of a header, and the value is a list of strings. All header names must begin with X-.",
"inputUserToUserLabel": "User-To-User Information",
"inputUserToUserDescription": "A list of opaque strings that are send as User-To-User SIP headers.",
"inputRingTimeoutLabel": "Ring Timeout (s)",
"inputRingTimeoutDescription": "The maximum time (in seconds) the call will be ringing before the attempt will be cancelled",
"inputAcceptAnsweringMachinesLabel": "Accept Answering Machines",
Expand All @@ -103,7 +105,8 @@
"childSuccessLabel": "On Success",
"childFailureLabel": "On Failure",
"childTerminationLabel": "On Termination",
"childDefaultLabel": "Default"
"childDefaultLabel": "Default",
"sectionSipLabel": "SIP"
},
"bargeIn": {
"input": {
Expand Down
23 changes: 16 additions & 7 deletions extensions/vier-cognitive-voice-gateway/src/common/transferCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {

export interface TransferCallInputs extends EndFlowInputs {
callerId?: string;
userToUserInformation?: Array<string>
customSipHeaders?: object;
ringTimeout?: number;
acceptAnsweringMachines?: boolean;
Expand All @@ -29,7 +30,14 @@ const callerIdField: INodeField = {
},
};

const customSipHeadersField: INodeField = {
export const userToUserField: INodeField = {
type: 'textArray',
key: 'userToUserInformation',
label: t.shared.inputUserToUserLabel,
description: t.shared.inputUserToUserDescription,
};

export const customSipHeadersField: INodeField = {
type: 'json',
key: 'customSipHeaders',
label: t.shared.inputCustomSipHeadersLabel,
Expand Down Expand Up @@ -82,6 +90,7 @@ const whisperingTextField: INodeField = {
export const transferCallFields: Array<INodeField> = [
callerIdField,
customSipHeadersField,
userToUserField,
ringTimeoutField,
acceptAnsweringMachinesField,
dataField,
Expand All @@ -97,10 +106,10 @@ const callSection: INodeSection = {
defaultCollapsed: true,
};

const sipHeadersSection: INodeSection = {
key: 'sipHeaders',
fields: [customSipHeadersField.key],
label: t.shared.inputCustomSipHeadersLabel,
const sipSection: INodeSection = {
key: 'sip',
fields: [userToUserField.key, customSipHeadersField.key],
label: t.shared.sectionSipLabel,
defaultCollapsed: true,
};

Expand All @@ -120,7 +129,7 @@ const additionalSettingsSection: INodeSection = {

export const transferCallSections: Array<INodeSection> = [
callSection,
sipHeadersSection,
sipSection,
additionalDataSection,
additionalSettingsSection,
];
Expand All @@ -131,7 +140,7 @@ export const transferCallForm: Array<INodeFieldAndSectionFormElement> = [
type: 'section',
},
{
key: sipHeadersSection.key,
key: sipSection.key,
type: 'section',
},
{
Expand Down
19 changes: 19 additions & 0 deletions extensions/vier-cognitive-voice-gateway/src/helpers/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,25 @@ export function normalizeSipHeaders(headersObject: object | undefined): CustomSi
return headers;
}

export function normalizeUserToUserInformation(userToUserInformation: Array<string> | undefined): Array<string> | undefined {
if (!Array.isArray(userToUserInformation)) {
return undefined;
}

const information: Array<string> = []
for (const line of userToUserInformation) {
if (line === undefined || line === null || line === '') {
continue;
}
information.push(`${line}`)
}
if (information.length === 0) {
return undefined;
}

return information;
}

export const DEFAULT_NUMBER_VALUE = 'none';

function toNumberOrUndefined(numeric: number | string | undefined | null): number | undefined {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
normalizeData,
normalizeSipHeaders,
normalizeText,
normalizeUserToUserInformation,
} from '../helpers/util';
import t from '../translations';
import {
Expand Down Expand Up @@ -92,6 +93,7 @@ export const bridgeCallNode = createNodeDescriptor({
extensionLength: config.extensionLength,
callerId: normalizeText(config.callerId),
customSipHeaders: normalizeSipHeaders(config.customSipHeaders),
userToUserInformation: normalizeUserToUserInformation(config.userToUserInformation),
ringTimeout: convertDurationFromSecondsToMillis(config.ringTimeout),
acceptAnsweringMachines: config.acceptAnsweringMachines,
data: normalizeData(api, config.data),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
normalizeText,
convertDurationFromSecondsToMillis,
delay,
normalizeUserToUserInformation,
} from '../helpers/util';
import t from '../translations';
import {
Expand Down Expand Up @@ -78,6 +79,7 @@ export const forwardCallNode = createNodeDescriptor({
destinationNumber: normalizeText(config.destinationNumber),
callerId: normalizeText(config.callerId),
customSipHeaders: normalizeSipHeaders(config.customSipHeaders),
userToUserInformation: normalizeUserToUserInformation(config.userToUserInformation),
ringTimeout: convertDurationFromSecondsToMillis(config.ringTimeout),
acceptAnsweringMachines: config.acceptAnsweringMachines,
data: normalizeData(api, config.data),
Expand Down
13 changes: 12 additions & 1 deletion extensions/vier-cognitive-voice-gateway/src/nodes/referCall.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { INodeFunctionBaseParams, createNodeDescriptor } from "@cognigy/extension-tools";
import t from '../translations';
import { normalizeText } from "../helpers/util";
import {
normalizeSipHeaders,
normalizeText,
normalizeUserToUserInformation,
} from "../helpers/util";
import { EndFlowInputs, endFlowField } from "../common/shared";

interface IReferCallInputs extends EndFlowInputs {
destination: string;
userToUserInformation?: Array<string>
customSipHeaders?: object;
}

export interface IReferCallParams extends INodeFunctionBaseParams {
Expand Down Expand Up @@ -33,6 +39,9 @@ export const referCallNode = createNodeDescriptor({
placeholder: '+E.164 number or SIP URI',
},
},
// TODO enable these once CVG supports them
// userToUserField,
// customSipHeadersField,
endFlowField,
],
preview: {
Expand All @@ -45,6 +54,8 @@ export const referCallNode = createNodeDescriptor({
const payload = {
status: 'refer',
destination: normalizeText(config.destination),
customSipHeaders: normalizeSipHeaders(config.customSipHeaders),
userToUserInformation: normalizeUserToUserInformation(config.userToUserInformation),
};

api.say('', payload);
Expand Down
9 changes: 9 additions & 0 deletions extensions/vier-cognitive-voice-gateway/src/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,12 @@ export default {
'default': "Timeout",
'deDE': "Zeitüberschreitung",
},
inputUserToUserDescription: {
'default': "A list of opaque strings that are send as User-To-User SIP headers.",
},
inputUserToUserLabel: {
'default': "User-To-User Information",
},
inputWhisperingTextDescription: {
'default': "Enter the text that should be announced to the agent the call is forwarded to before the call partners are connected.",
'deDE': "Geben Sie den Text ein, der dem:der Agent:in bei der Weiterleitung angesagt werden soll, bevor die Gesprächspartner:innen verbunden werden.",
Expand All @@ -436,6 +442,9 @@ export default {
'default': "Whispering Announcement",
'deDE': "Whispering-Ansage",
},
sectionSipLabel: {
'default': "SIP",
},
sectionStopConditionLabel: {
'default': "Stop Condition",
'deDE': "Stoppbedingung",
Expand Down

0 comments on commit 4d8abaa

Please sign in to comment.