Skip to content

A Go-based SIP client for connecting to BSNL Wings VoIP service using the sipgo library.

License

Notifications You must be signed in to change notification settings

ashoksahoo/wings-client

Repository files navigation

BSNL Wings SIP Client

A Go-based SIP client for connecting to BSNL Wings VoIP service using the sipgo library.

Prerequisites

  • Go 1.21 or later
  • BSNL Wings account credentials

Quick Start

Using the Makefile (recommended):

# Initial setup - creates .env file and installs dependencies
make setup

# Edit .env with your BSNL Wings credentials
# Then run the application
make dev

Setup

  1. Copy the environment configuration file:

    cp .env.example .env
    # Or use: make setup
  2. Edit .env and add your BSNL Wings credentials:

    • SIP_USERNAME: Your BSNL Wings username
    • SIP_PASSWORD: Your BSNL Wings password
    • SIP_SERVER: BSNL Wings SIP server address (verify the correct server)
    • SIP_PORT: SIP server port (typically 5060)
  3. Install dependencies:

    go mod download
    # Or use: make deps

Running

Using Makefile (Recommended)

# Run in development mode (loads .env automatically)
make dev

# Build and run
make run

# Just build
make build

Making Calls

Once registered, use the interactive commands:

> call +919876543210    # Dial a number
> status                # Check call status
> hangup                # End the call

See CALLING.md for complete calling documentation.

Using Go Commands

# Using environment variables from .env file (filters out comments)
export $(grep -v '^#' .env | grep -v '^$' | xargs) && go run cmd/wings-client/main.go

# Or set environment variables manually
export SIP_USERNAME="your_username"
export SIP_PASSWORD="your_password"
export SIP_SERVER="sip.bsnl.in"
go run cmd/wings-client/main.go

# Build and run
go build -o wings-client cmd/wings-client/main.go
./wings-client

Makefile Commands

Run make help to see all available commands:

Command Description
make help Display all available commands
make setup Initial project setup (creates .env, installs dependencies)
make dev Run in development mode with .env
make build Build the application binary
make build-all Build for multiple platforms (Linux, macOS, Windows)
make run Build and run the application
make test Run all tests
make test-coverage Run tests with coverage report
make fmt Format Go code
make lint Run golangci-lint
make vet Run go vet
make check Run fmt, vet, and test
make clean Remove built binaries and artifacts
make install Install binary to $GOPATH/bin
make sngrep Start sngrep for SIP traffic debugging
make debug-sip Run client + sngrep in split screen (tmux)

Project Structure

wings-client/
├── cmd/
│   └── wings-client/       # Main application entry point
│       └── main.go
├── internal/
│   ├── config/             # Configuration management
│   │   └── config.go
│   └── sip/                # SIP client implementation
│       └── client.go
├── go.mod
├── .env.example            # Example environment configuration
└── README.md

Features

  • SIP Registration with BSNL Wings server
  • Outbound Calling with full audio support
  • RTP Audio Streaming (PCMU/PCMA codecs)
  • WebSocket API for real-time audio integration
  • Interactive CLI for making and managing calls
  • AI Voice Bot — GPT-4o + ElevenLabs STT/TTS with weather & hangup tools
  • Custom Pipecat Transport (WingsWebSocketTransport) with PCMU↔PCM conversion
  • ✅ Digest authentication support
  • ✅ UDP transport for SIP
  • ✅ Compatible with Pipecat and similar frameworks
  • ✅ Clean shutdown handling

AI Voice Bot

The pipecat/ai_bot.py bot answers phone calls with a fully conversational AI using:

  • STT: ElevenLabs Scribe v1 (speech-to-text)
  • LLM: OpenAI GPT-4o
  • TTS: ElevenLabs Turbo v2.5 (text-to-speech)
  • VAD: Silero (voice activity detection, supports interruptions)
  • Transport: WingsWebSocketTransport — custom Pipecat transport that handles PCMU↔PCM conversion and real-time audio pacing

AI Bot Tools

Tool Description
get_weather(city) Fetches live weather for any city via Open-Meteo
hangup() Politely says goodbye and ends the call

Running the AI Bot

Terminal 1 — start the SIP client:

make dev

Terminal 2 — start the AI bot:

cd pipecat

# Install dependencies (uv recommended)
uv sync
# or: pip install -r requirements.txt

# Set required API keys in .env
export OPENAI_API_KEY="sk-..."
export ELEVENLABS_API_KEY="..."

python ai_bot.py

AI Bot Environment Variables

Variable Description Default
OPENAI_API_KEY OpenAI API key Required
ELEVENLABS_API_KEY ElevenLabs API key Required
WINGS_WS_URL Wings WebSocket URL ws://localhost:8080/ws
BOT_NAME Bot display name BSNL Wings AI Assistant
ELEVENLABS_VOICE_ID ElevenLabs voice ID Rachel (21m00Tcm4TlvDq8ikWAM)
LOG_LEVEL Log verbosity INFO

Call Flow with AI Bot

Caller dials → BSNL IMS → wings-client (Go, SIP+RTP) → WebSocket :8080
                                                                ↕ PCMU binary
                                              WingsWebSocketTransport (Python)
                                                                ↕ PCM
                                               ElevenLabs STT → GPT-4o → ElevenLabs TTS

The bot greets callers automatically, listens for speech, and responds naturally. Silero VAD enables real-time interruptions.


WebSocket API

The client exposes a WebSocket server for real-time audio streaming and call control, making it easy to integrate with voice AI applications.

Quick Start:

const ws = new WebSocket('ws://localhost:8080/ws');
ws.onmessage = (event) => {
  if (event.data instanceof Blob) {
    // Received audio from SIP call
  } else {
    // Received event/control message
    console.log(JSON.parse(event.data));
  }
};

Features:

  • Bidirectional PCM audio streaming (8kHz, 16-bit, mono)
  • JSON-based control messages
  • Real-time call events
  • Compatible with Pipecat, WebRTC, and other frameworks

See WEBSOCKET_API.md for complete API documentation.

Configuration

All configuration is done through environment variables:

Variable Description Default
SIP_SERVER BSNL Wings SIP server address sip.bsnl.in
SIP_PORT SIP server port 5060
SIP_USERNAME Your BSNL Wings username Required
SIP_PASSWORD Your BSNL Wings password Required
SIP_DISPLAY_NAME Display name for the client BSNL Wings Client
LOCAL_IP Local IP to bind to 0.0.0.0
LOCAL_PORT Local port to listen on 5061
WEBSOCKET_ENABLED Enable WebSocket server true
WEBSOCKET_PORT WebSocket server port 8080

Troubleshooting

404 Not Found Error

If you're getting a "404 Not Found" response:

  1. Verify account activation: Ensure your BSNL Wings account is fully activated and provisioned
  2. Check credentials: Confirm your SIP username and password are correct
  3. Username format: Use the full number with country code (e.g., +918480000384)
  4. Contact BSNL: The account might need to be activated on their SIP server

Network Issues

  • Ensure your firewall allows UDP traffic on the configured local port (default: 5061)
  • If behind NAT, you may need to configure port forwarding
  • Check that no other application is using the local port

BSNL Wings Configuration

The correct BSNL Wings configuration includes:

  • Register Server: or.voip.ims.bsnl.in
  • Outbound Proxy: ir.bbsr.sbc.ims.bsnl.in:80 (Bhubaneswar SBC)
    • Alternative: ir.kol.sbc.ims.bsnl.in:80 (Kolkata SBC)
  • Username: Full number with +91 prefix
  • Port: 80 for outbound proxy (not standard 5060)

Documentation

For detailed documentation on specific topics, see:

Project Structure

wings-client/
├── cmd/wings-client/           # Main application entry point
├── internal/
│   ├── config/                 # Configuration management
│   ├── sip/                    # SIP client (registration, calling, RTP)
│   └── websocket/              # WebSocket server for audio bridge
├── pipecat/
│   ├── ai_bot.py               # AI voice bot (GPT-4o + ElevenLabs)
│   ├── wings_transport.py      # Custom Pipecat WebSocket transport
│   ├── weather.py              # Weather tool (Open-Meteo)
│   ├── echo_bot.py             # Simple echo bot (testing)
│   └── echo_bot_smart.py       # Echo bot with VAD
├── docs/                       # Documentation + GitHub Pages site
├── examples/                   # Code examples
└── scripts/                    # Helper scripts

License

MIT License — see LICENSE.

About

A Go-based SIP client for connecting to BSNL Wings VoIP service using the sipgo library.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors