### Clone and Setup Pipecat Bandwidth Example Source: https://dev.bandwidth.com/docs/voice/integrations/pipecat Clone the pipecat-bandwidth repository, navigate to the example directory, install dependencies using uv, and copy the environment file. ```bash git clone https://github.com/Bandwidth/pipecat-bandwidth cd pipecat-bandwidth/examples/bandwidth-chatbot uv sync cp env.example .env ``` -------------------------------- ### Start Recording (New) Source: https://dev.bandwidth.com/migration-guides/node/v1 Example of starting a recording using the new Bxml library, with options for transcription, file format, and multi-channel. ```javascript const attributes = { recordingAvailableUrl: 'https://initial.com', recordingAvailableMethod: 'POST', transcribe: true, transcriptionAvailableUrl: 'https://initial.com', transcriptionAvailableMethod: 'POST', username: 'initialUsername', password: 'initialPassword', tag: 'initialTag', fileFormat: 'wav', multiChannel: true }; const startRecording = new Bxml.StartRecording(attributes); const response = new Bxml.Response(startRecording); response.toBxml(); ``` -------------------------------- ### Start Recording (Old) Source: https://dev.bandwidth.com/migration-guides/node/v1 Example of starting a recording using the older library version, specifying recording available URL and method. ```javascript var startRecording = new StartRecording({ recordingAvailableUrl: 'https://url.com', recordingAvailableMethod: 'POST', username: 'user', password: 'pass', tag: 'tag', fileFormat: 'wav', multiChannel: false }); var response = new Response(startRecording); response.toBxml(); ``` -------------------------------- ### Start Recording with Pause and Resume (C#) Source: https://dev.bandwidth.com/docs/voice/programmable-voice/guides/recording This C# example demonstrates building BXML for call recording control, including starting, pausing, and resuming the recording. It utilizes the Bandwidth SDK for .NET. ```csharp @POST [/secret_agent_endpoint] public ActionResult record_call() { StartRecording startRecording = new StartRecording { RecordingAvailableUrl = "https://myapp.test/noBXML" }; SpeakSentence intro_tts = new SpeakSentence { Sentence = "Hello secret agent. What is your message?", }; Pause pause1 = new Pause{Duration = 10}; PauseRecording pauseRecording = new PauseRecording(); SpeakSentence passcode_tts = new SpeakSentence { Sentence = "Please say your secret passcode to send. Don't worry, the recording is paused!", }; Pause pause2 = new Pause{Duration = 5}; ResumeRecording resumeRecording = new ResumeRecording(); SpeakSentence goodbye_tts = new SpeakSentence { Sentence = "Thank you agent. Good luck on your mission!", }; StopRecording stopRecording = new StopRecording(); Response response = new Response(startRecording, intro_tts, pause1, pauseRecording, passcode_tts, pause2, resumeRecording, goodbye_tts, stopRecording); return new OkObjectResult(response.ToBXML()); } ``` -------------------------------- ### Clone Sample Application Source: https://dev.bandwidth.com/docs/voice/integrations/openai/realtime/websockets Clone the provided sample application repository to get started with the integration. ```bash git clone https://github.com/Bandwidth-Samples/openai-realtime-sip-python cd openai-realtime-websockets-python ``` -------------------------------- ### Start Stream (New) Source: https://dev.bandwidth.com/migration-guides/node/v1 Example of initiating a stream using the new Bxml library, including stream parameters. ```javascript const attributes = { name: 'initialName', tracks: 'inbound', destination: 'https://initial.com', streamEventUrl: 'https://initial.com', streamEventMethod: 'POST', username: 'initialUsername', password: 'initialPassword' }; const streamParam1 = new Bxml.StreamParam({ name: 'streamParamName1', value: 'streamParamValue1' }); const streamParam2 = new Bxml.StreamParam({ name: 'streamParamName2', value: 'streamParamValue2' }); let startStream = new StartStream(attributes, streamParam1); startStream.addStreamParams(streamParam2); const response = new Bxml.Response(startStream); response.toBxml(); ``` -------------------------------- ### VSCode (Copilot) Start Server Command Source: https://dev.bandwidth.com/docs/tools/mcp/quickStart Example command to start the Bandwidth MCP Server within VSCode using the MCP: Add Server command. This is for a Command (stdio) type server. ```bash uvx --from /path/to/mcp-server start ``` -------------------------------- ### Run Bandwidth CLI Quickstart Source: https://dev.bandwidth.com/docs/tools/cli/quickStart Execute the `band quickstart` command to interactively set up an application, provision a Voice Configuration Package, and order a phone number. ```bash band quickstart ``` -------------------------------- ### Get Calls API Endpoint Example Source: https://dev.bandwidth.com/apis/voice This example demonstrates how to call the 'Get Calls' API endpoint to retrieve call records. It shows the base URL and common query parameters for filtering and pagination. ```http GET https://voice.bandwidth.com/api/v2/accounts/{accountId}/calls?to=%2b19195551234&from=%2b19195554321&minStartTime=2022-06-21T19:13:21Z&maxStartTime=2022-06-21T19:13:21Z&disconnectCause=hangup&pageSize=500 ``` -------------------------------- ### Get All Trunks Response Example Source: https://dev.bandwidth.com/docs/voice/whitelist Example request to retrieve IP whitelist addresses for all trunks in an account. ```bash GET https://api.bandwidth.com/v2/accounts/12345/trunks Authorization: Bearer mySecretToken ``` -------------------------------- ### Initialize StartRecording (v8 vs v9) Source: https://dev.bandwidth.com/migration-guides/java/v8-to-v9 Shows how to initialize StartRecording, highlighting the v8 builder and v9 constructor with builder. ```java StartRecording startRecording = StartRecording.builder() .recordingAvailableUrl("https://myapp.com/noBXML") .build(); ``` ```java StartRecording startRecording = new StartRecording().builder() .recordingAvailableUrl("https://example.com") .recordingAvailableMethod("POST") .transcribe(true) .transcriptionAvailableUrl("transcription-example.com") .recordingAvailableMethod("POST") .username("user") .password("pass") .tag("tag") .fileFormat("wav") .multiChannel(true) .build(); ``` -------------------------------- ### Build and Install Bandwidth CLI from Source Source: https://dev.bandwidth.com/docs/tools/cli/quickStart Clone the `bw-cli` repository, then build and install the `band` executable locally using `make` commands. ```bash git clone https://github.com/Bandwidth/bw-cli.git cd bw-cli make build # builds ./band make install # installs to $GOPATH/bin ``` -------------------------------- ### Get Specific Trunk Response Example Source: https://dev.bandwidth.com/docs/voice/whitelist Example request to retrieve IP whitelist addresses for a specific trunk. ```bash GET https://api.bandwidth.com/v2/accounts/12345/trunks/trunk1/ipAddresses Authorization: Bearer mySecretToken ``` -------------------------------- ### Initialize Client (New SDK) Source: https://dev.bandwidth.com/migration-guides/node/v1 Initializes the configuration with username and password, then creates API instances. ```javascript const username = process.env.BW_USERNAME; const password = process.env.BW_PASSWORD; const config = new Configuration({ username, password }); const callsApi = new CallsApi(config); const conferencesApi = new ConferencesApi(config); // etc... for the other included APIs ``` -------------------------------- ### Install Bandwidth CLI with Go Source: https://dev.bandwidth.com/docs/tools/cli/quickStart Install the `band` CLI using the Go toolchain, ensuring you have the latest version. ```bash go install github.com/Bandwidth/bw-cli/cmd/band@latest ``` -------------------------------- ### Run Sample Application using Local Python Environment Source: https://dev.bandwidth.com/docs/voice/integrations/openai/realtime/sip Set up a virtual environment, install dependencies, and run the FastAPI application locally. ```bash python -m venv .venv source .venv/bin/activate cd app pip install -r requirements.txt python main.py ``` -------------------------------- ### Start Transcription (New) Source: https://dev.bandwidth.com/migration-guides/node/v1 Example of starting a transcription using the new Bxml library, with options for transcription event URL and custom parameters. ```javascript const attributes = { name: 'initialName', tracks: 'inbound', transcriptionEventUrl: 'https://initial.com', transcriptionEventMethod: 'POST', username: 'initialUsername', password: 'initialPassword', destination: 'https://initial.com', stabilized: true }; const customParam1 = new Bxml.CustomParam({ name: 'customParamName1', value: 'customParamValue1' }); const customParam2 = new Bxml.CustomParam({ name: 'customParamName2', value: 'customParamValue2' }); let startTranscription = new StartTranscription(attributes, customParam1); startTranscription.addCustomParams(customParam2); const response = new Bxml.Response(startTranscription); response.toBxml(); ``` -------------------------------- ### Start Transcription in NodeJS Source: https://dev.bandwidth.com/docs/voice/bxml/startTranscription Start call transcription using the Bandwidth NodeJS SDK. This example demonstrates constructing the BXML with custom parameters. ```NodeJS const speakSentence = new Bxml.SpeakSentence( 'This call is being streamed to a live studio audience and transcribed.', { voice: 'bridget' } ); const customParam1 = new Bxml.CustomParam({ name: 'custom_param_1', value: 'value_1' }); const customParam2 = new Bxml.CustomParam({ name: 'custom_param_2', value: 'value_2' }); const startTranscription = new Bxml.StartTranscription( { name='live_audience', tracks='both', destination='wss://live-studio-audience.myapp.example.com', transcription_event_url='https://myapp.example.com/noBXML' }, [customParam1, customParam2] ); const response = new Bxml.Response([speakSentence, startTranscription]); console.log(response.toBxml()); ``` -------------------------------- ### Initiate a Recording and Play BXML Source: https://dev.bandwidth.com/docs/voice/programmable-voice/guides/recording This PHP example demonstrates how to initiate a call recording and play a BXML response upon completion. It uses the Bandwidth PHP SDK to construct the BXML. ```php addVerb($speakSentence); $bxml = $response->toBxml(); $response = $response->withStatus(200)->withHeader('Content-Type', 'application/xml'); $response->getBody()->write($bxml); return $response; } } ``` -------------------------------- ### Initialize Bandwidth Client v8 Source: https://dev.bandwidth.com/migration-guides/java/v8-to-v9 Demonstrates how to initialize the Bandwidth client in v8 using various authentication methods. ```java BandwidthClient client = new BandwidthClient.Builder() .messagingBasicAuthCredentials("username", "password") .voiceBasicAuthCredentials("username", "password") .twoFactorAuthBasicAuthCredentials("username", "password") .webRtcBasicAuthCredentials("username", "password") .build(); ``` -------------------------------- ### Get Specific Trunk Response Example Source: https://dev.bandwidth.com/docs/voice/whitelist Example JSON response containing voice and E911 whitelisted IP addresses for a specific trunk. ```json { "capabilityName": "DEFAULT", "voiceWhitelists": [ { "ipAddresses": ["127.127.127.127", "127.127.127.128"], "subAccountId": "10001", "locationId": "100001" }, { "ipAddresses": ["128.128.128.128", "128.128.128.129"], "subAccountId": "20002", "locationId": "200002" } ], "e911Whitelists": [ { "ipAddresses": ["129.129.129.129", "130.130.130.130"] } ] } ``` -------------------------------- ### Start Transcription Websocket Message Source: https://dev.bandwidth.com/docs/voice/bxml/startTranscription This is an example of the 'start' event message received via WebSocket when transcription begins. It contains metadata about the transcription session. ```JSON { "eventType": "start", "metadata": { "accountId": "5555555", "callId": "c-2a913f94-7fa91773-a426-4118-8b8b-b691ab0a0ae1", "realTimeTranscriptionId": "s-2a913f94-93e372e2-60da-4c89-beb0-0d3a219b287c", "transcriptionName": "live_audience", "tracks": [ { "name": "inbound" }, { "name": "outbound" } ] }, "customParams": { "foo": "bar", "foos": "bars" } } ``` -------------------------------- ### Bandwidth API Client Setup in Python Source: https://dev.bandwidth.com/docs/voice/programmable-voice/guides/conference This Python snippet shows the initial setup for using the Bandwidth API client. It configures authentication using environment variables. ```python import os import bandwidth configuration = bandwidth.Configuration( username=os.environ["BW_USERNAME"], password=os.environ["BW_PASSWORD"] ) with bandwidth.ApiClient(configuration) as api_client: ``` -------------------------------- ### FastAPI Server Setup Source: https://dev.bandwidth.com/docs/voice/integrations/openai/realtime/websockets Initialize a FastAPI application and load environment variables for the integration. ```python # main.py # !/usr/bin/env python3 # ...imports... # Set our Environment Variables try: BW_ACCOUNT = os.environ["BW_ACCOUNT_ID"] BW_USERNAME = os.environ["BW_USERNAME"] BW_PASSWORD = os.environ["BW_PASSWORD"] OPENAI_API_KEY = os.environ["OPENAI_API_KEY"] TRANSFER_TO = os.environ["TRANSFER_TO"] BASE_URL = os.environ["BASE_URL"] LOG_LEVEL = os.environ["LOG_LEVEL"].upper() LOCAL_PORT = int(os.environ.get("LOCAL_PORT", 3000)) except KeyError: print("environment variables not set") exit(1) app = FastAPI() ``` -------------------------------- ### Real-Time Transcription Started Event with Enqueued Time Source: https://dev.bandwidth.com/docs/voice/programmable-voice/webhooks/realTimeTranscriptionStarted This example shows the JSON payload for a Real-Time Transcription Started event, including the optional enqueuedTime parameter. ```json POST http://myapp.example/realTimeTranscriptionEvents Content-Type: application/json { "accountId" : "55555555", "answerTime" : "2022-06-30T18:55:02.080Z", "applicationId" : "7fc9698a-b04a-468b-9e8f-91238c0d0086", "callId" : "c-95ac912f-68aacdd7-4a8e-4223-a7fd-020e02fa6bf2", "callUrl" : "https://voice.bandwidth.com/api/v2/accounts/55555555/calls/c-95ac912f-68aacdd7-4a8e-4223-a7fd-020e02fa6bf2", "direction" : "outbound", "enqueuedTime" : "2022-06-30T18:54:59.172Z", "eventTime" : "2022-06-30T18:55:02.489Z", "eventType" : "realTimeTranscriptionStarted", "from" : "+15551112222", "realTimeTranscription" : { "id" : "t-95ac90b3-bfc81595-35fc-4b64-8265-fab6855b74a2", "name" : "example_transcription", "startTime" : "2022-06-30T18:55:02.489Z", "tracks" : ["inbound", "outbound"] }, "startTime" : "2022-06-30T18:54:59.175Z", "to" : "+15553334444" } ``` -------------------------------- ### Get Endpoint Information Request Source: https://dev.bandwidth.com/apis/brtc-apis/brtc This is an example of an HTTP GET request to retrieve information about a specific WebRTC endpoint using its account ID and endpoint ID. ```http GET /v2/accounts/{accountId}/endpoints/{endpointId} HTTP/1.1 Host: api.bandwidth.com Authorization: Bearer ``` -------------------------------- ### Get Group Response Example Source: https://dev.bandwidth.com/apis/numbers-apis/number-management Example JSON response for retrieving group details in an enterprise or reseller account. Includes group data, associated links, and any errors. ```json { "data": { "groupId": 26, "groupName": "Group Name", "description": "Group Description", "intent": "GOVN", "createdAt": "2023-10-01T12:00:00Z", "phoneNumberCount": 1 }, "links": [ { "href": "https://api.bandwidth.com/api/v2/accounts/6555555/numberReputationManagement/groups/26", "rel": "self", "method": "GET" }, { "href": "https://api.bandwidth.com/api/v2/accounts/6555555/numberReputationManagement/groups", "rel": "list-groups", "method": "GET" } ], "errors": [ ] } ``` -------------------------------- ### Start Recording: v10 vs v11 Source: https://dev.bandwidth.com/migration-guides/ruby/v10-to-v11 Instantiate the StartRecording command with recording and transcription URLs for v10 and v11. ```ruby start_recording = Bandwidth::Voice::StartRecording.new({ :recording_available_url => "https://myapp.com/noBXML" }) ``` ```ruby start_recording_attributes = { recording_available_url: 'https://start_recording.com', recording_available_method: 'POST', transcribe: true, transcription_available_url: 'https://start_recording.com', transcription_available_method: 'POST', username: 'start_recording_username', password: 'start_recording_password', tag: 'start_recording_tag', file_format: 'wav', multi_channel: true } start_recording = Bandwidth::Bxml::StartRecording.new(start_recording_attributes) ``` -------------------------------- ### Get Campaigns Request Source: https://dev.bandwidth.com/docs/messaging/campaign-management/csp/campaign-api This snippet shows an example HTTP GET request to retrieve a list of campaigns. It includes query parameters for pagination and specifies content type and authorization headers. ```http GET https://api.bandwidth.com/api/accounts/{accountId}/campaignManagement/10dlc/campaigns?page=0&size=2 HTTP/1.1 Content-Type: application/xml; charset=utf-8 Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ= ``` -------------------------------- ### Start Recording (v10) Source: https://dev.bandwidth.com/migration-guides/csharp/v10-to-v11 Initializes a StartRecording object with various parameters for v10. ```csharp StartRecording startRecording = new StartRecording { DetectLanguage = true, Transcribe = true, TranscriptionAvailableUrl = "https://transcriptionTest.url/", TranscriptionAvailableMethod = "POST", RecordingAvailableUrl = "https://myapp.com/noBXML", RecordingAvailableMethod = "POST", Tag = "test", FileFormat = "mp3", MultiChannel = true, Username = "username", Password = "password" }; ``` -------------------------------- ### Initialize StartGather (v8 vs v9) Source: https://dev.bandwidth.com/migration-guides/java/v8-to-v9 Illustrates the difference in initializing StartGather between v8 and v9, focusing on the builder pattern. ```java StartGather startGather = StartGather.builder() .dtmfUrl("https://startgather.url/callback") .build(); ``` ```java StartGather startGather = new StartGather().builder() .dtmfUrl("https://example.com/startgather") .dtmfMethod("POST") .username("user") .password("pass") .tag("tag") .build(); ``` -------------------------------- ### Start Recording (v11) Source: https://dev.bandwidth.com/migration-guides/csharp/v10-to-v11 Initializes a StartRecording object with similar parameters for v11. ```csharp StartRecording startRecording = new StartRecording { RecordingAvailableUrl = "https://myapp.com/noBXML", RecordingAvailableMethod = "POST", Transcribe = true, DetectLanguage = true, TranscriptionAvailableUrl = "https://transcriptionTest.url/", TranscriptionAvailableMethod = "POST", Username = "username", Password = "password", Tag = "test", FileFormat = "mp3", MultiChannel = true }; ``` -------------------------------- ### Get Call Recording Metadata (HTTP Request) Source: https://dev.bandwidth.com/apis/voice This is an example of an HTTP GET request to retrieve metadata for a specific call recording. Ensure you replace placeholder values with your actual account, call, and recording IDs. ```http GET /api/v2/accounts/{accountId}/calls/{callId}/recordings/{recordingId} HTTP/1.1 Host: voice.bandwidth.com Authorization: Basic ``` -------------------------------- ### Run with Local Python Environment Source: https://dev.bandwidth.com/docs/voice/integrations/openai/realtime/websockets Set up a virtual environment, install dependencies, and run the application using a local Python environment. ```bash python -m venv .venv source .venv/bin/activate cd app pip install -r requirements.txt python main.py ``` -------------------------------- ### Start Recording with Pause and Resume (Java) Source: https://dev.bandwidth.com/docs/voice/programmable-voice/guides/recording This Java code snippet shows how to construct BXML to start, pause, and resume call recordings using the Bandwidth SDK. It includes TTS prompts and pauses for a guided interaction. ```java @POST /secret_agent_endpoint endpoint public String record_call() { StartRecording startRecording = new StartRecording().builder() .recordingAvailableUrl("https://myapp.test/noBXML") .build(); SpeakSentence intro_tts = new SpeakSentence("Hello secret agent. What is your message?"); Pause pause1 = Pause(10.0); PauseRecording pauseRecording = PauseRecording(); SpeakSentence passcode_tts = SpeakSentence("Please say your secret passcode to send. Don't worry, the recording is paused!"); Pause pause2 = Pause(5.0) ResumeRecording resumeRecording = new ResumeRecording(); SpeakSentence goodbye_tts = new SpeakSentence("Thank you agent. Good luck on your mission!"); StopRecording stopRecording = new StopRecording(); Response response = new Response(); String bxml = response.withVerbs(startRecording, intro_tts, pause1, pauseRecording, passcode_tts, pause2, resumeRecording, goodbye_tts, stopRecording).toBXML(); return bxml; } ``` -------------------------------- ### Initialize Client (Old SDK) Source: https://dev.bandwidth.com/migration-guides/node/v1 Initializes the client using basic authentication with username and password. ```javascript const username = process.env.BW_USERNAME; const password = process.env.BW_PASSWORD; const client = new Client({ basicAuthPassword: password, basicAuthUserName: username }); const controller = new ApiController(client); ``` -------------------------------- ### GET Request Example for Available Numbers Source: https://dev.bandwidth.com/docs/universal-platform/order-numbers This snippet shows a GET request to retrieve available telephone numbers. It includes parameters for country code, quantity, city, and state. Ensure you include the Authorization header with your Bearer token. ```http GET https://api.bandwidth.com/api/v2/accounts/{accountId}/availableNumbers?countryCodeA3=USA&quantity=5&city=Raleigh&state=NC Authorization: Bearer mySecretToken ``` -------------------------------- ### Get Conference Asynchronously in C# Source: https://dev.bandwidth.com/migration-guides/csharp/v10-to-v11 Asynchronously retrieve details for a specific conference using its ID. This example uses the client.Voice.APIController. ```csharp using System; using System.Threading.Tasks; using Bandwidth.Standard; using Bandwidth.Standard.Exceptions; using Bandwidth.Standard.Voice.Models; var conferenceId = "conf-95ac8d8d-28e06798-2afe-434c-b0f4-666a79cd47f8"; try { var response = await client.Voice.APIController.GetConferenceAsync(accountId, conferenceId); Console.WriteLine(response.Data); } catch (ApiException e) { Console.WriteLine(e.Message); } ``` -------------------------------- ### Verify Bandwidth CLI Installation Source: https://dev.bandwidth.com/docs/tools/cli/quickStart After installation, run this command to confirm that the `band` CLI is installed correctly and accessible. ```bash band version ``` -------------------------------- ### Start Stream (Old) Source: https://dev.bandwidth.com/migration-guides/node/v1 Example of initiating a stream using the older library version, specifying destination and stream event method. ```javascript var startStream = new StartStream({ destination: 'https://url.com', streamEventMethod: 'POST', username: 'user', password: 'pass', name: 'test', tracks: 'inbound', streamEventUrl: 'https://url.com' }); var response = new Response(startStream); response.toBxml(); ``` -------------------------------- ### Start Gather (Old) Source: https://dev.bandwidth.com/migration-guides/node/v1 Example of initiating a gather operation using the older version of the library, specifying DTMF URL and method. ```javascript var startGather = new StartGather({ dtmfUrl: 'https://test.com', dtmfMethod: 'POST', username: 'user', password: 'pass', tag: 'custom tag' }); var response = new Response(startGather); response.toBxml(); ``` -------------------------------- ### Connect to an Endpoint using PHP Source: https://dev.bandwidth.com/docs/voice/programmable-voice/bxml/connect This PHP example demonstrates how to build a Connect verb with an Endpoint, event callback URL, and event fallback URL using the Bandwidth SDK. ```php $endpoint = new BandwidthLib\Voice\Bxml\Endpoint("endpoint-abc123"); $connect = new BandwidthLib\Voice\Bxml\Connect(); $connect->eventCallbackUrl("https://example.com/callback"); $connect->eventFallbackUrl("https://fallback.example.com/callback"); $connect->endpoints(array($endpoint)); $response = new BandwidthLib\Voice\Bxml\Response(); $response->addVerb($connect); echo $response->toBxml(); ```