|
| 1 | +package sample |
| 2 | + |
| 3 | +// envPrompt describes an environment variable that a sample app requires beyond |
| 4 | +// the standard Bandwidth credentials (which are auto-populated from band auth). |
| 5 | +type envPrompt struct { |
| 6 | + Key string // env var name written to .env |
| 7 | + Flag string // CLI flag name (without --) |
| 8 | + Description string // shown in --help |
| 9 | +} |
| 10 | + |
| 11 | +// langSetup describes how to install dependencies and run the app for a given language. |
| 12 | +type langSetup struct { |
| 13 | + // AppDir is the working directory to cd into before running. |
| 14 | + AppDir string |
| 15 | + // InstallCmd is the command to install dependencies (run once after clone). |
| 16 | + InstallCmd []string |
| 17 | + // RunCmd is the command to start the app (run in the AppDir). |
| 18 | + RunCmd []string |
| 19 | + // HealthPath is the HTTP path polled to detect a ready server. |
| 20 | + HealthPath string |
| 21 | +} |
| 22 | + |
| 23 | +// SampleEntry describes one sample app and its variants. |
| 24 | +type SampleEntry struct { |
| 25 | + Description string |
| 26 | + // Repos maps language name → GitHub clone URL. |
| 27 | + Repos map[string]string |
| 28 | + // ExtraEnv lists environment variables required beyond BW_* credentials. |
| 29 | + ExtraEnv []envPrompt |
| 30 | + // Setup maps language name → build/run instructions. |
| 31 | + Setup map[string]langSetup |
| 32 | + // Port is the default local port the app listens on. |
| 33 | + Port int |
| 34 | +} |
| 35 | + |
| 36 | +// catalog is the authoritative list of runnable Bandwidth sample apps. |
| 37 | +var catalog = map[string]*SampleEntry{ |
| 38 | + "live-assistant": { |
| 39 | + Description: "Real-time AI voice assistant powered by OpenAI Realtime API", |
| 40 | + Repos: map[string]string{ |
| 41 | + "python": "https://github.com/Bandwidth-Samples/openai-live-websockets-python", |
| 42 | + }, |
| 43 | + ExtraEnv: []envPrompt{ |
| 44 | + {Key: "OPENAI_API_KEY", Flag: "openai-key", Description: "OpenAI API key (must have Realtime API access)"}, |
| 45 | + {Key: "TRANSFER_TO", Flag: "transfer-to", Description: "Phone number to transfer calls to (E.164, e.g. +19195551234)"}, |
| 46 | + }, |
| 47 | + Setup: map[string]langSetup{ |
| 48 | + "python": { |
| 49 | + AppDir: "app", |
| 50 | + InstallCmd: []string{".venv/bin/pip", "install", "-q", "-r", "app/requirements.txt"}, |
| 51 | + RunCmd: []string{".venv/bin/python3", "main.py"}, |
| 52 | + HealthPath: "/health", |
| 53 | + }, |
| 54 | + }, |
| 55 | + Port: 3000, |
| 56 | + }, |
| 57 | + "voice-gather": { |
| 58 | + Description: "In-call DTMF gather example", |
| 59 | + Repos: map[string]string{ |
| 60 | + "python": "https://github.com/Bandwidth-Samples/in-call-gather-python", |
| 61 | + }, |
| 62 | + Setup: map[string]langSetup{ |
| 63 | + "python": { |
| 64 | + AppDir: ".", |
| 65 | + InstallCmd: []string{".venv/bin/pip", "install", "-q", "-r", "requirements.txt"}, |
| 66 | + RunCmd: []string{".venv/bin/python3", "app.py"}, |
| 67 | + HealthPath: "/", |
| 68 | + }, |
| 69 | + }, |
| 70 | + Port: 3000, |
| 71 | + }, |
| 72 | +} |
0 commit comments