@voctiv/agent-sdk 0.2.14 → 0.2.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +312 -61
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/recall-utils.d.ts +8 -0
- package/dist/recall-utils.d.ts.map +1 -0
- package/dist/recall-utils.js +51 -0
- package/dist/recall-utils.js.map +1 -0
- package/dist/types/events.d.ts +9 -2
- package/dist/types/events.d.ts.map +1 -1
- package/dist/types/logger.d.ts +30 -0
- package/dist/types/logger.d.ts.map +1 -1
- package/dist/types/logger.js +12 -0
- package/dist/types/logger.js.map +1 -1
- package/dist/types/nlu.d.ts +5 -3
- package/dist/types/nlu.d.ts.map +1 -1
- package/dist/types/platform.d.ts +74 -17
- package/dist/types/platform.d.ts.map +1 -1
- package/dist/types/script-context.d.ts +20 -5
- package/dist/types/script-context.d.ts.map +1 -1
- package/dist/types/script-context.js.map +1 -1
- package/dist/types/sip.d.ts +20 -11
- package/dist/types/sip.d.ts.map +1 -1
- package/examples/README.md +43 -0
- package/examples/after-call-continuation.ts +47 -0
- package/examples/outbound-with-recall.ts +43 -0
- package/examples/read-recall-from-params.ts +41 -0
- package/examples/recall-routing-by-attempt.ts +55 -0
- package/examples/schedule-call-with-defaults.ts +31 -0
- package/package.json +3 -2
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read recall settings from legacy dialog/call params and schedule outbound.
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
defineScript,
|
|
6
|
+
parseRecallCount,
|
|
7
|
+
parseRecallDelaySeconds,
|
|
8
|
+
} from '@voctiv/agent-sdk';
|
|
9
|
+
|
|
10
|
+
export default defineScript(async ({ context, logger, platform }) => {
|
|
11
|
+
const params = context.dialogParams ?? {};
|
|
12
|
+
|
|
13
|
+
const rawCount = params.recall_count ?? params.recallCount;
|
|
14
|
+
const rawDelay = params.recall_delay ?? params.recallDelay;
|
|
15
|
+
|
|
16
|
+
const recallCount =
|
|
17
|
+
parseRecallCount(rawCount) ?? context.recallCount ?? context.agent?.recallCount;
|
|
18
|
+
const recallDelaySec =
|
|
19
|
+
parseRecallDelaySeconds(rawDelay) ??
|
|
20
|
+
context.recallDelay ??
|
|
21
|
+
context.agent?.recallDelay;
|
|
22
|
+
|
|
23
|
+
logger.log('Parsed recall from params', {
|
|
24
|
+
rawCount,
|
|
25
|
+
rawDelay,
|
|
26
|
+
recallCount,
|
|
27
|
+
recallDelaySec,
|
|
28
|
+
attempt: context.attempt,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const msisdn = context.msisdn || context.callerId;
|
|
32
|
+
if (!msisdn || recallCount == null || recallDelaySec == null) {
|
|
33
|
+
logger.warn('Missing msisdn or recall config — skipping schedule');
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
await platform.call(msisdn, {
|
|
38
|
+
recallCount,
|
|
39
|
+
recallDelay: recallDelaySec,
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handle the first outbound attempt vs automatic recall attempts.
|
|
3
|
+
*
|
|
4
|
+
* Recall calls are still **online** SIP sessions (`getScriptPhase` → `'online'`).
|
|
5
|
+
* Use `context.attempt` (from `dialog.params.attempt`, starts at 0) to branch inside
|
|
6
|
+
* your single `defineScript` handler — the host does not invoke a separate function.
|
|
7
|
+
*/
|
|
8
|
+
import { defineScript, getScriptPhase } from '@voctiv/agent-sdk';
|
|
9
|
+
|
|
10
|
+
export default defineScript(async ({ channel, context, logger }) => {
|
|
11
|
+
const phase = getScriptPhase(context);
|
|
12
|
+
const attempt = context.attempt ?? 0;
|
|
13
|
+
|
|
14
|
+
logger.log('Call leg', {
|
|
15
|
+
phase,
|
|
16
|
+
attempt,
|
|
17
|
+
headless: context.headless,
|
|
18
|
+
recallCount: context.recallCount,
|
|
19
|
+
recallDelay: context.recallDelay,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
channel.sip.answer();
|
|
23
|
+
|
|
24
|
+
if (!context.headless && attempt > 0) {
|
|
25
|
+
await channel.audio.say(
|
|
26
|
+
`This is follow-up attempt number ${attempt + 1}. Please stay on the line.`,
|
|
27
|
+
);
|
|
28
|
+
} else if (!context.headless) {
|
|
29
|
+
await channel.audio.say('Hello, this is our first call to you today.');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const asr = await channel.createAsr({ language: context.language || 'ru-RU' });
|
|
33
|
+
|
|
34
|
+
return new Promise((resolve) => {
|
|
35
|
+
asr.result$.subscribe(async (text) => {
|
|
36
|
+
if (!text.trim()) return;
|
|
37
|
+
|
|
38
|
+
if (/voicemail|leave a message/i.test(text)) {
|
|
39
|
+
logger.log('Voicemail detected — host may schedule recall', { attempt });
|
|
40
|
+
channel.sip.hangup();
|
|
41
|
+
resolve({ output: { outcome: 'voicemail', attempt } });
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
await channel.audio.say('Thank you. Goodbye.');
|
|
46
|
+
channel.sip.hangup();
|
|
47
|
+
resolve({ output: { outcome: 'answered', attempt } });
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
channel.events.terminated$.subscribe(() => {
|
|
51
|
+
asr.destroy();
|
|
52
|
+
resolve({ output: { outcome: 'terminated', attempt } });
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schedule outbound using CMS contact-rules defaults already resolved on `context`.
|
|
3
|
+
*
|
|
4
|
+
* When `recallCount` / `recallDelay` are omitted from `platform.call()` options, the host
|
|
5
|
+
* fills them from `context.recallCount` / `context.recallDelay` only when `onFailedCall` is
|
|
6
|
+
* not configured for that scheduled call.
|
|
7
|
+
*/
|
|
8
|
+
import { defineScript } from '@voctiv/agent-sdk';
|
|
9
|
+
|
|
10
|
+
export default defineScript(async ({ channel, context, logger, platform }) => {
|
|
11
|
+
channel.sip.answer();
|
|
12
|
+
|
|
13
|
+
const msisdn = context.msisdn || context.callerId;
|
|
14
|
+
if (!msisdn) return;
|
|
15
|
+
|
|
16
|
+
logger.log('Recall configuration snapshot', {
|
|
17
|
+
effective: {
|
|
18
|
+
count: context.recallCount,
|
|
19
|
+
delaySec: context.recallDelay,
|
|
20
|
+
},
|
|
21
|
+
agentDefaults: {
|
|
22
|
+
count: context.agent?.recallCount,
|
|
23
|
+
delaySec: context.agent?.recallDelay,
|
|
24
|
+
},
|
|
25
|
+
attempt: context.attempt,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
await platform.call(msisdn);
|
|
29
|
+
|
|
30
|
+
await channel.audio.say('We have scheduled a call using your agent recall settings.');
|
|
31
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voctiv/agent-sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.16",
|
|
4
4
|
"description": "Voctiv TypeScript agent SDK: defineScript and platform types for the voice/dialog scripting runtime.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"author": "",
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
},
|
|
24
24
|
"files": [
|
|
25
25
|
"dist",
|
|
26
|
-
"README.md"
|
|
26
|
+
"README.md",
|
|
27
|
+
"examples"
|
|
27
28
|
],
|
|
28
29
|
"scripts": {
|
|
29
30
|
"build": "tsc -p tsconfig.build.json",
|