Skip to content

Commit 658088e

Browse files
committed
Added helpers to support prompt upload
1 parent 216e7cb commit 658088e

4 files changed

Lines changed: 145 additions & 0 deletions

File tree

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ go build -o five9 . # Build
2222
- `codegen/extract_api_spec.py` — parses `docs/scrape/*.md` into `codegen/five9_api_spec.json`
2323
- `codegen/generate_cli.py` — generates `cmd/*.go` from spec
2424
- `cmd/reports.go` — has a hand-written `run-and-wait` composite command (also generated, but with custom logic)
25+
- `cmd/custom_prompts.go` — hand-written `prompts upload` and `prompts replace` commands (WAV file upload via base64-encoded SOAP inline methods)
2526

2627
## Architecture
2728

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ five9 users get --user-name "jdoe@example.com"
4242
# Run a report
4343
five9 reports run-and-wait --folder-name "My Reports" --report-name "Call Log"
4444

45+
# Upload a WAV file as a new prompt
46+
five9 prompts upload --file greeting.wav --name "Main Greeting"
47+
48+
# Replace an existing prompt's audio
49+
five9 prompts replace --file updated.wav --name "Main Greeting"
50+
4551
# Different output formats
4652
five9 skills list --output table
4753
five9 campaigns list --output csv > campaigns.csv

cmd/custom_prompts.go

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
package cmd
2+
3+
import (
4+
"encoding/base64"
5+
"fmt"
6+
"os"
7+
"path/filepath"
8+
"strings"
9+
10+
"github.com/Cloverhound/five9-cli/internal/soap"
11+
"github.com/spf13/cobra"
12+
)
13+
14+
func init() {
15+
registerPromptsUpload()
16+
registerPromptsReplace()
17+
}
18+
19+
func registerPromptsUpload() {
20+
var filePath string
21+
var name string
22+
var description string
23+
24+
cmd := &cobra.Command{
25+
Use: "upload",
26+
Short: "Upload a WAV file as a new prompt",
27+
Long: `Upload a WAV file as a new prompt using addPromptWavInline.
28+
29+
The file is base64-encoded and sent inline in the SOAP body.
30+
If --name is omitted, the filename without extension is used.
31+
32+
Examples:
33+
five9 prompts upload --file greeting.wav
34+
five9 prompts upload --file greeting.wav --name "Main Greeting"
35+
five9 prompts upload --file greeting.wav --name "Main Greeting" --description "IVR main menu"
36+
five9 prompts upload --file greeting.wav --dry-run
37+
five9 prompts upload --file greeting.wav --debug`,
38+
RunE: func(c *cobra.Command, args []string) error {
39+
wavData, err := os.ReadFile(filePath)
40+
if err != nil {
41+
return fmt.Errorf("reading WAV file: %w", err)
42+
}
43+
44+
if name == "" {
45+
name = strings.TrimSuffix(filepath.Base(filePath), filepath.Ext(filePath))
46+
}
47+
48+
encoded := base64.StdEncoding.EncodeToString(wavData)
49+
50+
req := soap.NewRequest("addPromptWavInline")
51+
52+
promptChildren := []soap.Param{
53+
{Name: "name", Value: name},
54+
}
55+
if description != "" {
56+
promptChildren = append(promptChildren, soap.Param{Name: "description", Value: description})
57+
}
58+
req.SetComplexParam("prompt", promptChildren)
59+
req.SetParam("wavFile", encoded)
60+
61+
_, err = soap.Do(req)
62+
if err != nil {
63+
return err
64+
}
65+
66+
fmt.Fprintf(os.Stderr, "Prompt %q uploaded successfully\n", name)
67+
return nil
68+
},
69+
}
70+
71+
cmd.Flags().StringVar(&filePath, "file", "", "Path to WAV file to upload")
72+
cmd.MarkFlagRequired("file")
73+
cmd.Flags().StringVar(&name, "name", "", "Prompt name (defaults to filename without extension)")
74+
cmd.Flags().StringVar(&description, "description", "", "Prompt description")
75+
76+
PromptsCmd.AddCommand(cmd)
77+
}
78+
79+
func registerPromptsReplace() {
80+
var filePath string
81+
var name string
82+
83+
cmd := &cobra.Command{
84+
Use: "replace",
85+
Short: "Replace the WAV file on an existing prompt",
86+
Long: `Replace the audio file of an existing prompt using modifyPromptWavInline.
87+
88+
The file is base64-encoded and sent inline in the SOAP body.
89+
90+
Examples:
91+
five9 prompts replace --file greeting.wav --name "Main Greeting"
92+
five9 prompts replace --file greeting.wav --name "Main Greeting" --dry-run
93+
five9 prompts replace --file greeting.wav --name "Main Greeting" --debug`,
94+
RunE: func(c *cobra.Command, args []string) error {
95+
wavData, err := os.ReadFile(filePath)
96+
if err != nil {
97+
return fmt.Errorf("reading WAV file: %w", err)
98+
}
99+
100+
encoded := base64.StdEncoding.EncodeToString(wavData)
101+
102+
req := soap.NewRequest("modifyPromptWavInline")
103+
req.SetComplexParam("prompt", []soap.Param{
104+
{Name: "name", Value: name},
105+
})
106+
req.SetParam("wavFile", encoded)
107+
108+
_, err = soap.Do(req)
109+
if err != nil {
110+
return err
111+
}
112+
113+
fmt.Fprintf(os.Stderr, "Prompt %q replaced successfully\n", name)
114+
return nil
115+
},
116+
}
117+
118+
cmd.Flags().StringVar(&filePath, "file", "", "Path to WAV file to upload")
119+
cmd.MarkFlagRequired("file")
120+
cmd.Flags().StringVar(&name, "name", "", "Name of existing prompt to replace")
121+
cmd.MarkFlagRequired("name")
122+
123+
PromptsCmd.AddCommand(cmd)
124+
}

skill/SKILL.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,20 @@ five9 lists delete --list-name "Old List"
143143
five9 lists add-record --list-name "My List" --body-file record.json
144144
```
145145

146+
### Prompts
147+
148+
```bash
149+
five9 prompts list
150+
five9 prompts get --prompt-name "Main Greeting"
151+
152+
# Upload a WAV file as a new prompt
153+
five9 prompts upload --file greeting.wav
154+
five9 prompts upload --file greeting.wav --name "Main Greeting" --description "IVR main menu"
155+
156+
# Replace an existing prompt's audio
157+
five9 prompts replace --file updated.wav --name "Main Greeting"
158+
```
159+
146160
### IVR Scripts
147161

148162
```bash

0 commit comments

Comments
 (0)