Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions examples/different-transcribers/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "@examples/different-transcribers",
"version": "1.0.0",
"private": true,
"description": "Examples of testing IVR call flow using various transcribers",
"license": "MIT",
"scripts": {
"test-ivr:google-speech-to-text": "export LOCAL_SERVER_PORT=8080 && export PUBLIC_SERVER_URL=$(curl -s localhost:4040/api/tunnels | jq -r .tunnels[0].public_url) && node --require ts-node/register src/google-speech-to-text.ts",
"test-ivr:amazon-transcribe": "export LOCAL_SERVER_PORT=8080 && export PUBLIC_SERVER_URL=$(curl -s localhost:4040/api/tunnels | jq -r .tunnels[0].public_url) && node --require ts-node/register src/amazon-transcribe.ts",
"ngrok": "ngrok http 8080",
"lint:prettier": "prettier --list-different 'src/**/*.ts' --write",
"lint:eslint": "eslint 'src/**/*.ts'",
"lint": "yarn lint:prettier && yarn lint:eslint",
"record": "terminalizer record --config ../../doc-assets/terminalizer-config.yml --skip-sharing terminal-recording",
"record:play": "terminalizer play terminal-recording",
"record:render": "rm -f terminal-recording.gif && terminalizer render -o terminal-recording terminal-recording"
},
"dependencies": {
"dotenv": "^8.2.0",
"ivr-tester": "^0.1.0",
"ivr-tester-transcriber-amazon-transcribe": "^0.1.2",
"ivr-tester-transcriber-google-speech-to-text": "^0.1.2"
},
"devDependencies": {
"@types/node": "^14.11.1",
"@typescript-eslint/eslint-plugin": "^4.13.0",
"@typescript-eslint/parser": "^4.3.0",
"eslint": "^7.10.0",
"eslint-config-google": "^0.14.0",
"eslint-config-prettier": "^6.12.0",
"eslint-plugin-jest": "^24.0.2",
"ngrok": "^3.2.7",
"prettier": "^2.1.2",
"terminalizer": "^0.7.2",
"ts-node": "^9.0.0",
"typescript": "^4.1.3"
}
}
135 changes: 135 additions & 0 deletions examples/different-transcribers/src/google-speech-to-text.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import {
CallFlowTestDefinition,
Config,
contains,
doNothing,
inOrder,
isAnything,
press,
testRunner,
TestSubject,
} from "ivr-tester";
import path from "path";
import { googleSpeechToText } from "ivr-tester-transcriber-google-speech-to-text";

// eslint-disable-next-line @typescript-eslint/no-var-requires
require("dotenv").config();

const call: TestSubject = {
from: process.env.FROM_PHONE_NUMBER,
to: process.env.TO_PHONE_NUMBER,
};

const timeout = 6000;

const tests: CallFlowTestDefinition[] = [
{
name: "Keys pressed are read back",
instructions: inOrder([
{
whenPrompt: isAnything(),
then: press("1"),
silenceAfterPrompt: 3000,
timeout,
},
{
whenPrompt: contains("please enter a number"),
then: press("0123456789"),
silenceAfterPrompt: 3000,
timeout,
},
{
whenPrompt: contains("you entered the values 0123456789"),
then: doNothing(),
silenceAfterPrompt: 3000,
timeout,
},
]),
},
// {
// name: "API call with short latency",
// instructions: inOrder([
// {
// whenPrompt: isAnything(),
// then: press("3"),
// silenceAfterPrompt: 3000,
// timeout,
// },
// {
// whenPrompt: similarTo(
// "please wait while we search for your phone number on our system"
// ),
// then: doNothing(),
// silenceAfterPrompt: 1500,
// timeout,
// },
// {
// whenPrompt: contains("please enter a number"),
// then: press("123"),
// silenceAfterPrompt: 3000,
// timeout,
// },
// {
// whenPrompt: similarTo("you entered the values 123"),
// then: doNothing(),
// silenceAfterPrompt: 3000,
// timeout,
// },
// ]),
// },
// {
// name: "API call with long latency",
// instructions: inOrder([
// {
// whenPrompt: isAnything(),
// then: press("4"),
// silenceAfterPrompt: 3000,
// timeout,
// },
// {
// whenPrompt: similarTo(
// "please wait while we search for your phone number on our system"
// ),
// then: doNothing(),
// silenceAfterPrompt: 3000,
// timeout,
// },
// {
// whenPrompt: contains("please enter a number"),
// then: press("123"),
// silenceAfterPrompt: 3000,
// timeout,
// },
// {
// whenPrompt: similarTo("you entered the values 123"),
// then: doNothing(),
// silenceAfterPrompt: 3000,
// timeout,
// },
// ]),
// },
];

const config: Config = {
transcriber: googleSpeechToText({
languageCode: "en-GB",
speechPhrases: ["you entered the values", "you timed out"],
useEnhanced: true,
}),
recording: {
audio: {
outputPath: path.join(__dirname, "../recordings"),
},
transcript: {
outputPath: path.join(__dirname, "../recordings"),
includeResponse: true,
},
},
};

testRunner(config)(call, tests)
.then(() => process.exit(0))
.catch((error: Error) => {
console.error(error);
process.exit(1);
});
1 change: 1 addition & 0 deletions examples/ivr-tester-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"description": "Examples of using IVR Tester's API with various transcribers",
"license": "MIT",
"scripts": {
"example:call-fuzzer-interaction": "node --require ts-node/register src/call-fuzzer-interaction.ts",
"example:different-transcribers:google-speech-to-text": "node --require ts-node/register src/different-transcribers/google-speech-to-text.ts",
"example:different-transcribers:amazon-transcribe": "node --require ts-node/register src/different-transcribers/amazon-transcribe.ts",
"example:timeout": "node --require ts-node/register src/timeout.ts",
Expand Down
51 changes: 51 additions & 0 deletions examples/ivr-tester-api/src/call-fuzzer-interaction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import {
CallFuzzerInteraction,
Config,
IvrNumber,
IvrTester,
} from "ivr-tester";
import path from "path";
import { googleSpeechToText } from "ivr-tester-transcriber-google-speech-to-text";
import ngrok from "ngrok";

// eslint-disable-next-line @typescript-eslint/no-var-requires
require("dotenv").config();

const call: IvrNumber = {
from: process.env.FROM_PHONE_NUMBER,
to: process.env.TO_PHONE_NUMBER,
};

const config: Config = {
localServerPort: 8080,
twilioAuth: {
accountSid: process.env.TWILIO_ACCOUNT_SID,
authToken: process.env.TWILIO_AUTH_TOKEN,
},
transcriber: googleSpeechToText({
languageCode: "en-GB",
}),
recording: {
audio: {
outputPath: path.join(__dirname, "../recordings"),
},
},
};

function catchError(err: Error) {
if (err) console.error(err);
process.exit(1);
}

ngrok
.connect(config.localServerPort)
.then((url) => {
return new IvrTester(
{ ...config, publicServerUrl: url },
new CallFuzzerInteraction()
)
.run(call)
.then(() => process.exit())
.catch(catchError);
})
.catch(catchError);
Loading