-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.ts
More file actions
61 lines (57 loc) · 2.26 KB
/
cli.ts
File metadata and controls
61 lines (57 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { Command } from 'commander';
import { callWithTask } from './task';
import { validate as validateConfig } from './config';
import {version, description} from './package.json';
export const voicecallCommand = new Command();
voicecallCommand
.name('voicecall')
.description(description)
.version(version);
voicecallCommand
.command('doctor')
.description('Validate the config')
.action(() => {
try {
validateConfig();
} catch (e) {
// Avoid uncaught throws: Bun prints huge snippets from minified dist/index.js.
console.error(e instanceof Error ? e.message : e);
process.exit(1);
}
});
voicecallCommand
.command('call')
.description('Place an outbound call')
.requiredOption('--to <number>', 'Recipient phone number in E.164 format')
.requiredOption(
'--task <task>',
'Drive the conversation until the task concludes then hang up'
)
.requiredOption(
'--context <context>',
'Additional background for the call (e.g. who you are, relationship, constraints)'
)
.action(async (opts: { to: string; task: string; context: string }) => {
const { conclusion, timedout } = await callWithTask({
...opts,
onStart: (callId) => {
console.log(`Calling ${opts.to}: (${callId})`);
console.log('─────────────────────────────');
console.log(`Task: ${opts.task}`);
console.log(`Context: ${opts.context}`);
console.log('─────────────────────────────');
},
onConnect: () => {
console.log('─────────────────────────────');
console.log('Caller picked up.');
console.log('─────────────────────────────');
},
onSpeech: (details) => {
console.log(`${details.role}: ${details.text}`);
},
});
console.log('─────────────────────────────');
console.log(`Conclusion: ${conclusion}`);
console.log('─────────────────────────────');
process.exit(timedout ? 1 : 0);
});